I am trying to run a .sh file from php. I tried doing it with shell_exec(). but its not working I refered many questions related to this in stack overflow but could not solve
my php code is(web.php)
<?php
echo shell_exec('/var/www/project/xxe.sh');
echo "done";
?>
only done is printed. but it is working from terminal(php /var/www/project/web.php)
In xxe.sh I am calling a python file
python vin.py
I have also changed the file permission to 777 for both .sh n .py files please help
If it works well in shell, I think apache is chrooted. So php can't find /var/...
Or user of httpd user does not have permission to enter /var/...
If you are good at PHP. Open dir /var/... And readdir() and check dir exists and check file exists.
This question might help you. scanning /home/ with opendir()
I have been stuck in this problem for several hours.
I have thought about a solution. 1. move your script to a python file "script.py" and place this file to your server root. 2. shell_exec("python script.py");
Any way, it works for me.
While trying to run a script triggered by github post-receive webhook.
Here is where my project directory is located(cloned git repo):
I create a script inside the above directory called webhook.php:
Execute the following command inside /var/www/html
Test it by going to http://www.myserver.com/my-repo/webhook.php
Add the path to your script to github webhooks.
If you say it works on the terminal and not on apache then apache's
php.ini
file may be disabling the use ofshell_exec()
.See http://www.php.net/manual/en/ini.core.php#ini.disable-functions
Your apache's
php.ini
file may look something likeRemove
shell_exec
from this list and restart the web server, although this is a security risk and I don't recommend it.I tried everything here and nothing worked. What finally solved it for me was using the following before the shell_exec:
I had the same issue because PHP backslashes.
PHP escapes the backslashes, so the command that reaches the shell
so I gave command like this
You have to double-escape the backslashes: once for PHP and once for the shell.