Page 1 of 1

exec() problem with unix

Posted: Tue Mar 28, 2006 5:57 am
by gunhippy
hi guys,

hopefully someone here can help.. I have trawled every forum and googled for a week now, and still cant get this fixed..

I have CentOS4.2 installed, with apache2 and php4 rpm installs. httpd is running under user apache.

it appears to work ok.. however.. my problem...

DocumentRoot is set to /var/www/html

my php page is this r.php

<?
shell_exec("/tmp/ls.sh");
?>

/tmp/ls.sh consists of:

#!/bin/sh
ls -al > /tmp/output

when I load sr.php in a browser, nothing happens. ( I am not expecting anything on screen, but /tmp/output never gets created).

a tail of /var/log/http/error_log shows
sh: /tmp/ls.sh: Permission denied


now, /tmp has 777 perms, and if I run

su -c "/tmp/ls.sh" apache
the file /tmp/output gets created.

if I change sr.php to
<?
shell_exec("ls > /tmp/output");
?>

the file /tmp/output gets created!

Any ideas as to why I can not run user scripts from within PHP??

This has got me utterly beaten..

Thanks in advance

Posted: Tue Mar 28, 2006 9:28 am
by feyd
php's user, apache, doesn't have permission to run them it would appear. A normal, good thing.

Posted: Tue Mar 28, 2006 10:59 am
by Chris Corbyn
Hmm, that's weird if the file is 0777. It's even weirder if you can run ls but not your shell script.

Can you run any other bash or sh scripts from PHP? I'm guessing that your shell script doesn't really contain that code since you'd not bother with the script :P

I can't think of anything off the top of my head that would cause it if the file is really 0777. I assume the filesystem that it's on is not mounted with the noexec option?

Posted: Tue Mar 28, 2006 5:20 pm
by gunhippy
the file permissions are fine siince the script is executable from bash, basic read commands workthrough the php pages, jsut nothing that writes or executes other commands. could this have anything to do with SELinux as it's the only thing thats different to the current server than the last server

Posted: Wed Mar 29, 2006 12:18 am
by timvw
My guess is that /tmp is mounted with the noexec attribute.

So when you load a program from /usr/bin that reads it's instructions from /tmp there is no problem,
but when you start something from /tmp it won't work.