LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   PHP script for rebooting the Linux server (https://www.linuxquestions.org/questions/linux-server-73/php-script-for-rebooting-the-linux-server-943800/)

em31amit 05-19-2012 12:23 PM

Quote:

Originally Posted by jeethapj (Post 4682513)
Ok sir.I have tried as "apache ALL = NOPASSWD: /etc/init.d/network restart",
"httpd ALL = NOPASSWD: /etc/init.d/network restart"..

When I checked "whoami" it is giving the result as "asterisk"..Then I tried also
"asterisk ALL = NOPASSWD: /etc/init.d/network restart"..

Then I run the script
<? php

System('sudo /etc/init.d/network restart',$result);
echo "$result";
?>

Then nothing is happening and it is displaying the result 1.
Also when I tried
<? php

System('service network restart',$result);
echo "$result";
?>

It is returning the result as 0 and also displaying


Shutting down interface eth0: [FAILED] Shutting down loopback interface: [FAILED] Bringing up loopback interface: [FAILED] Bringing up interface eth0: [FAILED]


here are the step which you need to follow;

1) Comment a option into of "Default requiretty" using visudo

Code:

cat /etc/sudoers  | egrep "requiretty|apache"
#Defaults    requiretty
apache ALL=NOPASSWD: /etc/init.d/network restart

2) your php code

Code:


<?php

  system('sudo /etc/init.d/network restart',$result);
  echo "$result";
?>

it must work.

jeethapj 08-03-2012 02:51 AM

Please anyone help me to run the command "service network restart" through GUI..When I directly run the command in command prompt it is working.But through GUI it is not..The command is executing but it is showing

"Shutting down interface eth0: [FAILED] Shutting down loopback interface: [FAILED] Bringing up loopback interface: [FAILED] Bringing up interface eth0: [FAILED]"

I am the root user.


All times are GMT -5. The time now is 06:57 PM.