从 php exec() 运行 libreoffice

2022-01-04 00:00:00 permissions exec php libreoffice

我已经在带有 apache 的 freebsd-server 上安装了 libreoffice headless,以便以编程方式转换文档(例如 odt->pdf).它从命令行工作!但我的目标是能够从 php 做到这一点.这要求网络用户 (www) 可以运行 libreoffice.但它不能.

I have installed libreoffice headless on a freebsd-server with apache in order to convert documents programmatically (e.g. odt->pdf). It works from the command line! But my goal is to be able to do it from php. This demands that the web-user (www) can run libreoffice. But it cannot.

以我自己的用户身份运行 libreoffice 时,我得到:

When running libreoffice as my own user, I get:

%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也是同样的问题:

If I try the same command as root, it does not work. The same is the problem with the www-user from php:

sp# libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found
sp#

问题是我没有从 libreoffice 获得任何信息,因此我不知道为什么 libreoffice 不想作为我自己以外的其他用户运行.

The problem is that I do not get any information from libreoffice, thus I don't know why libreoffice does not want to run as other users than my own.

我的问题是:如何在 php 中通过 exec() 授予 www-user 运行 libreoffice 的权限?

My question is: How do I give the www-user permission to run libreoffice via exec() in php?

推荐答案

在运行 convert 命令之前,我设法通过一个快速的 export HOME=/tmp 解决了这个问题,这使 libreoffice 在某个地方可写工作很神奇.

I managed to fix this issue with a quick export HOME=/tmp before running the convert command, this gives libreoffice somewhere writable to work it's magic.

相关文章