stelthius Posted July 22, 2008 Share Posted July 22, 2008 Hi guys, Just curious as to if anyone knows how to restart apache & mysql via a web script such as php or any other type of script, Thanks Rick, Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/ Share on other sites More sharing options...
LooieENG Posted July 22, 2008 Share Posted July 22, 2008 <?php exec('/etc/init.d/apache2 restart'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596069 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 Thanks how would i make it work so it only restarts once a button is pressed ? im new'ish to php so i need to ask thanks again Rick, Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596071 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 also is there anyway to actually know if the service has restarted or failed to restart ? Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596074 Share on other sites More sharing options...
LooieENG Posted July 22, 2008 Share Posted July 22, 2008 restart.html <form name="restart" method="post" action="restart.php"> <input type="submit" name="restartApache" value="Restart"> </form> restart.php <?php if ( $_POST['restartApache'] ) { if ( exec('/etc/init.d/apache2 restart') ) { echo 'Apache service restarted!'; } else { echo 'Service couldn\'t be restarted'; } } else { ?> <form name="restart" method="post" action="restart.php"> <input type="submit" name="restartApache" value="Restart"> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596078 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 WOW thanks, that is greatly appretiated Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596082 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 Hmmm works nice but the only problem is the page will have like Restart Apache Restart MySQL and then once it has restarted just say *Service Successfully restarted but remai on the same page if you get me i do have a peice of code already but it doesnt seem to work Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596087 Share on other sites More sharing options...
DarkWater Posted July 22, 2008 Share Posted July 22, 2008 Well, you're restarting the server, so you won't be able to serve any pages during that time. Why do you want to do it like this anyway? Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596094 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 Because i need to be able to restart apache and mysql via php, if it cant be done then i guess im outta luck lol it doesnt have to be in PHP any language really just aslong as it works as i said im new im no guru so im learning as i go along Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596098 Share on other sites More sharing options...
unkwntech Posted July 22, 2008 Share Posted July 22, 2008 I would use JavaScript to do the checking because it is client side and will operate even if the server is down. Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596102 Share on other sites More sharing options...
stelthius Posted July 22, 2008 Author Share Posted July 22, 2008 i actually got it to work like this, <?php if ($_GET['cmd'] == 'restartapache') if ( exec('/etc/init.d/httpd restart') ) { echo '<font color=red>'.$lang_serrestarted.'</font>'; } else { echo '<font color=green>Service couldn\'t be restarted</font>'; } if ($_GET['cmd'] == 'restartmysql') if ( exec('/etc/init.d/mysqld restart') ) { echo '<font color=red>'.$lang_serrestarted.'</font>'; } else { echo '<font color=green>Service couldn\'t be restarted</font>'; } if ($_GET['cmd'] == 'restartftp') if ( exec('/etc/init.d/ftpd restart') ) { echo '<font color=red>'.$lang_serrestarted.'</font>'; } else { echo '<font color=green>Service couldn\'t be restarted</font>'; } } ?> <br> <br> Restart Apache - <a href="?page=servercontrol&cmd=restartapache">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 tips on cleaning it up or making it more efficiant are welcome but it works and thats what i was aiming for Rick. Quote Link to comment https://forums.phpfreaks.com/topic/115934-restart-apache-mysql/#findComment-596109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.