1

I'm attempting to run the following command through PHP:

$output = shell_exec('sudo /Users/Derk/Code/automation/psc/pdfs.sh 1'); 

This runs the following bash script code:

sudo /usr/local/bin/pdftk cvcheck_template.pdf fill_form data.fdf output output.pdf flatten sudo /usr/local/bin/convert -density 150 -gravity south -geometry +0+150 -composite output.pdf signature.png new_output.pdf 

The bash script works perfectly in the command line but when I attempt to run it via PHP on a web server (MAMP) it does not give me any output. The first command seems to work but the second command gives me nothing.

Any help would be much appreciated.

3
  • Why are you chaining sudo? First to run the script, and then the script apparently also runs sudo. Once is enough... Is the PHP being executed from the shell, or from a webserver? If the latter, check the webserver error log. Commented Oct 22, 2015 at 14:43
  • The PHP is being run through a webserver (MAMP). I checked the PHP error log but it does not show anything unfortunately. Could it be a user permissions issue? Commented Oct 22, 2015 at 23:18
  • You could create a logfile somewhere, e.g. /tmp/debuglogfile and make it writeable by all: chmod 666 /tmp/debuglogfile. Then change the PHP code to shell_exec('sudo /Users/Derk/Code/automation/psc/pdfs.sh 1 2>/tmp/debuglogfile') and see if any error output is written to the logfile. As you write the first command is executed (make sure it is! "seems to work" doesn't cut it), then sudo is apparently set up correctly, so permissions shouldn't be the problem... does the user under which the webserver runs have the same sudo rights as you? Commented Oct 23, 2015 at 8:01

1 Answer 1

0

It ultimately came down to a permissions issue. The individual files touched through running Python scripts through the web browser need to have write access in the www-data group.

My mistake was that they had read and execution rights but no writing rights. So once I chmodded the appropriate files everything worked beautifully.

I also used sudo -u www-data command to test the PHP files without having to test them through the browser. That made testing a lot faster.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.