Unoconv 作为 apache 用户无法创建文件

Unoconv as apache user unable to create files

我以 apache 用户身份使用 unoconv 创建 PDF 文件。它 运行 作为终端用户没问题,但当我 运行 作为 apache 用户时。我收到错误。

sudo -u apache  /usr/bin/unoconv -o /home/gloryque/tmp/1431347151.pdf -f pdf /home/gloryque/tmp/8.doc

我遇到错误

mkstemp("/usr/share/httpd/.execoool7VwpU") failed: Permission denied
mkstemp("/usr/share/httpd/.execooouoUVdw") failed: Permission denied
mkstemp("/usr/share/httpd/.execooopRuy27") failed: Permission denied
mkstemp("/usr/share/httpd/.execooov92dRJ") failed: Permission denied
mkstemp("/usr/share/httpd/.execoooiZZVFl") failed: Permission denied
mkstemp("/usr/share/httpd/.execooowk5LuX") failed: Permission denied
mkstemp("/usr/share/httpd/.execoooCgtDjz") failed: Permission denied
mkstemp("/usr/share/httpd/.execoooLxXy8a") failed: Permission denied
mkstemp("/usr/share/httpd/.execooo8LCvXM") failed: Permission denied

我在centos 7机器上

unoconv 尝试在 /usr/share/httpd 中写入一些临时数据。它显然没有这样做的权限。

在我的测试中(在 Ubuntu 系统上),HOME 环境变量一直是关键点。使用

HOME=/tmp sudo -u apache  /usr/bin/unoconv -o /home/gloryque/tmp/1431347151.pdf -f pdf /home/gloryque/tmp/8.doc

暂时将 HOME 设置为 /tmp 解决了该问题。

apache 用户还需要将结果数据写入目标目录的权限 /home/gloryque/tmp

我推荐以下内容:

  • 使用最新版本的unoconv(发布时至少v0.7,或者今天GitHub的master分支)

  • 使用最新的 LibreOffice 稳定版本(最新版本使用更少的内存,通常速度更快且崩溃更少)

  • 使用本机 LibreOffice python 二进制文件到 运行 unoconv,例如。 /opt/libreoffice4.4/program/python /usr/bin/unoconv -f pdf file.doc

  • 硬编码 unoconv 脚本 shebang 中的 python 路径,所以放在第一行 #!/opt/libreoffice4.4/program/python 而不是 #!/usr/bin/env python。 (Apache/PHP通常不设置PATH,所以unoconv失败)

  • 确保用户 运行ning unoconv 有权访问其 HOME 目录

如果您执行上述操作,一切都会顺利进行。如果 LibreOffice 仍然崩溃,您应该将其与上游项目联系起来。另请注意,LibreOffice 无法同时处理多个 connection/client,因此理想情况下,您的 PHP 脚本应正确锁定 and/or 队列请求。

如果您还有任何问题,请报告给:http://github.com/dagwieers/unoconv/issues