Php failed to execute exec, could you tell me how to solve it?

The

code has only one line, as follows, IP is written by me blindly, and there is no

in order to see it take effect.
var_dump(exec(sprintf("/usr/sbin/iptables -I INPUT -s %s -j DROP", "43.1.1.1")));

1 browser access, no effect

write, feedback in the browser is empty, originally empty, iptables itself does not return any data, and then check did not take effect

iptables -L

2 manual input is no problem

it"s OK to enter shell manually

iptables -I INPUT -s 43.1.1.1 -j DROP

3 php does not disable the function

execution in php-cli is OK, or using php to execute files is also OK, but only operations are not performed in the browser, is it because of permission issues? Could you tell me how to solve it?

Sep.01,2021

who is the user running the php-fpm process?


Yes, permission problem. I tested it with other orders.

[root@localhost public]-sharp cat test.php
<?php
echo exec("/command"),PHP_EOL;

[root@localhost public]-sharp php test.php
helloworld
[root@localhost public]-sharp ll /command
-rwx------+ 1 root root 16 Oct 18 17:00 /command
[root@localhost public]-sharp curl http://localhost/test.php

there is no output at this time. Then give setfacl-m u:apache:rwx / command

[root@localhost public]-sharp curl http://localhost/test.php
helloworld

the program is executed successfully at this time.

I also tried to give permission to execute iptables in this way, but failed. Let's investigate the reason when we have time.

  • iptables is generally executed by root. I don't think your php-fpm/apache is root running the worker process, is it? So permissions must be a problem
  • and check whether the environment variable of php executing shell in browser mode is correct
these two should be solved by checking.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bed9-2c2c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bed9-2c2c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?