how to execute shell commands (linux)?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maxpayne
Forum Newbie
Posts: 2
Joined: Wed May 30, 2007 6:26 am

how to execute shell commands (linux)?

Post by maxpayne »

Hi, I am very new to php.
I am trying to execute a shell program from php.
Basically i am trying to execute the following shell command "ls -la > list.txt"
I ve tried exec() and shell_exec() functions but neither will do...
Basically it will execute ls-la or whoami or commands like that but it will not execute commands like mkdir or some command that will create a file.
I believe that the problem might be permission related.
I am using fedora core 6 (selinux disabled).
As far as I know apache on fedora has full permissions only on /tmp directory (which is where i try to create my files...).
Where can i search for error logs?

Thanx in advance people and sorry if i ask something stupid but i am really stuck...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$cmd = 'ls -la';
echo 'shell_exec: ', shell_exec($cmd . ' 2>&1');
&2>1 redirects STDERR to STDOUT. Maybe an error message shows up.
maxpayne
Forum Newbie
Posts: 2
Joined: Wed May 30, 2007 6:26 am

Post by maxpayne »

it returns no error if i try to create a file it returns nothing but it also doesnt create the file...
does anyone know where are the apache and php error logs?
any other ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please post your code.

The location of the apache error log file is controlled by the config parameter ErrorLog
Post Reply