Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Starting Or Stopping Apache And Mysql Server Via Batch File
masterio
post Sep 22 2006, 02:14 PM
Post #1


Newbie [Level 3]
***

Group: Members
Posts: 49
Joined: 25-August 06
Member No.: 28,897



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

CODE
@ECHO OFF

if "%1"=="start" goto start_server
if "%1"=="stop"  goto stop_server
if "%1"=="" goto begin

:begin
TITLE ::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_server
TITLE ACTIVATING SERVER...
ECHO =================================================
ECHO       BATCH SCRIPT FOR ACTIVATING SERVER
ECHO    By Rio Astamal (masterio.trap17.com)
ECHO =================================================
ECHO _
ECHO Activating MySQL Service . . .
@NET START mysql
ECHO _
ECHO Activating Apache HTTP Server Service. . .
@NET START apache2
ECHO _
ECHO SERVER HAS BEEN STARTED!
DATE /T
TIME /T
goto end

:stop_server
TITLE STOPPING SERVER...
ECHO ==================================================
ECHO       BATCH SCRIPT FOR STOPPING SERVER
ECHO    By Rio Astamal (masterio.trap17.com
ECHO ==================================================
ECHO _
ECHO Stopping Apache HTTP Server Service...
@NET STOP apache2
ECHO _
ECHO Stopping MySQL Service. . .
@NET STOP
ECHO SERVER HAS BEEN SHUTTING DOWN!
DATE /T
TIME /T
goto end

:end
if "%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

Usage:
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

EXPLAINATION:
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].

SUMMARY
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...! biggrin.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Complete Login System(57)
  2. Complete Login And Registration System(9)
  3. Server Status(12)
  4. How To: Change Your Website's Index File(24)
  5. Transfer File Of Any Size Using Winsock Control(5)
  6. Starting Your Own Clan(21)
  7. How To: Make A Simple Php Site(21)
  8. Checking For Open Ports From Php(3)
  9. Quiz With Php, But Without Mysql(3)
  10. Making A Dynamic Page On Blogspot(5)
  11. How To Fix Codecs And Movie File Problems(0)
  12. Check Referrer To Prevent Linking Yours From Other Sites(8)
  13. *nix File Permissions - An Overview(6)
  14. Cpanel Mysql Database Management(6)
  15. Flat-file Cms(4)
  1. How To Make A Simple File Based Shoutbox Using Php And Html(8)
  2. Simple Shoutbox(34)
  3. Simple User System(19)
  4. Adding Data To A Database And Displaying It Later(1)
  5. How To Create Counter-strike 1.6 Server In Console Mode(5)
  6. Install An Aef Forum Onto The Trap17(11)
  7. Installing Apache And Php(2)
  8. Getting Started With Mysql(2)
  9. How To Make Your Own Counter Strike Source Dedicated Server!(38)
  10. Make A Moderately-secure Password System Using Javascript(4)
  11. Debug Exe Files(4)
  12. How To Extract The Audio From Youtube Videos(6)
  13. How To Create Pdf Files Using Free Tool(0)


 



- Lo-Fi Version Time is now: 12th October 2008 - 07:30 AM