Jump to content
xisto Community
Sign in to follow this  

Starting Or Stopping Apache And Mysql Server Via Batch File

Recommended Posts

Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT (2000, XP, 2003) via a batch file script.


As we know in Windows NT based system Apache and MySQL installed as Windows Services. So we can stop and start it using NET command.


For more information about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql" and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run > services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!.


1. Open your command prompt by clicking Start > Run > cmd > OK

2. Type edit then press ENTER to start the EDIT program.

3. Type code below


@ECHO OFFif "%1"=="start" goto start_serverif "%1"=="stop"  goto stop_serverif "%1"=="" goto begin:beginTITLE ::BATCH SCRIPT::ECHO ----------------------------------------------------------------------------------ECHO USAGE OF THIS SCRIPT:ECHO server.bat option1 [option2]ECHO WHERE option1 = start/stop (start or stopping server)ECHO	  option2 = yes/no (close the command prompt or not [optional])ECHO -----------------------------------------------------------------------------------goto end:start_serverTITLE ACTIVATING SERVER...ECHO =================================================ECHO	   BATCH SCRIPT FOR ACTIVATING SERVERECHO	By Rio Astamal (masterio.trap17.com)ECHO =================================================ECHO _ECHO Activating MySQL Service . . .@NET START mysqlECHO _ECHO Activating Apache HTTP Server Service. . .@NET START apache2ECHO _ECHO SERVER HAS BEEN STARTED!DATE /TTIME /Tgoto end:stop_serverTITLE STOPPING SERVER...ECHO ==================================================ECHO	   BATCH SCRIPT FOR STOPPING SERVERECHO	By Rio Astamal (masterio.trap17.comECHO ==================================================ECHO _ECHO Stopping Apache HTTP Server Service...@NET STOP apache2ECHO _ECHO Stopping MySQL Service. . .@NET STOPECHO SERVER HAS BEEN SHUTTING DOWN!DATE /TTIME /Tgoto end:endif "%2"=="yes" (  exit)

To save the file:

1. Press ALT-F > Save

2. Go to your Windows Directory, so we can start it from anywhere in command prompt

3. OK



C:\>server.bat (to show the usage of the script)

C:\>server.bat stop yes (close the command prompt after finished the task)

C:\>server.bat start



If you create a batch file, Anything inside it is assumed as DOS command by command prompt. In that script, first, we make the ECHO command invisible by using @ECHO OFF command. Then we check the argument given by user. %1 is argument 1, %2 is argument 2 and so on. We use first argument(%1) to check what user want. Is he want to stop/start the server. We use argument2 (%2) to check wheter we close the command prompt or not after it.


TITLE is used for changing the title of command prompt title bar. For starting service We can use NET START [service_name]. In our script we use @NET START to prevent DOS for echoing the command. For stopping service we can use NET STOP [service_name].



With a batch file we can do alot of thing not just stop/starting service. But we can use it for renaming many files at once, deleting temporer directory and many more. For more tutorial you can googling!!.


ENJOY...! :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.