Running libreoffice from php exec()

libreoffice convert-to pdf command line
libreoffice command line
libreoffice command line save as
convert docx to pdf libreoffice php
libreoffice convert file
libreoffice laravel
libreoffice headless --convert-to html
convert ods to pdf command line

I have installed libreoffice headless on a freebsd-server with apache in order to convert documents programmatically (e.g. odt->pdf). It works from the command line! But my goal is to be able to do it from php. This demands that the web-user (www) can run libreoffice. But it cannot.

When running libreoffice as my own user, I get:

%libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found #This should not be a problem, says people on the net.
convert /usr/home/ ->
 /usr/home/ using writer_pdf_Export

If I try the same command as root, it does not work. The same is the problem with the www-user from php:

sp# libreoffice --headless -convert-to pdf Litteraturundervisningogit.doc
javaPathHelper: not found

The problem is that I do not get any information from libreoffice, thus I don't know why libreoffice does not want to run as other users than my own.

My question is: How do I give the www-user permission to run libreoffice via exec() in php?

I managed to fix this issue with a quick export HOME=/tmp before running the convert command, this gives libreoffice somewhere writable to work it's magic.

Running libreoffice from php exec(), Running libreoffice from php exec() - php. libreoffice as www-data under apache. I'll recomend put config path first you run exec() or shell_exec(); IE: // Vars� This led me to the assumption that this had to do with the php code executing the exec() command as the Apache user 'www' in my operating system. Looking at other forums people have mentioned issues running this command from PHP through Apache due to their either being no home or temporary directory for the conversion to take place.

Not strictly an answer, but rather than using PHP's exec, you might consider using PUNO, a PHP5 module that provides access to the UNO Programming API.

Running Libreoffice --convert-to Command from Exec(), libreoffice --headless --convert-to pdf --outdir $outputDirHere I try to run it through PHP in ProcessMaker using the exec() command it doesn't� On Windows-Apache-PHP servers there is a problem with using the exec command more than once at the same time. If a script (with the exec command) is loaded more than once by the same user at the same time the server will freeze. In my case the PHP script using the exec command was used as the source of an image tag.

Did you look at this blog post?

Libreoffice running headless from php exec(), Hi, I have installed libreoffice headless in order to convert documents do I give the www-user permission to run libreoffice via exec() in php? I am running into problems with shell_exec. I want to convert a *.doc file into png with libreoffice. The .doc file lies within the files folder of a drupal website. The command I want to execute (in a php file) is the following:

This works for me.

Make sure you have installed java RE, for example in ubuntu:

apt-get install default-jre

First, find the location of your libreoffice

$ which libreoffice

Include the folder location in the PATH, and also set the HOME var by adding these lines:

system("libreoffice .....

Convert file to PDF using LibreOffice under user apache (i.e. when , So, create a tmp directory in the same folder where you store your webpage and then run the following php code: <?php shell_exec('export HOME=/tmp &&� see the same problem in centos 7.3 with php-fpm, and php-fpm is run under apache user. the solution is chown of home diretory of apache /var/www chown apache /var/www systemct restart php-pfm.service. because the libreoffice need write .config/libreoffice in the /var/www 👍

I was having the same problem and yes (thanks Wrikken) after prepending /usr/local/sbin to the PATH environment variable I was able to run libreoffice as www-data under apache.

Libreoffice Problem, I have installed Libreoffice to convert doc file in to pdf file. terminal but when the same command is executed using PHP's exec(), it is not working. I found that PHP script is not getting permission to run libreoffice command. The pcntl_exec() function works exactly like the standard (unix-style) exec() function. It differs from the regular PHP exec() function in that the process calling the pcntl_exec() is replaced with the process that gets called.

Running libreoffice from php exec, Running libreoffice from php exec() location: - date: January 30, 2012. I have installed libreoffice headless on a freebsd-server with apache� I've tested this on CentOS 64-bit, with LibreOffice 3.4.5 and, and it works - kind of. With both versions of LibreOffice, the provided folder is used as HOME without problems - as long as it has a LibreOffice profile folder within it. If it doesn't, LibreOffice (both versions) creates the profile folder and then exits, returning code 81.

shell_exec - Manual, Note: This function is disabled when PHP is running in safe mode. See Also �. exec() - Execute an external� If you’re running a portable version of LibreOffice on Windows, the user profile folder is located in the \Data\settings\user folder in the folder where you installed the program. For example, for our portable version of LibreOffice, the user profile folder is at C:\Users\Lori\Documents\Portable Software\LibreOffice\Data\settings\user. macOS

exec - Manual, Example #1 An exec() example. <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) Purchase or download the latest LibreOffice Getting Started Guide, written by community experts. LibreOffice, the best free and open source office suite.

  • Is it just a PATH issue? What is in their respective $PATH's?
  • You tested by command line with root user, %sudo php program.php, that as client have permission?
  • That is very smart... You probably saved me a lot of time. Thanks.
  • This solves hanging conversions from PHP for me, but can you tell me what this exactly does? Why does this solve hanging conversions?
  • Libreoffice writes shadow/temporary/hidden files to the user's (the user running PHP, normally apache or http or www-data) home directory. The user running PHP from a webserver (not from CLI) never normally has a home directory, so the $HOME env variable will be blank or not set and libreoffice cannot write to /. So setting this explicitly to tmp gives libreoffice a bit of space with permission to write. HTH
  • I am a little biased, for obvious reasons, but I think this is the best solution :)
  • @nikyspag Sir, please could you share your code with me.