V
V
Vladislav2015-01-16 21:14:30
PHP
Vladislav, 2015-01-16 21:14:30

Why is the iptables command not being executed via PHP's exec() function?

I'm trying to execute the iptables command through PHP, the code is this:
exec("sudo iptables -I INPUT -s ".$enemy_ip." -j DROP");
exec("sudo iptables save");
The result should be adding some IP address to the iptables table, but it doesn't. Other commands run smoothly, for example top works fine. Iptables works correctly from the console, everything is added perfectly. By the way, the same code works correctly on another server with the same settings as the one on which it cannot be executed. No errors are displayed, nothing is written about rights. What can you try? Where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2015-01-16
@jennik

Umm... Is there a user from under which php works in sudoer's?
Check: exec("sudo top");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question