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.
Related
I want to execute bash script with php.
When i launch php script in browser i got an error " permission denied"
when i run php whoami , i get www-data. I granted all permisions for write and read.
When i run bash script as www-data it works. But via php im still getting the same error.Should i check php.ini settings or somethnig?
If i write unknown bash command in php script, using shell_exec(). I got an error sh: command not found.I think it should be "bash: comand not found".
Can u please help me out.
PHP
<?php
$message=shell_exec ("bash bashscript 2>&1");
print_r($message);
?>
bash
#!bin/bash
cp /myfiles/file aa
I have a php script that works perfectly when ran form command line; including the exec().
The exec I do are calling some .sh scripts.
These .sh script are of type bash
So I call them:
exec('/bin/bash /home/user/soft/bin/mybash.sh > /dev/null');
It works great when I run my php from command line I see all the instructions; works also when use with an alias. but when I it via a daemon:
sudo -u myuser php -f /home/user/bin/serverwait.php eveything that should be done in the .sh are not being done. but the rest of the file is doing what it is suppose to do (it checks for open ports and write to a log file)
I tried looking at my php.ini for cli and all seems right.
I'm trying to compile a C program with shell_exec() (I tried using exec() also). I'm using nginx on CentOS 6 as a server. Here is the command I try to execute:
/usr/bin/gcc /MyStuff/program.c -o program
I set the permissions of the files and the parent folders to 755 and also tried:
/usr/sbin/setenforce Permissive
But none of them seems to give result. The php is under user apache. The output of the command execution when
/usr/sbin/setenforce Permissive
is:
collect2: cannot find 'ld'
When
/usr/sbin/setenforce Enforcing
is
cc1: error: /MyStuff/program.c: Permission denied
Any ideas what's the problem?
I have installed webp package in my server and i want to use "dwebp" command in my PHP application.
My command is simple, it is like
dwebp "/full/path/test.webp" -o "/full/path/test.png"
If i run it from SSH terminal, it is 100% succesful.
But that command can't be run from PHP.
I have tried to use system(), passthru(), exec(). All failed which means the PNG file is not created.
However these commands succesfully called from PHP :
touch. If i use this, the created file is under "apache" owner.
ls -la
I have tried to change the directory permission from 777 / 775 / 755.
Using passthru, the result from calling from PHP is empty string.
In php.ini, disable_functions is empty
No error message, error_reporting is on.
I have a bash script:
run.sh
#!/bin/sh
cd /var/www/project/bin/
CMD="./executable <full_path_to_file>;
$CMD
When I run this program from the terminal. (i.e. ./run.sh, it works fine)
However when I call it from PHP:
system("full_path_to_sh_file", $out);
It calls the script successfully, and even runs the executable, but now the executable throws an error saying that the supplied file can't be found.
Any ideas?
How do you run PHP script, from webserver or command line?
If from webserver, what user is it run (httpd or apache?)
Make sure the environment as same as when you are running from terminal (for example: same user)
Try this if running as different user:
sudo -u apache /fullpath/run.sh