unable to run oowriter as web user
Asked Answered
E

5

11

I have a web server set up on my laptop. I am building a web application which I am accessing through the local network. I have a php file which contains the following lines:

$command = "/usr/bin/oowriter --invisible --convert-to pdf /var/www/hackathon/document/gaurav.doc -outdir /var/www/hackathon/pdf/"
exec($command, $output, $return_var);
print_r($output);

So, the problem is that when I run the above code in the terminal php runs perfectly. But when accessed via a web browser, output is just empty and no conversion is done as intended.

Apache error log shows the following lines:

[Java framework] Error in function createSettingsDocument (elements.cxx).
javaldx failed!
Warning: failed to read path from javaldx

I have tried solutions from https://wiki.archlinux.org/index.php/Libreoffice#Fixing_Java_Framework_Error. But it didn't work.

I am using OpenJDK 7.

Does anybody have any idea on how to make this work?

Eileneeilis answered 16/4, 2012 at 5:19 Comment(1)
In my case, setting HOME=/tmp, the directory libreoffice try to access, made it work. Fraber and ConsuLanza Informatica have the good approach. Thx guys. Also, the greatmatter answer in this related post helped me figuring it out eventually.Domineering
C
7

Can't vote, can't comment (yet)... So...

What Tim-Erwin said is true.

The error actually states that Error in function createSettingsDocument which is a hint that some function named createSettingsDocument (note: create Settings Document) is failing....

Here's how you (or atleast I) get it to work:

  1. Run libre office as a normal user once and note the directory name it creates.
  2. Check which user the server is running (or which user PHP is running as, which might be different from www-data if you're on FPM etc...).
  3. Check what the home directory is set to for this user (from /etc/passwd for example)
  4. Create the directory noted in step 1 in the directory from step 3
  5. Change owner of created directory to the user from step 2

On my server the needed directory was actually /var/www/libreoffice, while in my desktop machine,the directory would of been /var/www/.config/libreoffice so you need to make sure.

Chavaree answered 27/2, 2015 at 10:0 Comment(0)
I
6

Fraber's answer solved the problem for me!

Used:

$cmd = 'HOME='.getCWD().' && export HOME && libreoffice --headless ....';
exec($cmd);

libreoffice then created '.config' and 'libreoffice' directories in the php script directory. Obviously it must be writeable by the webserver process.

Ironist answered 6/6, 2016 at 21:0 Comment(1)
This is the correct answer - I've been banging my head on this for several hours trying to use both unoconv and libreoffice directly.Rhodolite
Y
3

OpenOffice needs a user directory. Since you are trying to invoke OpenOffice with the web server, you have to grant the respective user write access to is. On Debian, for instance, that would mean to allow www-data to write to /var/www/.openoffice.org/:

mkdir /var/www/.openoffice.org
chown www-data /var/www/.openoffice.org
Yoon answered 31/12, 2012 at 16:12 Comment(1)
I can't mark this answer up as I don't know if it helps with the OP's problem, but it was useful to know in terms of using LibreOffice headlessly with Alfresco 4.2, as this error appears in the logs when attempting (and failing) to preview documents.Geomancer
E
2

I got the same error message running "ooffice --headless --convert-to pptx filename" from a Web server (actually "NaviServer" 4.99). The solutions above did not solve my issue, but they got me on the right track. It turned out that NaviServer changes the "HOME" environment variable to it's installation directory /usr/local/ns, so that LibreOffice tried to access and create a .config folder in this directory. I found out by executing the BASH "set" command from the Web server and checking the environment variables.

Entelechy answered 2/3, 2016 at 16:59 Comment(0)
W
0

I was getting this problem in doc to odf conversion using php file thorugh apache2 in Debian 10 (buster).

In browser and apche logs it shows

"Array ( [0] => javaldx failed! [1] => Warning: failed to read path from javaldx )"

I check syslog at /var/log/syslog and get following errors. which is leads to some permission and directory issue in apache's home directory.

Apr 18 02:44:53 siptrunkbgp kernel: [744789.941286] audit: type=1400 audit(1587192293.959:70491): apparmor="ALLOWED" operation="mkdir" profile="libreoffice-oopslash" name="/var/www/.config/" pid=9835 comm="oosplash" requested_mask="c" denied_mask="c" fsuid=33 ouid=33
Apr 18 02:44:54 siptrunkbgp kernel: [744789.995119] audit: type=1400 audit(1587192294.015:70492): apparmor="ALLOWED" operation="mkdir" profile="libreoffice-soffice" name="/var/www/.config/" pid=9852 comm="soffice.bin" requested_mask="c" denied_mask="c" fsuid=33 ouid=33

So I just create .config directory and give proper permission in my apache root location (/var/www) using below command.

mkdir -p /var/www/.config/libreoffice

chown -Rf www-data.www-data /var/www/.config/

This will allow apache user to create required files for conversion using libreoffice.

Witchcraft answered 18/4, 2020 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.