Libreoffice --headless se niega a convertir a menos que sea root, no funcionará desde el script PHP

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

Funciona como un encanto.


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

Maldita sea.


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

Maldita sea.

Anyone have any idea? Trying to research this just confused me more. Is this probably a bug or some dependency quirk?

preguntado el 24 de agosto de 12 a las 01:08

I have the same problem in Ubuntu 12.04, I am trying to convert ods files to pdf and it's working with sudo only -

@Jacek Wysocki - I found a workaround using DocumentConverter.py with LibreOffice ( artofsolve.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. -

I have one too: $ sudo visudo and I've added this line: %users ALL=(ALL) NOPASSWD: libreoffice después de esto sudo libreoffice ... without password -

9 Respuestas

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.

Respondido el 17 de enero de 15 a las 02:01

This really should be the accepted answer. You saved my day. - Capitán Witbaard

También puedes usar: 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. - perplejidad

Works well for me Thanks @greatmatter - adeel branquia

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 mostró: 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)

con TMPDIR=app/tmp

Lo arreglamos configurando TMPDIR to a directory that is writeable by the App process' user, i.e. TMPDIR=/tmp on CloudFoundry:

process.env.TMPDIR = "/tmp";

Respondido 12 Abr '16, 07:04

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

Respondido el 27 de junio de 18 a las 17:06

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

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

contestado el 08 de mayo de 15 a las 16:05

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 confirma que libreoffice-common: /usr/bin/soffice). - pbhj

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.

Respondido el 30 de enero de 19 a las 08:01

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.

Ejemplo:

$ libreoffice --headless --convert-to pdf --outdir myfolder/ myfile.docx

Respondido 24 Jul 20, 07:07

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 (consulte la sección del 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 ...

respondido 28 mar '22, 13:03

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.

Respondido 03 Jul 13, 22:07

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.

De

user = www-data 
group = www-data

A:

user = ubuntu
group = ubuntu

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

contestado el 07 de mayo de 14 a las 08:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.