我已经在带有apache的freebsd-server上安装了libreoffice headless,以便以编程方式转换文档(例如odt-> pdf)。它从命令行工作!但我的目标是能够从PHP做到这一点。这要求web用户(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-user的问题:
sp# libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found
sp#
问题是我没有从libreoffice获得任何信息,因此我不知道为什么libreoffice不想像其他用户那样运行。
我的问题是:如何通过php中的exec()授予www-user权限来运行libreoffice?
在设置转换命令之前,我设法用快速的export HOME=/tmp
解决了这个问题,这使得libreoffice可以在某个地方写入来实现它的魔力。
不是严格的答案,而是使用PHP的exec,您可以考虑使用PUNO,这是一个PHP5模块,提供对OpenOffice.org UNO编程API的访问。
在将/usr/local/sbin
添加到PATH环境变量之后,我遇到了同样的问题并且是(感谢Wrikken)我能够在apache下运行libreoffice作为www-data。
我建议先放置配置路径,然后运行exec()或shell_exec();
IE:
// Vars
putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
putenv('HOME=' . $outputdir);
$ output dir = chmod 777和libreoffice命令中的相同文件夹“--outdir”
关于Universal Network Objects (UNO),有一些“即插即用”的最终用户工具,请参阅Docvert和JODConverter(jODconverter和pyODconverter)。所有这些都可以被PHP称为web-service或exec。
这适合我。
确保已安装java RE,例如在ubuntu中:
apt-get install default-jre
首先,找到你的libreoffice的位置
$ which libreoffice
/usr/bin/libreoffice
在PATH中包含文件夹位置,并通过添加以下行来设置HOME var:
putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
putenv('HOME=/tmp');
system("libreoffice .....