Jump to content

PhP exec problem


byte.billionaire

Recommended Posts

Hi All,

 

I want to execute an external program and I have the following program.

 

<?php

        $cmd = "sudo -u root -S ifconfig eth0 0.0.0.0 down";

        exec($cmd);

?>

 

When running in terminal mode... no problem at all. 

When running in Apache/PhP mode...... PROBLEM....

 

I have also this line in the the /etc/sudoers

apache ALL = NOPASSWD: ALL

 

Please help!!!

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/38732-php-exec-problem/
Share on other sites

It could be to do with paths.  Try giving the full path for sudo and ifconfig

 

Apart from that, try printing out the return value from exec(), and/or adding the optional second argument to exec() (which records the entire output).  Maybe there's some hints in there.

Link to comment
https://forums.phpfreaks.com/topic/38732-php-exec-problem/#findComment-186103
Share on other sites

I have changed the code to this....

 

<?php

        $data = array();

        $cmd = "sudo -u root -S /sbin/ifconfig eth0 0.0.0.0 down";

        exec($cmd, $data, $ret);

 

        echo "<pre>";

        if ($ret == 0)                // check status code. if successful

            foreach ($data as $line)

                echo "$line \n";

        else

            echo "Cannot execute $prgfile for some reason";    // if unsuccessful display error

        echo "</pre>";

?>

 

However, still could not execute it probably....Any other recommendations???

 

 

Link to comment
https://forums.phpfreaks.com/topic/38732-php-exec-problem/#findComment-186113
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.