I have a certain PHP script that calls exec() to execute a command to convert a PDF to JPG. This command works fine in bash.
To preempt your initial troubleshooting guesses, note the following:
When I call this PHP script from the browser (visiting http://www.example.com/script.php), exec() does not execute its argument.
IMPORTANT: I know that there are no issues with my script or the way I have constructed the bash command, because from bash, I can execute the script with 'php' and it works (e.g. 'php script.php' converts the file)
I have also tried switching out exec() with system().
Last, I have had this issue once before in the past but cannot remember how I fixed it.
I know there is something I am missing, so I hope someone else has experienced this as I have and remembers how to fix it!
Thank you in advance for any assistance you can provide.
Alex
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix.
php phpinfo(); ?> You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go. If exec is not listed in the disable_functions line it means that it is enabled.
The PHP execution operator consists of backticks (``) and is used to run shell commands. The output of the command will be returned, and may, therefore, be stored in a variable.
PHP exec will wait until the execution of the called program is finished, before processing the next line, unless you use & at the end of the string to run the program in background.
Add 2>&1
to the end of your command to redirect errors from stderr to stdout. This should make it clear what's going wrong.
Just some guess, it might be that your webserver process user does not have privileges to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With