1

I believe this is a permissions issue, but not sure how to fix it.

I have a php script -- mainscript.php -- that calls:

$scriptCall = "/usr/bin/php wrap_prep.php 2>&1 &";

When running mainscript.php, the wrap_prep.php never executes. However, when I log into my webserver as root and run php wrap_prep.php 2>&1 & it works fine.

I have set both scripts to owner and group to my apache user as well as 755 permissions.

I recently recompiled PHP to add a library (not sure if this has anything to do with the new issue).

4
  • is wrap_prep.php in the same directory as mainscript.php? Otherwise you may have to add an absolute or relative path. Is there anything in your apache error_log like "File not found"? Commented Jan 21, 2010 at 18:43
  • Are you trying to run wrap_prep.php in the background? Commented Jan 21, 2010 at 18:51
  • Thilo - same directory, yes. Peter - yes. Commented Jan 21, 2010 at 19:38
  • I left off the exec call in my initial post: exec( $scriptCall ); Commented Jan 21, 2010 at 19:49

3 Answers 3

1

First of all, you should simply output what exec() ing the command gives you. There should be an error message no matter what.

Second, the fact that you are in a PHP script does not necessarily mean that the user PHP runs under is allowed to call the PHP binary at /usr/bin/php. Can you try changing the rights of that?

If that doesn't help, check out which user your PHP script is running as exactly. As far as I know, posix_getuid() is the most accurate tool to find that out. Make sure the permissions you are setting are really identical with the users you set the rights for.

Oh and Thilo's comment above is the most obvious thing and should be checked out first :)

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for reply. I tried echo'ing the results of the exec. It returned an empty string. Trying the posix_getuid()... looks like that may be an issue. When I run from ssh my UID is either root or username. But when I call it from my webbrowser, the UID is 99. Perhaps that's where the prob lies.
Can you check which user has the UID 99?
Using posix_getpwuid(99) I get: Array ( [name] => nobody [passwd] => [uid] => 99 [gid] => 99 [gecos] => Nobody [dir] => / [shell] => /sbin/nologin ) 99
Can you execute any other command through exec (e.g. a ls) and do you get any output?
Yup - ls returns the last entry in the return val as well as my $output array is filled (both webserver & webbrowser calls).
|
0

I'd check to make sure your host hasn't disabled exec entirely. I believe phpinfo() tells you if it is.

1 Comment

No disabled functions or safe mode. Thx though.
0

If running on windows (I know the OP isnt) the problem may be needed to wrap the entire command in a set of quotes.

This is explained here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.