Find the answer to your Linux question:
Results 1 to 5 of 5
hi how i can run this command (service iptables restart) from php code? i try to use exec function, this the code <?php $output=shell_exec('service iptables restart'); echo "<pre>$output</pre>"; ?> but ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38

    php problem

    hi
    how i can run this command (service iptables restart) from php code?
    i try to use exec function, this the code
    <?php
    $output=shell_exec('service iptables restart');
    echo "<pre>$output</pre>";
    ?>
    but it doesn't exec this command but another simple commands can run.
    please help me.

  2. #2
    Just Joined! vigour's Avatar
    Join Date
    Oct 2007
    Posts
    68
    You need root to execute that command...

    I suggest you configure it in sudo and execute it trough sudo

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38
    how i can configure it from sudo?

  4. #4
    Just Joined! vigour's Avatar
    Join Date
    Oct 2007
    Posts
    68
    Execute as root:
    Code:
    visudo
    enter the following lines:

    Code:
    Cmnd_Alias RES=/etc/init.d/iptables restart
    apache ALL=NOPASSWD: RES
    Save it... You must be familiar with Vim text editor.. visudo uses the same methods of editing...

    Then you will be able to use:

    Code:
    $output=shell_exec('/usr/bin/sudo /etc/init.d/iptables restart');

  5. #5
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38
    i did what you say but i faild.
    can you give me another solution?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...