php-fpm
, nginx
exec when in use .phpfiles()
shell_exec()
system()
works fine from the command line.
Example when works well:
#php myphp.php
myphp.php
contains:
<?php
exec('ping -c 3 google.com', $output);
print_r($output);
?>
But if I put on my browser http://localhost/myphp.php
, it does not work anymore.
Any ideas? I edit
I made a file with the following contents:
#cat info.php
<?php
if(function_exists('exec')) {
echo "exec is enabled";
}
phpinfo();
?>
In my browser, print
exec is enabled, y php info..
I made a file with the following contents:
#cat info.php
<?php
// Check for safe mode
if( ini_get('safe_mode') ){
// Do it the safe mode way
echo "Do it the safe mode way";
}else{
// Do it the regular way
echo "Do it the regular way";
}
?>
In my browser, print
Do it the regular way
Did not I like to know if I'm in a jail?
In my php ini
#cat /etc/php-5.5.ini
safe_mode not shown, or ON or OFF. simply does not exist
I think exec and those kind of functions are disabled in your php.ini . You can check it by
if(function_exists('exec')) {
echo "exec is enabled";
} else {
echo "exec is disabled";
}
Open your php.ini and navigate to section disable_functions
If exec is listed under there , remove it.
Then restart php-fpm
.
Also If Safe Mode is enabled this function will not be available. You need to disable it.
Edit
use full path for ping. You can find it by issuing this command in shell which ping
Edit
<?php
exec('/sbin/ping -c3 google.com', $output);
print_r($output);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With