Erik Stagg
Erik Stagg

Reputation: 88

shell script works fully in terminal but not when run by php

I have a shell script that uses unoconv and then pdftk. when i run the script through the command line it works exactly how i want it to. When i use shell_exec($cmd) in php with the same exact command it runs the script (i know because of the echo's in the script) but it looks like it does not use unoconv (and therefore cannot use pdftk). Any idea on how to troubleshoot this problem? here some code:

 if(isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])){
    $fname = $_FILES["file"]["name"];
    $tmp_name = $_FILES["file"]["tmp_name"];
    $dir = "powerpoints/".$name."/";
    $ispdf = "1";

    $output = shell_exec('mkdir '.$dir);
    chmod($dir, 0777);
    echo $output;
    if(move_uploaded_file($tmp_name, $dir.$fname)){
        chmod($dir.$fname, 0777);
        $cmd = 'importppt.sh '.$name.' '.str_replace(".ppt", "", $fname);
        echo "\n".$cmd;
        $output = shell_exec($cmd);
        echo $output;
    }else{
        $message = "move_uploaded_file() Failed";
    }

and here is the shell script

 #!/bin/bash

 echo $1 ' is the argument:' $2 ' is the second   '
 STRING="/var/www/html/devclassroomproject/powerpoints/"
 echo $STRING$1/$2'.ppt   '

 unoconv $STRING$1/$2'.ppt'
 pdftk $STRING$1/$2'.pdf' burst output $STRING$1/$1'_%2d.pdf'

This is what is printed from echos:

importppt.sh pptest pptestpptest is the argument: pptest is the second 
/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt

edit: to decipher my debugging the command: "importppt.sh pptest pptest" importppt.sh being the shell script; pptest is the first and second argument

printed by the first echo in the shell script: "pptest is the argument: pptest is the second"

printed by the second echo in the script verifying the complete path of the pdf which does exist: "/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt"

sorry for the confusion

Upvotes: 0

Views: 487

Answers (1)

Erik Stagg
Erik Stagg

Reputation: 88

Found out what was wrong. the answer is here http://johnparsons.net/index.php/2013/08/05/how-to-keep-unoconv-apache-from-making-you-sad/

basically you have to set up a home directory for the user for apache2 as www-data and change the path to the shell in the passwd file

he doesnt mention it but the changes will not work unless you restart apache

Upvotes: 1

Related Questions