Page 1 of 1

how to execute shell commands (linux)?

Posted: Wed May 30, 2007 6:36 am
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...

Posted: Wed May 30, 2007 7:37 am
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.

Posted: Wed May 30, 2007 8:11 am
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?

Posted: Wed May 30, 2007 8:23 am
by volka
Please post your code.

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