I am having an Issue while running libreoffice from shell_exec inside a php script. This script is for converting DOCX to HTML via Libreoffice. The script is working well in terminal but not inside web browser. I have also tried to setup HOME to /tmp, but not working at all.
<?php
$soffice_path = '/usr/sbin/soffice';
$path_with_perm_777 = '/opt/lampp/htdocs/tmp';
$docx_file = __DIR__ . '/sample.docx';
echo `which soffice`;
echo `whoami`;
echo shell_exec('echo ${PATH}');
$command = escapeshellcmd('export HOME="/tmp"') . " && " . escapeshellcmd($soffice_path.' --headless --convert-to pdf --outdir '. $path_with_perm_777 .'/converted/ '.$docx_file);
var_dump( shell_exec($command) );
Output in terminal :-
/usr/bin/soffice
jack
${PATH}:/usr/bin/custom/:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin
string(175) "convert /opt/lampp/htdocs/sample.docx -> /opt/lampp/htdocs/tmp/converted//sample.pdf using filter : writer_pdf_Export Overwriting: /opt/lampp/htdocs/tmp/converted//sample.pdf"
Output in web browser :-
/usr/sbin/soffice
jack
/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
NULL
Output of ( ls -l /opt/lampp/htdocs/ ) :
drwxrwxrwx 2 jack jack 4096 Jan 23 13:50 tmp
System Info:
PHP 5.6.39, Manjaro Linux 18.0.2, LibreOffice 6.1.4.2