Jump to content

need a little help with some php commands


stelthius

Recommended Posts

Hi Guys,

 

I have built a test script to restart a few services via php but i have hit a wall, the script doesnt seem to work, safe mode is off in php and im aware it isnt recommended using PHP to perform the actions i want to it perform if anyone has any better ( Safer ) solutions please let me know :D

 

Below is my code, can anyone tell me why it wont work please ?

 

<?php		
	if (isset($_GET['cmd'])){
		if ($_GET['cmd'] == 'restart') {
		passthru('shutdown -r -t 01');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'shutdown') {
		passthru('shutdown -s -t 01');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartapache') {
		passthru('net stop apache');
		passthru('net start apache');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartmysql') {
		passthru('net stop MySQL');
		passthru('net start MySQL');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartftp') {
		passthru('#');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
	}		

	ini_set('display_errors','0'); 

	function lookup_ports($hport,$hdomain) {
         	$fp = fsockopen($hdomain, $hport,$errno,$errstr, 4);
        	if (!$fp){
             	$data = "<font color=red size=4>*</font>";
         	} else {
             	$data = "<font color=green size=4>*</font>";
             	fclose($fp);
         	}
         return $data;
	}

              ?>
System Control<br>
<br>
Restart Server - <a href="?page=servercontrol&cmd=restart">Restart Server</a><br>
<br>
Shutdown Server - <a href="?page=servercontrol&cmd=shutdown">Shutdown Server</a><br />
<br />
Restart Apache - <a href="?page=servercontrol&cmd=apacherestart">Restart Apache</a><br />
<br />
Restart MySQL - <a href="?page=servercontrol&cmd=restartmysql">Restart MySQL</a><br />
<br />
Restart FTP - <a href="?page=servercontrol&cmd=restartftp">Restart FTP</a><br />

 

Any help or ideas is appretiated,

 

 

Thanks Rick

Link to comment
Share on other sites

Firstly, you should be using elseif. Secondly, you may try using shell_exec().

 

Also, I don't think I've ever seen apache or mysql restarted in that manner. Try:

 

apache:

/etc/init.d/httpd restart

apache2ctl restart

apachectl restart

 

mysql:

/etc/init.d/mysqld restart

Link to comment
Share on other sites

I'm not sure of your permissions, but try to do sudo /etc/init.d/httpd restart. if not you can always do stop and then start.'

 

Try each of those apache restarts, one of them is bound to work.

 

Actually I lied: /etc/init.d/apache restart :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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