cheng
cheng

Reputation: 2136

Php exec function doesn't work as expected

I am using exec function in a php script, if I run the script in command line, such as "php xx.php", the exec function will be executed, but if i access the php page from a browser, then the exec function will not run. Anyone known how to solve the problem?

Thanks.

Upvotes: 2

Views: 8564

Answers (4)

Lucio Fonseca
Lucio Fonseca

Reputation: 3527

if you're using MAMP (to WAMP and LAMP I think that it should to be kinda similar) try open the file MAMP/Library/bin/envvar and the four lines of if and else that should looks like this:

#if test "x$DYLD_LIBRARY_PATH" != "x" ; then
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#else
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"

It works for me! Good Lucky!

Upvotes: 0

mahadeb
mahadeb

Reputation: 676

You can use "2>&1" as succeeding with the command which you are trying to execute with exec().

for example: - exec( php xx.php 2>&1", $output);

Then you can trace the problem by print output.

Upvotes: 3

dleavitt
dleavitt

Reputation: 1392

Is the script trying to create/edit/delete files? Try making the files and the containing directory writeable by the web server. If you're trying to add a file, navigate to the folder you're adding it to and run the following: chmod go+w .. If you're trying to delete/edit a file, trying the following: chmod go+w myfile.txt.

When running a script from the command line it runs as the logged in user, whereas when running it through a browser it is run as the web server user (usually a user named www.) This user generally doesn't have write access to the files and directories that are being served.

Upvotes: 4

philwinkle
philwinkle

Reputation: 7056

Check your phpinfo() output to see if safe mode is enabled. Also check to see if suhosin or mod_security are enabled. All of these can limit your ability to use exec()...

Upvotes: 2

Related Questions