سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

  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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top