Results 1 to 7 of 7
what is the function in php that used to execute files in linux. i want to execute script file that contains iptables rules...
- 04-29-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
php function
what is the function in php that used to execute files in linux. i want to execute script file that contains iptables rules
- 04-29-2008 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,679
- 04-29-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
php function 2
how i can use exec function in php to execute iptables command
- 04-29-2008 #4Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,679
Wow...just wow...
Exec Function - PHP Manual
Copy/paste from the PHP function manual:
Code:<?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?>
- 05-15-2008 #5Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
use php to run iptables command
With iptables, things are a bit more complicated than the command whoami due to the fact that only root can execute iptables command. But we can get around this with sudoers. You need to add the web server user (for example, apache) to /etc/sudoers like this
apache ALL=NOPASSWD:/sbin/iptables
then in your php script you put your command something like
$cmd="sudo /sbin/iptables Blah Blah Blah";
exec($cmd);
if you don't see /etc/sudoers, you need to get it installed first.
- 05-20-2008 #6Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
iptables2
i add this line to sudoers
apache ALL=NOPASSWD:/sbin/iptables
then i write php script like this
<?php
$cmd="sudo /sbin/iptables -A INPUT -p tcp -s 172.16.58.10 -j REJECT";
exec($cmd);
?>
but i didn't get the result.
thanks for help.
- 05-22-2008 #7Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
shyma,
You need to find out the what the www user is first. If you are using apache, look under /etc/apache/uid.conf. Replace "apache" in "apache ALL=NOPASSWD:/sbin/iptables" with the User setting in uid.conf and try again. Also if you can post the error message returned by php if you need further help.


Reply With Quote
