Jump to content

PHP problem with shell_exec() command


shenmu0

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.