PHP how to execute a command

前端 未结 4 1652
北荒
北荒 2021-01-06 13:49

I\'m trying to use LibreOffice for converting a spreadsheet to another format, when I execute the command from the console it works fine but when I do it from PHP using exec

4条回答
  •  遥遥无期
    2021-01-06 14:09

    I solved this problem with the command below :

    exec('libreoffice --headless --invisible --norestore --convert-to pdf --outdir /my/folder /my/file/calc.xls');
    

    Just check rights, libreoffice uses user home folder, If you use default settings for Ubuntu then PHP runs oenter code heren www-data rights and it's home is /var/www/, but default this directory is owned by root.enter code here

    In PHP - you can see rigths:

    exec('whoami', $arr);
    print_r($arr);
    

    In console - You can see your HOME and give correct rights:

    su wwww-data
    echo $HOME
    exit;
    chown www-data:www-data /var/www -R
    

提交回复
热议问题