When I'm trying to execute a PHP script using shell_exec(), it's not working.
In the error_log file it shows:
PHP Warning: shell_exec() [function.shell-exec]: Unable to execute
'php /home/snabbsam/public_html/.....
System
Centos
shell_exec works with clamscan
shell_exec() works on clamscan() function of clamav.
But it's not executing PHP script
Things I've checked:
PHP safe_mode is off
shell_exec() is not present in disable_functions in php.ini
Tried giving executable permission to the file & the parent folders as suggested in https://stackoverflow.com/a/8668666/402089
Try adding a full path to where the executable for php is in your shell_exec call, just in case it's in a directory that's not accessible by default for the webserver user.
Related
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.
I've been trying to run the php script:
shell_exec("bash /etc/example.sh")
from the browser but it does not work. This bash file creates a new one on the /etc directory.
I've also tried the functions exec() && system() but they don't work either. The weird thing happens when I run other Linux commands on these php function like:
shell_exec(rm -r /etc/fake);
they work fine, I have also tested my bash file on the linux command line and it works great.
I am sure this is not a permission issue, since I previously set the 777 permission on the file i am trying to execute.
shell_exec("bash /etc/example.sh")
I am using php7.0.33 and Debian 9, so I suppose this may be an issue with this PHP version 7.0.
Thank you for the help.
Hello i have a PHP script, and its added to cron, it is possible to execute from this script shell command (with exec() or something) without enabling it on php.ini? I don't want to enable exec on my site
It's called PHP CLI, check here
Usually when you install php, there's option to install php_cli too.
So long you can run php on shell prompt, then it can work.
Open bash (or other shell), try this:
php -v
If the version printed, then it's working.
Then you can
php -f phpfile
or put
#!/usr/bin/php
At the beginning of your php file as a line, and chmod +x file.php, and then
./file.php
#or
/path/to/file.php
to run it.
(Note /usr/bin/php is the usual place of php executable, it might change, eg in unix is ually /bin/php. Use whereis php to check its place.)
I have installed xampp in my windows OS.completed the configuration settings .But i can't run a simple php script from CMD . Is there anything should i do bfore running the script .
Be sure, that php is added to your path variable, so you can run php -v in your terminal. You should get the current version of your installed php.
If php was added to your path variable, you can run a php script like php file.php
See http://php.net/manual/en/faq.installation.php#faq.installation.addtopath
First, you have to go till that file path in command prompt then use command to execute php script,
php file_name.php
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.