Web Hosting Talk







View Full Version : Problem with PHP exec()


owocki
04-11-2006, 01:20 AM
I seem to have a problem with the exec command with PHP. Seems that no matter what the permissions on an executable (ie. './a.out') I am unable to run them via php.

Any thoughts?

Mark S
04-11-2006, 01:51 AM
what are the current permissions of the file?

owocki
04-11-2006, 01:57 AM
They are 755. Like I said, it doesnt matter if they are 777, no luck.

Mark S
04-11-2006, 01:59 AM
but who are they chowned by? root? what user does php run as?

owocki
04-11-2006, 02:09 AM
the file being exec() ed is owned by apache, and php runs as apache

thanks

owocki
04-11-2006, 02:18 AM
note if php script is invoked via : php myscript.php then everything runs fine

Mark S
04-11-2006, 02:20 AM
Oh Okay;

so do you have "#!/path/to/php/bin" at the very beginning of your script (BEFORE <?php //code ?>)?

owocki
04-11-2006, 02:27 AM
no i dont.. im a bit confused by what youre going for. sorry :)

the problem is ... i can run exec() properly via command line (ie. php myscript.php) but cannot run it via www.myurl.com/myscript.php

owocki
04-11-2006, 02:44 AM
just a note: safe mode is off on this machine.

wolseley
04-11-2006, 04:19 AM
Try using the full path to the executable instead of ./

(I've had similar problems with some versions of php, I think it may be to do with the dir the script thinks it is in when invoked but have not looked further into it as this seems to work.)

owocki
04-11-2006, 12:51 PM
I've actually tried that and have come up with no luck! Ahh!

Thanks again ! Does anyone have any thoughts?

Burhan
04-11-2006, 02:50 PM
Use shell_exec(), and make sure the program is outputting to stdout, not stderr (otherwise, you need to redirect).

Mark S
04-11-2006, 06:13 PM
Right; What I was saying before, is doing "php myscript.php" is different than saying "./myscript.php". The shell needs to know how to execute it as/which program will execute that script.

Therefore, you need to add "#!/usr/bin/php" (assuming thats where the php-bin file is located).

Another example would be a bash script. Any bash script will run by saying "sh myscript.sh" however to be able to do "./myscript.sh" you must add "#!/bin/bash" to the beginning of your bash script.

owocki
04-11-2006, 06:52 PM
Thanks. I've got it running via shell script. Like I said I need to call an executable from apache.

:)

Mark S
04-11-2006, 07:07 PM
So it will run by saying "./myscript.php"? Okay, you didnt make that clear. Make sure it is chowned by apache and that it is 777. Can you confirm the properties by showing the ouput of "ls -al | grep myscript.php"?