How to Stop Apache Service

How to Stop Apache Service thumbnail
Stop your Apache server correctly to prevent database corruption or other data loss.

The Apache Web server is a multi-threading server software package that can be started and stopped at will. Because Apache is a multi-threading server, it may have what are called "multiple child processes" running under its own Process Identification number. Stop the Apache daemon, which is the running process, by stopping the parent rather than any of its child processes to prevent any possible data corruption. Such corruption can occur if a child process is in the middle of writing data to a database or a flat storage file when it is stopped.

Instructions

    • 1

      Log in as the superuser or administrator on the server machine and type the following at the command prompt in the terminal: "locate apachectl". This command will check the server machine to see if the "apachectl" utility has been installed. If the utility is installed, always use it rather than the alternative method provided in these instructions.

    • 2

      Type the following command to list all instances of the keyword "apache2" on the system: "locate apache2*log". This command will locate your apache2 directory on the server system. Put the asterisk between the two words so that the command also finds the log files. Press "Return" or "Enter" to list the locations. Use the apache2 directory in which the log files are located. For the remainder of this tutorial, it will be assumed that the needed apache2 directory is located in "/usr/local/apache2" and that the Process Identification file is at the location "/usr/local/apache2/logs/httpd.pid."

    • 3

      Shut down Apache2 immediately by using the following command: "apachectl -k stop" and then wait a few seconds for the server to stop. This command abruptly stops any downloads that may be in progress by visitors to the website being served by Apache, and these Web pages will not load completely. If the "apachectl" utility isn't installed on the server, you can obtain the same result with the "kill" command as follows: "kill -TERM `cat /usr/local/apache2/logs/httpd.pid`".

    • 4

      Stop the apache2 server with a "graceful restart," which will allow all present Web page requests to finish loading without permitting any new page requests to enter the queue after you have entered the command. Perform a graceful restart using the "apachectl" utility by entering the following command: "apachectl -k graceful-stop". Type the following "kill" command for a similar stop, where the server is immediately restarted so the outage doesn't become apparent to visitors, when "apachectl" utility isn't installed on your computer: "kill -HUP `cat /usr/local/apache2/logs/httpd.pid`".

Tips & Warnings

  • Be courteous to users pointing their Web browsers to websites being served by your Apache2 server. Stop the server and make changes at midnight where the server is located to avoid doing server updates or configuration changes during the busiest times of the day.

Related Searches:

References

  • Photo Credit Thinkstock Images/Comstock/Getty Images

Comments

Related Ads

Featured