Running libreoffice from php exec()

吃可爱长大的小学妹 提交于 2019-11-29 03:44:37

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.

Not strictly an answer, but rather than using PHP's exec, you might consider using PUNO, a PHP5 module that provides access to the OpenOffice.org UNO Programming API.

I was having the same problem and yes (thanks Wrikken) after prepending /usr/local/sbin to the PATH environment variable I was able to run libreoffice as www-data under apache.

I'll recomend put config path first you run exec() or shell_exec();

IE:

// Vars
putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
putenv('HOME=' . $outputdir); 

$outputdir = chmod 777 And the same forlder from libreoffice command "--outdir"

About Universal Network Objects (UNO), there are some "plug-and-play" final-user tools, see Docvert and JODConverter (jODconverter and pyODconverter). All of then can be called as web-service or exec by PHP.

This works for me.

Make sure you have installed java RE, for example in ubuntu:

apt-get install default-jre

First, find the location of your libreoffice

$ which libreoffice
/usr/bin/libreoffice

Include the folder location in the PATH, and also set the HOME var by adding these lines:

putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
putenv('HOME=/tmp'); 
system("libreoffice .....
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!