8
votes

I am trying to convert a files from doc to pdf on my aws linux server. On my previous machine it worked fine but now i am having issues on my new machine. The only difference is i have upgraded from PHP 7.0 to PHP 7.2. and libre office version

LibreOffice 6.0.1.1 00m0(Build:1)

I have tried giving root permissions to libreoffice and the package that executes the command but no success.

This is the package i am using https://github.com/szonov/libreoffice-converter

I am using it with laravel 5.4. This is the code in the package that performs the action

    $replacement = array(
        'bin'        => $this->bin,
        'convert_to' => $convert_to,
        'outdir'     => $outdir,
        'source'     => $this->source
    );
    $cmd = $this->makeCommand($replacement);
    $cmd = "sudo ".$cmd;
    shell_exec($cmd);
    $result = false;
    if (file_exists($outfile)) {
        $this->mkdir(dirname($this->destination));
        $result = rename($outfile, $this->destination);
    }

    // remove temporary sub directory
    rmdir($outdir);
    return $result;

I have tried appending sudo since when i dd the command and execute is using sudo it worked in command line..

3
You are using apache or nginx? Any error logs?Tarun Lalwani
yes apache. no there are no errors. it fails silently.. The issue i am having is apache user cant create a temp folderSyed Abdur Rehman Kazmi
Check which user apache workers run under and then use sudo -u www-data mkdir /tmp/abc and run sudo -u www-data <your command> this will help you understand the issues through terminalTarun Lalwani
The issue is everything works fine from terminal. I have tried changing my vendor folder to www-data permission. same as my tmp folder. still no luckSyed Abdur Rehman Kazmi
Then enable error reporting in your php.ini for the apacheTarun Lalwani

3 Answers

1
votes

So you need to either use something like below

Execute root commands via PHP

Or you should enable to login to the www-data user

sudo usermod -s /bin/bash www-data

Then you should login with that user and fix all the issues with permissions so you can run the command

sudo su www-data

Once you have done this make sure to reset the login using below

sudo usermod -s /bin/nologin www-data

Once the issue is sorted out in user terminal, you can run the commands without issue in apache as well

0
votes

You have to change the ownership of your directory where your storing the files, Please try the below command on your aws ubuntu machine.

sudo chown -R www-data:www-data /var/www/my-project/

0
votes

This issue has only 2 scenarios

  1. The user dont have permission.
  2. The problem is from the code.

I'm moving on the assumption that Laravel is working well with you except for this part

This means that you have access to the storage files, why don't you save there?

If you can save there, compare the folders and your problem is solved.

If you cannot save there, then the issue is from the code which I doubt as you stated that everything is working well previously.