'Libreoffice --headless refuses to convert unless root, won't work from PHP script
Running headless Ubuntu server 12.something.
root@server: chown www-data /my/path/ -R
root@server: chgrp www-data /my/path/ -R
root@server: chmod 755 /my/path/ -R
root@server: libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf
Works like a charm.
root@server: sudo -i -u www-data
$libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf
Error: Please reverify input parameters...
Damn.
root@server: sudo -i -u someotheruser
$libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
convert /my/path/foo.ppt -> /my/path/foo.pdf
Error: Please reverify input parameters...
Damn.
Anyone have any idea? Trying to research this just confused me more. Is this probably a bug or some dependency quirk?
Solution 1:[1]
I finally found an answer to this... Add:
export HOME=/tmp &&
to the beginning, so:
export HOME=/tmp && libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path
That worked for me on CentOS 6.5, and as shell_exec() in PHP.
Solution 2:[2]
We faced the same issue when running the soffice binary headless (LibreOffice 5.0.5.2) in a CloudFoundry (Diego) container as part of a NodeJS app.
It seems newer versions of libreoffice do not expect a writeable HOME, but try to write to TMPDIR.
strace showed:
8349 mkdir("app/tmp", 0777) = -1 ENOENT (No such file or directory)
8349 open("app/tmp/lu8349pzgegi.tmp", O_RDWR|O_CREAT|O_EXCL, 0600) = -1 ENOENT (No such file or directory)
with TMPDIR=app/tmp
We fixed it by setting TMPDIR to a directory that is writeable by the App process' user, i.e. TMPDIR=/tmp on CloudFoundry:
process.env.TMPDIR = "/tmp";
Solution 3:[3]
All what you need to do - create folder "/var/www/.config". When you try to convert some file under www-data user libreoffice require ".config" dir in user's home directory. But libreoffice has no permissions to create such folder. User www-data default home directory is "/var/www". So just run commands:
sudo mkdir /var/www/.config
sudo chmod 700 /var/www/.config
sudo chown www-data /var/www/.config
Solution 4:[4]
I had this same error, but the problem wasn't root access. The command was wrong.
This worked for me, getting text from a doc in LibreOffice 4.2.:
soffice --headless --convert-to txt:Text file_to_convert.odt
(http://ask.libreoffice.org/en/question/14130/how-do-i-install-filters-for-the-soffice-command/)
Solution 5:[5]
I was able to get over this issue by deleting the file first and then running the convert file. Looks like the overwrite of the file failed due to file owner issues.
Solution 6:[6]
For me it was due to unwritable output folder. Use --outdir and specify a writeable folder.
If output file already exists, it will overwrite automatically.
Example:
$ libreoffice --headless --convert-to pdf --outdir myfolder/ myfile.docx
Solution 7:[7]
The environment variables used by LibreOffice are listed here: https://wiki.documentfoundation.org/Development/Environment_variables#System_Variables
The environment variable in question seems to be related to XDG_CONFIG_HOME (see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables) but setting it does not solve the issue.
So the best that we can do is in the line of the answer from greatmatter
HOME=/tmp libreoffice ...
Solution 8:[8]
Much as Jacek stated in his comment, make the user you are trying to execute the command as a sudoer with no password required. Then change your libreoffice command to be
sudo libreoffice <rest of command>
Worked for me. I had the same issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | greatmatter |
| Solution 2 | Matthias Winzeler |
| Solution 3 | sNICkerssss |
| Solution 4 | |
| Solution 5 | crafter |
| Solution 6 | mnazwan |
| Solution 7 | Raffi |
| Solution 8 | Mysrt |
