I have PHP code (setup.php) that execute bash-script, this is my code :
$hasil = shell_exec("./setup-srv.sh testajah mydomain.com");
echo "<pre>".$hasil."</pre>";
successfull when executed from commadline (setup-srv.sh), but failed when executed from browser (setup.php)
these 2 files at /var/www/html/
setup-srv.sh has several jobs :
- register subdomain to DNS server
- create and populate data to mysql database
- copy master folder and it's contents to new folder
- execute certbot to new subdomain
I chmod 2 files with 777, but still failed.
I need help, thank you at advance.
1 Answer 1
I'm assuming you're on a newer PHP than 5.3, or you have safe mode off.
This is likely to be an issue with the differences between your environment and the web server's environment.
Things to try:
Unlikely to be the problem, but .. $hasil = shell_exec("/var/www/html/setup-srv.sh testajah mydomain.com");
SU to the webserver user and try to run the script, see what happens.
Make sure SELinux isn't interfering with the webserver's ability to execute external programs.