ncjoes / office-converter

PHP Wrapper for LibreOffice
MIT License
197 stars 75 forks source link

Works on Homestead/Vagrant but error on RedHat/Centos/Apache-Permissions Issue #15

Open hzuluaga opened 4 years ago

hzuluaga commented 4 years ago

On my dev environment, which is Laravel homestead/Vagrant, it works fine. However on my production env , which is a redhat7/apache2.4.6 , it does not. I have installed Libreoffice v6.3.3.2 on both envs.

Before installing your package, I was calling “libreoffice command ” from Laravel through an exec call:

exec("libreoffice --headless --convert-to pdf --outdir '".$tmpdir."' '".$tmpdir.$filename."'");

If $tmpdir has a very large path, I get a “ file not found error” message, even if the “libreoffice --headless --convert-to pdf” command is launched directly in the terminal, but if the path is relatively small it works and converts the file , but only if run in the terminal. If I try to run the exec function with the libreoffice command passing a $tmpdir variable with a small path inside my Laravel controller, the word document is generated on my Dev environment but not in my Production environment, the file is not converted, apparently due to permissions issues , the “apache user” does not have permissions to run the libreoffice command. I searched how to allow “apache user” to execute external scripts using php “exec” function but it seems it’s required to give root permissions to apache user which is not recommended at all for security reason obviously.

It was then when I decide to look for more options, and found your package, which I installed in both my dev and prod env, and the code goes :

 use NcJoes\OfficeConverter\OfficeConverter;

     $outputdir=$this->storage_documents->path($this->file_path."/");
    $filename_parts = explode('.', $filename);
    $filename_parts[1] = 'pdf';
    $pdf_filename= implode('.', $filename_parts);

    $converter = new OfficeConverter($outputdir.$filename);
    $converter->convertTo($pdf_filename);

On my local dev env it works perfectly ( homestead/vagrant on a mac) , but in production, I get the following error message :

rename(/var/www/html/jep_indi_test/storage/app/documentos_expedientes/Sala de Definición de Situaciones Jurídicas/Despacho 001/1569335404-141/SUBSDSJ-SOME-SusAsu-PEDR-563-2019/secretaria judicial_oficio-o ficio-Orfeo.pdf,/var/www/html/jep_indi_test/storage/app/documentos_expedientes/Sala de Definición de Situaciones Jurídicas/Despacho 001/1569335404-141/SUBSDSJ-SOME-SusAsu-PEDR-563-2019/secretaria judicial_oficio-oficio-Orfeo.pdf): No such file or directory

It seems the PDF was never created , maybe due to permissions or any other reason!

I would appreciate you could give any advice or hint with my case.

thx

nielsvangijzen commented 4 years ago

Does the whole path exist before you write to it?

BuddhiAbeyratneAL commented 2 years ago

https://www.phpdocx.com/documentation/conversion-plugin/debugging-libreoffice