Tuesday 17 July 2018

Install, Start, Stop, and Uninstall Apache Service on Windows

Install, Start, Stop, and Uninstall Apache Service on Windows

For PHP users, just like me, it annoyed when we should turn on and turn off the apache server manually, it’s like doing the same thing again and again, be more practical if the server automatically runs when we turn on our computer, right? there many solutions out there such as creating auto start file, but the best solution is to use a service, so let’s discuss how to install apache service on windows.
The same thing has also happened to MySQL, so if you are in the same case, you can refer to this tutorial: Install, Start, Stop, and Uninstall MySQL Service on Windows
In order to be able to install the service, the command prompt should be run as Administrator, to do so, click on the windows start menu and type cmd, then right click on the cmd file that appears in the search box and click Run as Administrator. The cmd(dot)exe file can also be found in Windows system folder (C:\Windows\System32)
Run Command Promt As Administrator

I. Install Apache Service on Windows

After you open your command prompt window, then navigate to bin directory that located inside apache in your xampp folder, for instance (E:\xampp\apache\bin), for example, I use xampp folder located in drive E. Next, use the following command to install the service:
httpd -k install
The complete command shown bellow:
Install Apache Service on Windows Using Command Promt
The image above shows that the apache service is successfully installed without any errors.
Note:
Please look at the image above, there is a message Errors reported here must be corrected before the service can be started“, this means that after successfully installing apache service, httpd is testing it, whether it able to start or not, if encountering a problem, then it will be reported below the message. Here is an example:
Error in Installing Apache Service on Windows
It reported that port 80 is being used, so the apache service will not able to start.
Install using custom service name
If you want to install the service using your own name, you can use this command:
httpd.exe -k install -n "Your Service Name"
The following figure shows the instance of the complete command:
Install Apache Service on Windows Using Custom Name

II. How to start Apache Service on Windows

After you successfully install apache service on Windows, then it won’t work until you start it or restart the windows, so the next step is run the service, to do so, use the following command:
httpd -w -k start
if you install the service using your custom service name, then you should determine the name in the command, the command is:
httpd -w -k start -n "Your Service Name"
For instance, here I start the service using custom name “Apache 2.4 – PHP 5.6” that I have installed previously:
Start Apache Service on Windows Using Custom Name
If no error message appears (like the picture above), then the service would be running without problem. The following figure shows that an error occurs:
Error When Starting Apache Service on Window
The system couldn’t find the service named “Apace 2.4 – PHP 5.6” (missing h on Apace)
Stopping the apache service
To stop the service, use the following command:
httpd -w -k stop
if you use a custom service name, use the following command:
httpd -w -k stop -n "Your Service Name"
The following figure shows the use of the command above:
Stopping Apache Service on Windows Using Custom Name
Restarting the apache service
To restart the service, use the following command:
httpd -w -k restart
if you want to restart the service using a custom name, then use the following command:
httpd -w -k restart -n "Your Service Name"
For example, we’ll restart the apache service named “Apache 2.4 – PHP 5.6”:
Restarting Apache Service on Windows Using Custom Name

III. How to Un install Apache Service on Windows

If you change your mind and want to remove / uninstall the apache service, then use the following command:
httpd -k uninstall
if your service uses a custom name, then use the following command:
httpd -k uninstall -n "Your Service Name"
For example, I’ll remove apache service named “Apache 2.4 – PHP 5.6” that I have previously installed.
Uninstall Apache Service on Windows with Custom Name

IV. Additional Note

Probably you know that Windows provide a tool that can be used to manage services in Windows including Apache service that we discussing here, this tool is named Services.msc, to access it open your windows start menu and type service, then click on the Services.msc name that appears in the search box. You can also open the Services.msc file through Windows Control Panel by navigating to: Start » Control Panel » System and Security » Administrative Tools.
The Services.msc Windows
In some situation, and when running, stopping, and restarting the apache service, you may convenience using this tools rather than typing the command to do this simple task, but this tool has some limitation,that is: it isn’t able to Install and Remove/Uninstall the services.

0 comments:

Post a Comment