what i am trying to acomplish is to have a php page execute a shell command and display the output on the web page.
the code for the page is something along the lines of
<?php
echo shell_exec('ls -l /code');
?>
when i load up this page all i see is blank. yet when i execute it from the command line i see the command being executed and the output printed.
I am sure its something to do with the permissions and i am hoping someone can point me the right way.
this is what I see in the httpd log file
ls: cannot access /gateway_code: Permission denied
ls: cannot access /gateway_code: Permission denied
BTW the directory /code is set to "Read only" for the user "apache"
thanks! -ankit
Check your base directory restriction. Php doesn't have permission to access /bin/ls. Instead of adding /bin directory to the base directory restriction list copy /bin/ls over to the folder /code.
If you really have to do this.
That's your interpretation of the way the permissions have been set - it would have been a lot more useful if you'd told us what the permissions actually are.
I suspect the directory is not executable by the apache uid. Or there maybe MAC/ACL issues in play here - but you've provided no details of which Linux distribution this is, nor how the permissions are set up.
The first thing to do is make PHP give you a better answer than just a blank page. You can redirect stderr to stdout using
2>&1
such that the error message will be printed with echo.Next, make sure that whatever process is running your php script (ie. apache) has execute permissions on the directory you're trying to list. If you don't mind being heavy-handed, you can easily determine whether permissions are the problem by just giving rwx access to everybody.
And finally, make sure that you're specifying the right path. In your question you say that you're trying to list the contents of
/code
-- is it really your intention to be listing a root level directory? If thecode
folder is in the same directory as your script, you might have better luck with a relative path.