Start Apache at System Reboot

December 4th, 2011 by admin Leave a reply »

My server provider had some node high load issues in the past month. They rebooted the node few times to make things normal. And I can’t blame them for doing that. Rebooting a node server takes few minutes and we won’t have hours of downtimes.
I was busy with my new job(I hate it!). However, I wasn’t able to touch my server under those circumstances. And every time my provider rebooted the server, Apache wasn’t starting automatically and therefore, my server suffered lots of downtime.

Since I have installed Apache from the source, I need to manually start Apache after every reboot. But that is a big problem if you are not in front of your server 24/7. That’s when we need to find a solution.

The solution for the issue is to add the Apache start to the default runlevel. It is something like Startup on Windows systems.

Follow the instructions below to add Apache start to the default runlevel.

  1. Create a file in /etc/init.d/ named apache.
    nano /etc/init.d/apache
  2. Paste the following code into it.
    #!/bin/sh
    case "$1" in
    start)
    echo "Starting Apache ..."
    # Change the location to your specific location
    /usr/local/apache/bin/apachectl start
    ;;
    stop)
    echo "Stopping Apache ..."
    # Change the location to your specific location
    /usr/local/apache/bin/apachectl stop
    ;;
    graceful)
    echo "Restarting Apache gracefully..."
    # Change the location to your specific location
    /usr/local/apache/bin/apachectl graceful
    ;;
    restart)
    echo "Restarting Apache ..."
    # Change the location to your specific location
    /usr/local/apache/bin/apachectl restart
    ;;
    *)
    exit 64
    ;;
    esac
    exit 0

    Note: It is a modified version of the script here: http://www.techsww.com/tutorials/servers/apache_web_http_server/tips_and_tricks/starting_apache_web_server_at_every_reboot_for_debian_ubuntu_linux.php
  3. Make the script executable.
    chmod u+x /etc/init.d/apache
  4. Add the script to default runlevel.
    update–rc.d –f apache defaults
  5. apache is the filename of the script we created in the /etc/init.d/ directory.

    Doing this will start Apache at the every system reboot and you need not to worry about losing visitors because of your Apache installation.

Advertisement

Leave a Reply

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.