8

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..

Syed Abdur Rehman Kazmi
  • 1,530
  • 3
  • 11
  • 24

3 Answers3

1

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

Tarun Lalwani
  • 124,930
  • 8
  • 149
  • 214
0

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/

nitinsridar
  • 562
  • 1
  • 4
  • 22
  • composer update ? why that ? i have tried composer dump-autoload – Syed Abdur Rehman Kazmi Mar 03 '18 at 13:52
  • What’s the difference between composer dump-autoload, composer update and composer install? Please refer the below link: http://developed.be/2014/08/29/composer-dump-autoload-laravel/ – nitinsridar Mar 03 '18 at 17:06
  • i am not asking for the difference. i want to know why you want me to do that ? – Syed Abdur Rehman Kazmi Mar 04 '18 at 10:11
  • compsoer dump-autoload, Definition: composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project. – nitinsridar Mar 05 '18 at 07:46
0

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.

Hamza Mohamed
  • 1,172
  • 1
  • 10
  • 26