Libreoffice --headless refuses to convert unless root, won't work from PHP script
Asked Answered
C

9

13

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?

Cosmetic answered 24/8, 2012 at 0:38 Comment(3)
I have the same problem in Ubuntu 12.04, I am trying to convert ods files to pdf and it's working with sudo onlyAnodize
@Jacek Wysocki - I found a workaround using DocumentConverter.py with LibreOffice ( artofsolving.com/opensource/pyodconverter ). Only trouble is, you need to daemonize libreoffice, which is kind of a pain in the ass and caused me some trouble. Oh, and the daemon still needs to run as root.Cosmetic
I have one too: $ sudo visudo and I've added this line: %users ALL=(ALL) NOPASSWD: libreoffice after that sudo libreoffice ... without passwordAnodize
F
24

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.

Fabrication answered 17/1, 2015 at 2:48 Comment(3)
This really should be the accepted answer. You saved my day.Algernon
You can also use: HOME=/tmp libreoffice --headless --convert-to pdf:writer_pdf_Export /my/path/foo.ppt --outdir /my/path since you're only setting the HOME variable for one process.Kirmess
Works well for me Thanks @FabricationStays
J
5

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

Junno answered 12/4, 2016 at 6:36 Comment(0)
V
5

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
Vaccination answered 27/6, 2018 at 16:15 Comment(1)
Thank you, I think this is the best solution. It worked for me as the www-data user under Ubuntu 18.04 and LibreOffice 6.3.1.Vennieveno
J
2

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/)

Juanjuana answered 8/5, 2015 at 10:38 Comment(1)
In addition I had to quote the filter name soffice --headless --convert-to txt:"Text" ./*.docx (yes this is for a LibreOffice install on Kubuntu 14.10, apt-file confirms that libreoffice-common: /usr/bin/soffice).Koch
U
0

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.

Uphill answered 30/1, 2019 at 8:33 Comment(0)
V
0

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
Voluble answered 24/7, 2020 at 6:27 Comment(0)
N
0

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 ...
Nablus answered 28/3, 2022 at 12:38 Comment(0)
C
-1

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.

Chemoreceptor answered 3/7, 2013 at 21:20 Comment(0)
M
-3

You can not run libreoffice soffice binary with www-data user. Use a user with sudo privilege instead. Check my Gist https://gist.github.com/nathanielvarona/423bda9e4a8a4f0f9bbf#file-soffice-listener-sh

And since you are going to use this in PHP. Just give a try also to PHP-FPM. Install it and then modify the /etc/php5/fpm/pool.d/www.conf file.

From

user = www-data 
group = www-data

To:

user = ubuntu
group = ubuntu

I've successfully run this in AWS EC2 and also with my VBox VMs.

Mauromaurois answered 7/5, 2014 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.