2

I had a problem while using PHP exec(). I am not able to figure out the issue and I have tried with following code:

exec("pdfcrop --margins '-6 -2 -3 -2' '/home/username/pdf/Figure 1 Timeline of Virtual Sim Use/page.01.pdf' '/home/username/pdf/out/output.pdf'", $output, $error);

Whenever I use this commands in exec() it returns status code of 2 but if I use this command to my terminal then it works well. So kindly give your suggestion to solve this problem.

thank you..

4
  • 2
    Maybe this might help Commented Jan 16, 2014 at 10:32
  • Thanks for your response. Also i have tried with shell_exec() but same result not working. Commented Jan 16, 2014 at 10:35
  • exec() doesn't return status codes, it returns the last line from the result of the command. Do you mean that $error is 2? Do you mean PDFCrop? Commented Jan 16, 2014 at 10:43
  • yes it is an error code and i need to run pdfcrop with exec() function Commented Jan 16, 2014 at 10:45

3 Answers 3

6

php exec function runs the process under the apache user ( www-data ) user most probably this user does not have access to : /home/username/pdf/Figure

You can test this very easy by trying to change this path to /tmp/name of pdf file.pdf

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

Comments

0

pdfcrop is a Perl program. Opening it to read, you will find it creates tmp files in current directory.
It works in PHP call after I made the following changes:

  • $tmp = "/tmp/tmp-..."

  • pdftex - add argument -output-directory=/tmp

Comments

0

In case of Linux Debian 9.5 I have got from Php exec() function return code 2 because wrong console for user www-data in /etc/passwd file: I had to change line:

www-data:x:33:33:www-data:/usr/sbin/nologin

To:

www-data:x:33:33:www-data:/var/www:/bin/bash

And now error gone and commands are executed as expected!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.