I want to generate a PDF from a URL, so I execute the command by WkHTMLtoPDF as below: /usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/local/bin/wkhtmltopdf http://www.google.com /tmp/google.pdf 2>&1 The above command works fine on Terminal, But when I invoke the command inside PHP failed! And show me an error message as below: array(2) {
[0]=> string(27) "which: no xauth in ((null))"
[1]=> string(40) "xvfb-run: error: xauth command not found"} I don't know how to resolve this issue! Anyone can help me on this, my OS environment as below: My PHP code as below: <php
$var = array();
$res = 0;
$cmd = '/usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/local/bin/wkhtmltopdf http://www.google.com /tmp/google.pdf 2>&1';
exec($cmd, $var, $res); echo $cmd.'<br />';
var_dump ($var);?> php centos wkhtmltopdf xauth | this question edited May 30 '15 at 5:12 TessellatingHeckler 12.5k 3 15 36 asked May 30 '15 at 5:04 Chunhui Zhang 6 1 3 Checked if safe-mode is disabled? – joao Beno May 30 '15 at 5:05 You mean safe_mode = Off? I checked the safe_mode is Off in php.ini – Chunhui ZhangMay 30 '15 at 6:27 You tried to run just /usr/local/bin/wkhtmltopdf http://www.google.com /tmp/google.pdf ? – joao Beno May 30 '15 at 15:24 @joaoBeno Yes,I tried to run the command without xvfb-run inside PHP and failed! But succeed on command line. – Chunhui Zhang May 30 '15 at 17:01 @joaoBeno I think this is a permission issue? How to grant the permission to nobody user to run wkhtmltopdf? – Chunhui Zhang May 30 '15 at 17:03 | show more comments 1 Answers 1解决方法 For CentOS PHP environment the WkHTMLtoPDF tool not need xvfb-run to exec the command, But for Ubuntu PHP environment need xvfb-run to exec the command! I had revised my code as below and the issues was resolved: $osName = 'lsb_release -d 2>&1';exec('lsb_release -d', $osName);$isCentOS = strrpos(strtolower($osName[0]), 'centos');
$cmd = '/usr/local/bin/wkhtmltopdf http://www.google.com /tmp/google.pdf 2>&1';if ($isCentOS === false) { $cmd = '/usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/local/bin/wkhtmltopdf http://www.google.com /tmp/google.pdf 2>&1';
} The issues is currently resolved and Thanks @joaoBeno saved me for fixed this issue~~ | this answer answered May 31 '15 at 4:01 Chunhui Zhang 6 1 3
|