|
-
Jun 18th, 2008, 06:32 AM
#1
Thread Starter
Addicted Member
Exec doesn't work
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.
-
Jun 18th, 2008, 07:23 AM
#2
Re: Exec doesn't work
What is:
- your operating system
- your default shell, if applicable
- an exact command you tried to execute that failed.
-
Jun 18th, 2008, 10:13 AM
#3
Thread Starter
Addicted Member
Re: Exec doesn't work
Operating system is Centos.
I don't know abotu shell.
Any command... any..
-
Jun 18th, 2008, 01:56 PM
#4
Re: Exec doesn't work
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,
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.
-
Jun 18th, 2008, 11:56 PM
#5
Thread Starter
Addicted Member
Re: Exec doesn't work
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
-
Jun 19th, 2008, 12:00 AM
#6
Re: Exec doesn't work
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";
-
Jun 19th, 2008, 12:10 AM
#7
Thread Starter
Addicted Member
Re: Exec doesn't work
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.
-
Jun 19th, 2008, 01:31 AM
#8
Thread Starter
Addicted Member
Re: Exec doesn't work
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?
-
Jun 19th, 2008, 02:00 AM
#9
Re: Exec doesn't work
Try executing the PHP script from shell.
When invoked from Apache it runs as Apache user, usually nobody.
-
Jun 19th, 2008, 02:02 AM
#10
Re: Exec doesn't work
But `whoami' should work and return 'nobody' in that case anyway. So perhaps there is another issue here.
-
Jun 19th, 2008, 07:58 AM
#11
Thread Starter
Addicted Member
Re: Exec doesn't work
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|