stelthius Posted July 21, 2008 Share Posted July 21, 2008 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 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 https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/ Share on other sites More sharing options...
Jabop Posted July 21, 2008 Share Posted July 21, 2008 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 https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/#findComment-595791 Share on other sites More sharing options...
stelthius Posted July 21, 2008 Author Share Posted July 21, 2008 Hi Jasop, Thanks for your reply, the apache way you said to try didnt work and the mysql one well it kind of worked here is the mysql one output Stopping MySQL: [FAILED] Starting MySQL: [ OK ] Link to comment https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/#findComment-595793 Share on other sites More sharing options...
Jabop Posted July 21, 2008 Share Posted July 21, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/#findComment-595796 Share on other sites More sharing options...
stelthius Posted July 21, 2008 Author Share Posted July 21, 2008 but still somethign isnt right for Mysql to say it failed on stopping mysql even tho it is running :S strange! Link to comment https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/#findComment-595799 Share on other sites More sharing options...
stelthius Posted July 21, 2008 Author Share Posted July 21, 2008 well i found a way to get the actual server to reboot but im still stuck with how to get the services to restart efficiantly Link to comment https://forums.phpfreaks.com/topic/115876-need-a-little-help-with-some-php-commands/#findComment-595861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.