I installed libreoffice-headless and can convert documents when logged on into the shell as a normal user.
[root@desktop ~]# yum install libreoffice-headless [root@desktop ~]# yum install libreoffice-writer [root@desktop ~]# su NotionCommotion sh-4.1$ /usr/bin/libreoffice --headless -convert-to pdf --outdir /tmp/ayb /tmp/ayb/document_34.doc convert /tmp/ayb/document_34.doc -> /tmp/ayb/document_34.pdf using writer_pdf_Export
I now wish to do the same thing, but using PHP and therefore as user apache, however, the following will not convert the file.
<?php shell_exec('/usr/bin/libreoffice --headless -convert-to pdf --outdir /tmp/ayb /tmp/ayb/document_34.doc'); ?>
In an attempt to troubleshoot, I ran the same command through the shell as user apache, but still it will not convert the file:
[root@desktop ~]# su -s /bin/sh apache -c "/usr/bin/libreoffice --headless -convert-to pdf --outdir /tmp/ayb /tmp/ayb/document_34.doc"
Apache unlike normal users doesn't have a home, and I recall hearing I might need to specify a home using
HOME=/tmp/ayb before attempting to convert, but it doesn't help (I think when using CentOS 5.8 and probably a different version of LibreOffice, it did, but am not certain).
How do I convert a file to PDF using libreoffice when running it as user apache?
CentOS 6.4 httpd.x86_64 2.2.15-28.el6.centos @updates libreoffice-headless.x86_64 1:18.104.22.168-16.1.el6_3 @base