I want to execute the bash script present on the system from a php script. I have two scripts present on the system. One of them is a php script called client.php present at /var/www/html and the other is a bash script called testscript present at /home/testuser.
My client.php script looks like
<?php
$message=shell_exec("/home/testuser/testscript 2>&1");
print_r($message);
?>
My testscript looks like
#!/bin/bash
echo "Testscript run succesful"
When i do the following on terminal
php client.php
I get the following output on terminal
Testscript run successful
But when i open the page at
http://serverdomain/client.php
I get the following output
sh: /home/testuser/testscript: Permission denied
I get this error even after i did chmod +x testscript.
How do i get it to work from the browser? Please help.
read
permission?Execute
permission is useless withoutread
permission. – Samveen Jun 17 '13 at 16:04sudo
permissions to your webserver on that script. Or wrap the script in a suid binary. But either way, be VERY VERY VERY VERY VERY careful with this. Invoke the script wrong, pass around some data wrong, and you've provided remote users with a root shell on your server, and boom goes your server. – Marc B Jun 17 '13 at 19:45