php - 从php exec()运行libreoffice

为了以编程方式转换文档(例如odt->pdf),我在带有Apache的FreeBSD服务器上安装了libreoffice Headless。它在命令行中工作!但我的目标是能够从PHP完成这项工作。这就要求网络用户(www)可以运行libreoffice。但它不能。
当以自己的用户身份运行libreoffice时,我得到:

%libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found #This should not be a problem, says people on the net.
convert /usr/home/bundsgaard.net/www/jeppe/foredrag/Litteraturundervisningogit.doc ->
 /usr/home/bundsgaard.net/www/jeppe/foredrag/Litteraturundervisningogit.pdf using writer_pdf_Export
%

如果我尝试使用与root相同的命令,它将不起作用。来自php的www用户也有同样的问题:
sp# libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found
sp#

问题是我没有从libreoffice获得任何信息,因此我不知道libreoffice为什么不想作为我自己的用户运行。
我的问题是:如何授予WWW用户在PHP中通过exec()运行libreoffice的权限?


最佳答案:

在运行convert命令之前,我用一个快速的export HOME=/tmp解决了这个问题,这使libreoffice在某个可写的地方工作起来非常神奇。