Forum Moderators: coopster

Message Too Old, No Replies

Starting and Stopping DHCPD daemon from PHP

         

nickodemus

11:27 am on Nov 11, 2007 (gmt 0)

10+ Year Member



I want to be able to start and stop, or even restart the DHCPD daemon from a PHP script. I am starting to write a web application that enables the editing of the DHCPD config file, and after editing I want to be able to restart the daemon so it takes the updates automatically.

I have tried the exec command, but this doesn't seem to work...

e.g.

exec("/etc/init.d/dhcpd stop",$report)

coopster

11:53 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, nickodemus.

Have you checked your logs? It may be likely that the user PHP is running as does not have permission to start/stop the daemon ...
[php.net...]

nickodemus

3:17 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Thankyou for your reply coopster.

I thought it might be a security issue so have been experimenting to try and discover what is what.

I tried running whoami command via the system command, and it told me it was using 'wwwrun' as the user. So thought, ok, if I configure 'sudo' so that no password is required, and wwwrun has the same rights as root then it should work.

So I tried...

system("sudo service dhcpd stop");

And set the following entry in the sudoers config file...

wwwrun ALL = (root) ALL

This still hasn't worked. I've looked on the link you have sent, and it mentions that apache uses the nobody user, so I will attempt the same thing with this user and see what happens.

If any one can give me any other pointers it would be most appreciated.

nickodemus

3:30 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Correction..

The sudoers file is set like this:

wwwrun ALL = (root) NOPASSWD: ALL

I set nopasswd so it doesn't attempt to ask for one. However, this still doesn't work.

nickodemus

3:41 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Success!

I have managed to get it to work, it is the nobody user that needs to be added to the sudoers file..

e.g.

nobodyALL = (root) NOPASSWD: ALL

This is probably not a secure way of configuring it, but for test purposes at least I know that security is the cause of my problems!

If anyone has a better way of doing this however please let me know.

nickodemus

3:48 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



I have found that you do need both wwwrun and nobody in the sudoers file for it to work.