Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing wkhtmltopdf from PHP fails

There have been a few topics similar to mine, but they did not help me. Maybe something new will come up.

Problem: I can't execute wkhtmltopdf form PHP. My basic code is: exec('wkhtmltopdf http://somesite.com /home/user/file.pdf');

Now a few things I already checked:

  • the same command works when executed from console
  • safe_mode is disabled - I can execute commands in PHP, for example exec('ls'); works fine
  • path to wkhtmltopdf can be found and I can run the program itself, for example exec('wkhtmltopdf -V'); works fine and outputs versioning info
  • the output path is writable, it has 777 permissions and exec('wkhtmltopdf -V > /home/user/file.pdf'); works fine, creates the file and puts versioning info inside
  • executing from PHP has internet access, for exemple exec('wget -O /home/user/file.pdf http://somesite.com') works fine, retrieves the site source and puts it into the file
  • replacing exec with passthru, shell_exec etc. makes no difference

Concluding: I can execute wkhtmltopdf, I can access internet, I can write the specific file, but a correct conversion command fails and returns status 1.

I use the latest Ubuntu, PHP Version is 5.3.10-1ubuntu3, wkhtmltopdf version is 0.9.9. I tried it also on some other machine with the same retults.

Any (just ANY) ideas will be greatly appreciated!

like image 541
Krzychu Avatar asked May 17 '12 07:05

Krzychu


1 Answers

Add 2>&1 to the end of your command to understand the exact error.

exec('wkhtmltopdf http://somesite.com /home/user/file.pdf 2>&1');

This way it will tell you the error when running this under Apache. Once you know what's wrong, it is easier to address. I had a similar problem before with ImageMagick

like image 132
dakdad Avatar answered Sep 20 '22 13:09

dakdad