Php-fpm does not work exec, system, shell_exec, only CLI

php-fpm , nginx exec when using .phpfiles() shell_exec() system() works fine from the command line.

An example when it 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 no longer works.

Any ideas? I am editing

I made a file with the following contents:

 #cat info.php <?php if(function_exists('exec')) { echo "exec is enabled"; } phpinfo(); ?> 

In my browser, type

exec 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, type

Do it the usual way

Didn't I want to know if I ended up in jail?

In my php ini

 #cat /etc/php-5.5.ini 

safe_mode is not displayed, either ON or OFF. just doesn't exist

+5
source share
3 answers

I think exec and these functions are disabled in your php.ini. You can check it out on

 if(function_exists('exec')) { echo "exec is enabled"; } else { echo "exec is disabled"; } 

Open php.ini and go to disable_functions

If exec is listed there, delete it.

Then restart php-fpm .

Also, if safe mode is enabled, this feature will not be available. You need to disable it.

Edit

use the full path for ping. You can find it by issuing this command in the command shell which ping

Edit

 <?php exec('/sbin/ping -c3 google.com', $output); print_r($output); ?> 
0
source

php-fpm is blocked by default on OpenBSD. This is probably the reason why you see that it works on Kli, and not on the Internet.

You have two solutions. Disable chroot (comment out the line chroot = /var/www on /etc/php-fpm.conf ) or fix problems you may encounter.

The static compiled version of ping is under /bin/ping (from inside chroot). You will need to copy /etc/hosts and /etc/resolv.conf inside chroot to resolve host names (since you are trying to ping google). All other system commands that you plan to invoke must also be copied inside chroot (along with their shared libraries or compiled statically).

Use ldd(1) to find out which libraries you will need. Depending on what you are trying to achieve, this can be a tedious job.

Exec, system and shell_exec are probably disabled, as other users have noted.

0
source
 <?php //echo "-...  1 "; //echo "Wait... 1 min"; echo exec('/bin/bash --login -c "cd /var/www/194.7.2.2/public && /usr/local/rvm/rubies/ruby-2.5.3/bin/ruby work1.rb "'.$_GET['some_value']); 

It worked 4me!

0
source

Source: https://habr.com/ru/post/1216155/


All Articles