Find the answer to your Linux question:
Results 1 to 8 of 8
i know that exec function in php used to execute commands , i have a problem:i try to use exec function to execute iptables command but i failed.please help me. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38

    exec function


    i know that exec function in php used to execute commands , i have a problem:i try to use exec function to execute iptables command but i failed.please help me.
    this is the code
    <?php
    $output = shell_exec('iptables -L ');
    echo "<pre>$output</pre>";
    ?>

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769

    Smile

    Quote Originally Posted by shyma View Post
    <?php
    $output = shell_exec('iptables -L ');
    echo "<pre>$output</pre>";
    ?>
    your code is working from command line.
    If you are trying execute this code using browser then check with absolute path name

    replace this line
    $output = shell_exec('iptables -L ');
    with this
    $output = shell_exec('/sbin/iptables -L ');
    Let me know the results
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38

    exec function 2

    i try this code but i failed also
    <?php
    $output = shell_exec('/sbin/iptables -L');
    echo "<pre>$output</pre>";
    ?>
    thanks for help.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769

    Smile

    Hi shyma,
    You can reply this thread - Don't need to create new thread like you did here.
    http://www.linuxforums.org/forum/lin...ction-2-a.html
    [quote]
    i try this code but i failed also
    <?php
    $output = shell_exec('/sbin/iptables -L');
    echo "<pre>$output</pre>";
    ?>
    thanks for help.
    [\quote]

    Are you trying to run php from web browser?
    anyway first check that code runs from command line or not.
    if it's not running from command line post it's output as well as post the output of command
    whereis iptables
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  6. #5
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38
    yes i try to run php from web browser and the command run in command line, but i didn't know what is the problem.
    thanks.

  7. #6
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769

    Exclamation

    You are logged in as root -- right? and
    you are getting desired output from command line-right?
    And you are not getting result from browser - right?

    Then try and replace the command iptables with simple command like ls

    /bin/ls

    If 'ls' command gives you output then i think problem lies with permissions.

    Try with ls command and let me know the results
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  8. #7
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38
    simple commands can be executed. and iptables commands can not.
    how i can get permissions to execute iptables commands through php interface?
    please help me.

  9. #8
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769

    Exclamation

    Quote Originally Posted by shyma View Post
    simple commands can be executed. and iptables commands can not.
    how i can get permissions to execute iptables commands through php interface?
    please help me.
    So root user commands are not executed.
    If i'm not wrong - i think you need to give permission in /etc/sudoers -you can give sudo privileges to apache's user, and then use it on php [also check out httpd.conf if ur server is apache & php.ini ]

    Try google from here on about "executing root commands under php using browser"

    All the best
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

Posting Permissions

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