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
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"
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 .....
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.
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.
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.
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.