1

I am unable to execute the following command under user apache using php exec function.

exec('/usr/bin/libreoffice --headless --convert-to pdf --outdir /var/www/html/ /var/www/html/coverpage.doc');

OS : CentOS 6.4 Final

Any help or suggestions are highly appreciable. Thanks

neubert
  • 15,947
  • 24
  • 120
  • 212
LX7
  • 609
  • 1
  • 6
  • 22
  • use a php pdf class? dompdf, tcpdf, phpexcel, phpword etcetc – Dave Nov 12 '13 at 10:23
  • What happens if you use the command by itself? What user is your PHP running as? Does that user have access to the executeable? – h2ooooooo Nov 12 '13 at 10:35
  • @h2ooooooo : via direct ssh, command works good. but via php its not working. PHP is running under user apache. – LX7 Nov 12 '13 at 10:51
  • @LX7 Then I'll ask again - [switch user to the "apache" user](http://unix.stackexchange.com/questions/3568/how-to-switch-between-users-on-one-terminal) and then run the command. Does it **then** work good? – h2ooooooo Nov 12 '13 at 10:56
  • @h2ooooooo: No its not working for user apache, Can you please tell me how can i set executable permission for user apache..??? – LX7 Nov 12 '13 at 10:58
  • 1
    @LX7 [Perhaps you can try this](http://stackoverflow.com/questions/9593724/php-how-to-execute-a-command) or [this](http://superuser.com/questions/627266/convert-file-to-pdf-using-libreoffice-under-user-apache-i-e-when-using-php) – h2ooooooo Nov 12 '13 at 11:18
  • @LX7 If you figured out how to fix it then make sure to add it as an answer so whoever else has this problem can figure it out as well. – h2ooooooo Nov 13 '13 at 12:17

3 Answers3

1

First check for the permission given for /var/www folder. Give apache:apache as owner for /var/www/.

Use the below command to install libreoffice headless package if it is not installed.

sudo yum install openoffice.org-headless

This has worked for me in centOS.

LX7
  • 609
  • 1
  • 6
  • 22
Liju Raj
  • 76
  • 4
0

There may be numerous reasons start by redirecting command error output to a file and then continue troubleshooting from there :

exec('/usr/bin/libreoffice --headless --convert-to pdf --outdir /var/www/html/ /var/www/html/coverpage.doc 2> /tmp/error.txt');

After running the script check /tmp/error.txt.

litechip
  • 326
  • 2
  • 9
0
  1. I would first of all try it with giving absolute paths to the command.

  2. I suspect that the libreoffice binary does not work -- you have to locate the soffice binary and see if that works.

  3. Then, your --convert-to pdf is not sufficient. It needs to be:

    --convert-to pdf:writer_pdf_Export

  4. Next, the command will not work if there is already a LibreOffice GUI instance up and running on your system. Add this additional parameter to your command:

    "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"

  5. Also, make sure that the --outdir /pdf you specify does exist, and that you have write permission to it. Or, rather use a different output dir. Even if it is just for the first testing and this debugging round:

    $ mkdir ${HOME}/lo_pdfs

  6. This works for me on Mac OS X Mavericks 10.9.5 with LibreOffice v4.4.3.2 (using my specific path for the binary soffice which will be different for you anyway...).

    /path/to/soffice                                                     
    

    --headless

    "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"

    --convert-to pdf:writer_pdf_Export

    --outdir ${HOME}/lo_pdfs path/to/test.docx

If this will not work try this answer Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working

Community
  • 1
  • 1
Suneel Kumar
  • 5,621
  • 3
  • 31
  • 44