When i try to execute any command thru exec() function i get 127 as return code and command doesn't execute though on shell every command works.
How can i resolve this issue?
Thanks.
Printable View
When i try to execute any command thru exec() function i get 127 as return code and command doesn't execute though on shell every command works.
How can i resolve this issue?
Thanks.
What is:
- your operating system
- your default shell, if applicable
- an exact command you tried to execute that failed.
Operating system is Centos.
I don't know abotu shell.
Any command... any..
Show us an example of an exact command that you tried. Any command could be anything. Even 'aslkfdjsdflajsf'.
Also, consult the exec function documentation to see if you've missed anything. According to that page,
Quote:
Return Value
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
To get the output of the executed command, be sure to set and use the output parameter.
I tried this one
exec('whoami',$output, $return);
and in return code i get alway 127 for any valid command i try to execute.
i think there is some privilege issue? :-s
exec can actually be restricted and disabled in various ways such as safe mode and the disable_functions setting in php.ini.
Are you working on shared hosting, by any chance?
edit: try:
PHP Code:echo ini_get('safe_mode')."\n";
echo ini_get('safe_mode_exec_dir')."\n";
No, I have shell access, its not shared hosting.
Safe Mode is OFF.
I think i should ask how to run my script with root privilege?
Probably it will solve my issue.
I have found that when I execute command for any external program installed i get 127 while for other commands i get return code 1.
Now I am sure its because exec tries to execute the external while it doesn't has root privilege and on shell it works fine because it has root privilege.
So, is there any way to execute php script using root privileges?
Try executing the PHP script from shell.
When invoked from Apache it runs as Apache user, usually nobody.Code:# php myscript.php
But `whoami' should work and return 'nobody' in that case anyway. So perhaps there is another issue here. :confused:
I found there was issues with my system build. I got new one and now everything is working fine.
Special thanks to Penagate, Mendhak and RobDog (though he didn't reply in this thread). You might not know but you have really helped me lot of time indirectly.
You are great people. God bless you.