exec/system problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

exec/system problems

Post by Nunners »

I've setup an automated script that thens selects some other scripts to run depending on day, time (which I would have done on a cron but it needs other info dependant on whether work is open or not!) however I've hit a problem.

The following....

Code: Select all

$cron["script"]="/cronjobs/db_tidy.hourly.php";
$return = exec("/usr/bin/php /var/www/vhosts/website/httpsdocs".$cron["script"], $return_var);
Produces....
sh: /php: No such file or directory
If I call the script from the command line it works fine, however from using either exec or system calls from within php, it doesn't.

Can anyone shed any light on why it might be happening?

Thanks
Nunners
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: exec/system problems

Post by VladSun »

What's the output of:

Code: Select all

$return = exec("/usr/bin/php -v  2>&1", $return_var);
and

Code: Select all

$return = exec("ls -l /usr/bin/php 2>&1", $return_var);
and

Code: Select all

$cron["script"]="/cronjobs/db_tidy.hourly.php";
$return = exec("/usr/bin/php /var/www/vhosts/website/httpsdocs".$cron["script"]." 2>&1", $return_var);
There are 10 types of people in this world, those who understand binary and those who don't
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Re: exec/system problems

Post by Nunners »

Code: Select all

 
$return = exec("/usr/bin/php -v 2>&1", $return_var);
$return = exec("ls -l /usr/bin/php -v  2>&1", $return_var);
$cron["script"]="/cronjobs/db_tidy.hourly.php";
$return = exec("/usr/bin/php /var/www/vhosts/website/httpsdocs".$cron["script"]." 2>&1", $return_var);
 
sh: /php: No such file or directory
sh: /ls: No such file or directory
sh: /php: No such file or directory
This lead me onto think that it was because the file links weren't working, cos the actual file is /usr/bin/php5, but that made no different at all.

Permissions problem?

Thanks
Nunners
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: exec/system problems

Post by VladSun »

Maybe ...
http://bg.php.net/function.exec
Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.
There are 10 types of people in this world, those who understand binary and those who don't
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Re: exec/system problems

Post by Nunners »

Looks like safe_mode is ON - any thoughts on work arounds for this?

Cheers
Nunners
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: exec/system problems

Post by VladSun »

Copy them to safe-mode-exec-dir (create it first - outside of DocumentRoot).

http://bg.php.net/manual/en/ini.sect.sa ... e-exec-dir
There are 10 types of people in this world, those who understand binary and those who don't
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Re: exec/system problems

Post by Nunners »

What needs to bu in the safe_mode_exec_dir?

Is it /usr/bin - for php - or is it the file location of the php file to be run - or indeed is it both?

If it is both, what's the seperator?

Currently, I'm working on the basis of /usr/bin/...
should it read:
safe_mode_exec_dir = /usr/bin/

Or do I need "" or something else?

Cheers
Nunners
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Re: exec/system problems

Post by Nunners »

Can anyone give any guidance on this? I'm really struggling to get things working.

Thanks
Nunners
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: exec/system problems

Post by VladSun »

As I said :
- create a directory (e.g. /my/directory);
- copy executables you want to be available in this directory;
- change safe_mode_exec_dir = "/my/directory"
- restart Apache.

You can also run phpinfo() and see what's the current value for safe_mode_exec_dir and use it (if there is a value)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply