0

I got a problem when converting doc to pdf using libreoffice5 in php.

I wrote a Linux shell to convert a office doc document to pdf (t.sh):

#!/bin/sh
libreoffice5.0 --headless --invisible --convert-to pdf --outdir $1 $2

Then I created a php file in apache htdocs dir as follows (mytest.php):

<?php 
$cmd = './t.sh ./ ./55ffbc34c3808.docx';
var_dump($cmd);

$rtn = exec($cmd, $rtnResult, $rtnVal);
var_dump($rtnResult);

But when I run http://localhost/mytest.php, the page never stop and no result was printed (no pdf was generated). When I run ps -ef|grep libre, I saw the following:

maijin   10403 10402  0 03:11 ?        00:00:00 /opt/libreoffice5.0/program/oosplash --headless --invisible --convert-to pdf --outdir ./ ./55ffbc34c3808.docx
maijin   10420 10403  1 03:11 ?        00:00:00 /opt/libreoffice5.0/program/soffice.bin --headless --invisible --convert-to pdf --outdir ./ ./55ffbc34c3808.docx
maijin   10427  8755  0 03:11 pts/1    00:00:00 grep libre

These processes never stop. I check the libreoffice and it is correct:

>ls -l  /usr/local/bin/libreoffice5.0
lrwxrwxrwx 1 root root 35 Aug 22 02:54 /usr/local/bin/libreoffice5.0 -> /opt/libreoffice5.0/program/soffice

If I run the t.sh shell in linux console, the pdf file can be generated. Why can't I convert the doc to pdf in php?

mjstudio
  • 1
  • 1
  • Kill all previous "zombie" soffice process. Get sure apache user has the privileges of creating new files in the directory you want them to be created. – Amarnasan Sep 22 '15 at 10:53
  • I killed all zombie but it didn't work. I already did: chmod -R a+rw ./ – mjstudio Sep 23 '15 at 02:54
  • 1
    Check this: http://stackoverflow.com/questions/9593724/php-how-to-execute-a-command . Start with the second answer (the one given by @user1662766). Basically you need to tell libreoffice where is the HOME of the user running it. Which is apache. Which happen to have no HOME. Just check it. – Amarnasan Sep 23 '15 at 06:19

0 Answers0