Running libreoffice from php exec()

前端 未结 7 1288
臣服心动
臣服心动 2020-12-16 16:05

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

相关标签:
7条回答
  • 2020-12-16 16:23

    I'll recomend put config path first you run exec() or shell_exec();

    IE:

    // Vars
    putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
    putenv('HOME=' . $outputdir); 
    

    $outputdir = chmod 777 And the same forlder from libreoffice command "--outdir"

    0 讨论(0)
  • 2020-12-16 16:26

    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
    /usr/bin/libreoffice
    

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

    putenv('PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin');
    putenv('HOME=/tmp'); 
    system("libreoffice .....
    
    0 讨论(0)
  • 2020-12-16 16:29

    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.

    0 讨论(0)
  • 2020-12-16 16:32

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

    0 讨论(0)
  • 2020-12-16 16:33

    About Universal Network Objects (UNO), there are some "plug-and-play" final-user tools, see Docvert and JODConverter (jODconverter and pyODconverter). All of then can be called as web-service or exec by PHP.

    0 讨论(0)
  • 2020-12-16 16:43

    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.

    0 讨论(0)
提交回复
热议问题