chadrt Posted September 1, 2017 Share Posted September 1, 2017 OK I am banging my head here and it hurts... I am trying to execute a shell script that I wrote and it is being a PITA <?php // for future use $end = $_REQUEST['end']; $start = $_REQUEST['start']; // This DOES NOT WORK - pdfit.sh has temporary permissions 777 $output = shell_exec('/home/webserver/mysite/public_html/commissions/wkhtmltox/bin/pdfit.sh'); echo "<pre>$output</pre>"; // This WORKS GREAT $output = shell_exec('ln -a'); echo "<pre>$output</pre>"; ?> So I know I am able to use shell_exec as in the second example shown, the pdfit.sh script works great from the CL so I am at a total loss. Chad Quote Link to comment https://forums.phpfreaks.com/topic/304838-execute-shell-script-in-php/ Share on other sites More sharing options...
kicken Posted September 1, 2017 Share Posted September 1, 2017 What do you get as output for your script? An error? Nothing? Try adding stderr redirection. $output = shell_exec('/home/webserver/mysite/public_html/commissions/wkhtmltox/bin/pdfit.sh 2>&1'); Also keep in mind that the environment will be difference when the server runs your script compared to when you run it from a terminal. Notable the PATH variable may be different and prevent programs from being found. Use absolute paths to your programs inside your shell script or setup PATH as needed. Quote Link to comment https://forums.phpfreaks.com/topic/304838-execute-shell-script-in-php/#findComment-1550581 Share on other sites More sharing options...
chadrt Posted September 1, 2017 Author Share Posted September 1, 2017 (edited) That gave me the answer I needed. Apache has no permission to write there so even though I applied 777 permissions to the script when run by apache it cant write the resulting file to the directory it resides in. I have had nothing but terrible luck with the whole permissions for my user webserver and apache running as www-data. I have followed several tutorials in this topic all to no avail. Nothing seems to give apache the rights to make files in the system. Short of 777 the entire box lol (NO I WILL NOT DO THAT!) I am at a loss. Thank you for your assistance!!! Funny how all I have done is "hack" many scripts together over the years and I am still a total noob and yet the forum calls me an "Advanced Member" Edited September 1, 2017 by chadrt Quote Link to comment https://forums.phpfreaks.com/topic/304838-execute-shell-script-in-php/#findComment-1550582 Share on other sites More sharing options...
Solution requinix Posted September 1, 2017 Solution Share Posted September 1, 2017 0777 on the script means anyone can read, write, or execute the script. If you're absolutely sure that the script is safe to execute - no vulnerabilities - then you can setuid it to cause it to be run in its owner's account instead of Apache. But there's no guarantee the system will honor that. Otherwise it would be great if you could change things so that the directory it needs to write to is also owned by Apache. Means your personal account couldn't change anything inside without sudo but the script could run without fiddling with permissions. Worst case, set 0777 on the directory so that anyone can read the directory, write new files in it, or traverse the directory. I am still a total noob and yet the forum calls me an "Advanced Member" It says what? 1 Quote Link to comment https://forums.phpfreaks.com/topic/304838-execute-shell-script-in-php/#findComment-1550584 Share on other sites More sharing options...
chadrt Posted September 1, 2017 Author Share Posted September 1, 2017 It says what? That is freaking awesome! 0777 on the script means anyone can read, write, or execute the script. If you're absolutely sure that the script is safe to execute - no vulnerabilities - then you can setuid it to cause it to be run in its owner's account instead of Apache. But there's no guarantee the system will honor that. Otherwise it would be great if you could change things so that the directory it needs to write to is also owned by Apache. Means your personal account couldn't change anything inside without sudo but the script could run without fiddling with permissions. Worst case, set 0777 on the directory so that anyone can read the directory, write new files in it, or traverse the directory. So I own the box its in my house as my little playground with one of my static ip's. I am not worried anyone else on the box with abilities. With that being said I have tried changing the directory ownership to www-data:www-data and 777 on the script, that does not work I only get this: Loading pages (1/6)[> ] 0%[======> ] 10%[==================> ] 30%[============================================================] 100%QPainter::begin(): Returned falseError: Unable to write to destination Exit with code 1, due to unknown error. OK so I was using absolutes everywhere except the file output location in my shell script. Now that I have that out of the way I can go hang my head in a corner Everything is working as expected!! Quote Link to comment https://forums.phpfreaks.com/topic/304838-execute-shell-script-in-php/#findComment-1550587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.