exec() problem with unix

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
gunhippy
Forum Newbie
Posts: 3
Joined: Tue Mar 28, 2006 5:56 am

exec() problem with unix

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

php's user, apache, doesn't have permission to run them it would appear. A normal, good thing.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
gunhippy
Forum Newbie
Posts: 3
Joined: Tue Mar 28, 2006 5:56 am

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
Post Reply