简体   繁体   中英

shell script running in php gives error .sh: Permission denied

I am running a php file through browser which run the shell script but i recive the error ".sh: Permission denied" My Php File is

<?php
$output = shell_exec('/var/www/html/test.sh 2>&1');
echo "$output";

My Shell Script is

#! /bin/bash
scp -r -i /home/ec2-user/key.pem /var/www/html/test ec2-user@172.16.11.12:/var/www/html/
echo "hello world"

Any help will be appreciated

We found that the script, test.sh, would fail with "Permission denied" when executed by php's shell_exec when the script was located in either /var/www/html/ and /root (which was the id commands being executed by shell_exec). It executed just fine when when we moved the script to /usr/local/bin. The script also worked when executed manually on a console in all 3 directories. This also excludes the mount noexec theory. I don't see any restrictions documented in php documentation for shell_exec, or php.ini. Neither AppArmor or SELinux are enabled on the host. There were no errors in /var/log that mentioned the script. int_get('open_basedir') and strace of the the php process when running the.php file (you can do that on the command line) would be the only other thing that has come up. Any other ideas? I am stumped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM