中药方大全小图标
您当前的位置:首页 > 其他 > 网站日记

解决centos - WkHTMLtoPDF 0.12.2.1 PHP exec xvfb-run: Error: xauth command not found

提示: 阅读权限:公开  来源:原创  作者:中药方大全

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:

  • OS: CentOS release 6.6

  • wkhtmltopdf version: 0.12.2.1

  • nginx version: nginx/1.6.3

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.'&lt;br /&gt;';
    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

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


tags: 解决 centos WkHTML to PDF PHP exec xvfb Error xauth command not found
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. libreoffice7的命令大全
  2. 帝国cms代码片段备忘录
  3. 帝国cms插件之标题生成标题图片
  4. 帝国cms全站搜索的分页格式如何修改-流程
  5. 帝国cms插件安装模板
  6. 帝国cms插件之迅搜
  7. 帝国cms中点卡怎么可以直接用来网站的登录
  8. useragent两千条,爬虫专用
  9. 帝国cms7.2函数大全
  10. php代码判断是不是微信内部浏览器