shenmu0 Posted April 9, 2007 Share Posted April 9, 2007 Hello all, I've came up with an issue when trying to work on Linux's shell using PHP it seems to work when I issue the following commands, shell_exec("iptables -h");, shell_exec("ls"); and shell_exec("ifconfig"); however when I'm trying to do something like this, shell_exec("iptables -L") or shell_exec("iptables restart"); it doesnt seem to work I am a PHP and Linux novice.... Could somebody kindly help me, I am desparate to get this working Thankyou Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/ Share on other sites More sharing options...
SiC_Goat Posted April 9, 2007 Share Posted April 9, 2007 Can you post an example of your code? shell_exec("ls -l") and other correctly typed commands with spaced arguments should work per shell_exec(). Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225478 Share on other sites More sharing options...
shenmu0 Posted April 10, 2007 Author Share Posted April 10, 2007 Hello, thanks for replying I've tried several commands, such as "ls -l","ifconfig" and "iptables -h", these all works and return the result on the browser. However when I'm trying to do "iptables -L" which shows the currently configuration in my firewall, nothing happens.. this is my code: $output = shell_exec ("iptables -L"); echo $output; I also tried the "service iptables restart" command using shell_exec, however it returned: "Unloading iptables module [FAILED], Applying iptables firewall [FAILED]. This means that there are results for certain commands, is it a problem with permissions? I heard some people use "sudo" to authorize the access, but I don't know how to use it. Please give me some advice Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225607 Share on other sites More sharing options...
btherl Posted April 10, 2007 Share Posted April 10, 2007 iptables is probably not in your path. Try /sbin/iptables or /usr/sbin/iptables. It's a good habit to use exact paths too, for security. I would expect it to require root access.. you wouldn't want normal users examining your firewall rules. I can't advise you on how to set that up though. Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225645 Share on other sites More sharing options...
shenmu0 Posted April 10, 2007 Author Share Posted April 10, 2007 I've also tried, shell_exec("/sbin/iptables -L"); but nothing seems to happen however if I do, shell_exec("/sbin/iptables -h"); the output displays successfully Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225673 Share on other sites More sharing options...
btherl Posted April 10, 2007 Share Posted April 10, 2007 Sorry, I didn't read your post properly. It sounds like permissions then.. I'm sure sudo can do it, but I've never configured it before. Are you using a packaged hosting service? Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225695 Share on other sites More sharing options...
shenmu0 Posted April 10, 2007 Author Share Posted April 10, 2007 Im actually making a web based intereface to configure IPtables. I've generate my commands in javascript, and then pass it to PHP to generate the actual rule in shell with the shell_exec command. Link to comment https://forums.phpfreaks.com/topic/46339-php-problem-with-shell_exec-command/#findComment-225717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.