Why doesn't my PHP function work as expected?

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.

  • Answer:

    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.

cheng at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

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()...

philwinkle

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.

mahadeb

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.