How to auto start Apache during boot time – Linux


auto start apache, start apache during boot, apache startup script, apache start up script, linux, computer tipsIf you compile your own apache from source, your apache will not auto start during boot time. To enable auto start apache during boot time, you need to do some configuration on rc.d directory.

Follow the steps below and apache will auto start during boot time:-

Advertisements

  • Go to init.d folder

    #cd /etc/rc.d/init.d

  • Create httpd file

    #vi httpd

  • Copy and paste the code below and save the file (content below is for user who install their apache at /usr/local/apache):-

    #!/bin/sh
    #
    # Startup script for the Apache Web Server
    #
    # chkconfig: 345 85 15
    # description: Apache is a World Wide Web server. It is used to serve \
    # HTML files and CGI.
    # processname: /usr/local/apache/bin/httpd
    # pidfile: /usr/local/apache/logs/httpd.pid
    # config: /usr/local/apache/conf/httpd.conf

    # Source function library.
    . /etc/rc.d/init.d/functions

    # See how we were called.
    case “$1” in
    start)
    echo -n “Starting httpd: ”
    daemon /usr/local/apache/bin/httpd -DSSL
    echo
    touch /var/lock/subsys/httpd
    ;;
    stop)
    echo -n “Shutting down http: ”
    killproc httpd
    echo
    rm -f /var/lock/subsys/httpd
    rm -f /var/run/httpd.pid
    ;;
    status)
    status httpd
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    reload)
    echo -n “Reloading httpd: ”
    killproc httpd -HUP
    echo
    ;;
    *)
    echo “Usage: $0 {start|stop|restart|reload|status}”
    exit 1
    esac

    exit 0

  • allow apache start up script to be executable

    #chmod 744 httpd

  • Now you need to test if this apache start up script is good, type

    ./httpd start

    in your shell to run the apache start up script

  • If you can execute this apache start up script with no error then you can continue with the next steps.
  • Create a symbolic link at /etc/rc.d/rc3.d folder with name S80httpd that link to /etc/rc.d/init.d/httpd

    #cd /etc/rc.d/rc3.d
    #ln -s ../init.d/httpd S80httpd

    Note: Click here for more details on how to create symbolic link

  • Your server now is ready to start apache during boot time. Please reboot your server to take immediate effect.
  • To check if apache will start up during boot time, type

    #ps ax | grep httpd

    at your shell right after you login with a new reboot, if it shows httpd process then you have configured your apache to start during boot time correctly.

[tags]apache auto start up during boot time, apache auto start, apache start up script, apache startup script, apache auto start script, apache start during boot, linux apache auto start[/tags]




Share this with your friends:-

10 Responses to “How to auto start Apache during boot time – Linux”

  1. chua says:

    hi CG, it’s depend on which distribution of Linux you are using. some distribution is for the engineer and some is for the end user. so you need to find the right distribution for yourself.

    If you are just a simple end user, then you may try Ubuntu Linux (http://www.ubuntu.com/).
    It make your life more easier with great User Interface.

  2. CG says:

    ARE YOU FUCKING SERIOUS???? How come linux installs don’t do all this, for all the apps when they install them. This is horseshit. Everything when you install it under linux is brain dead broken to begin with and does not work, you’ve got to search for FAQs on the net like this and then edit fucking files. Linux is bullshit crap

  3. Reijjo says:

    How about “chkconfig” command? It is intented to be used instead of these crappy scripts and manual init.d editing?!?!?

  4. avinash says:

    Hi,
    i dont have such path in my suse /etc/rc.d/init.d?

    init.d is directly in /etc.

    any idea how to solve this??

    please help

  5. sheri says:

    Your script has bug.below script works I correct it.You can use..

    #!/bin/sh
    #
    # Startup script for the Apache Web Server
    #
    # chkconfig: 345 85 15
    # description: Apache is a World Wide Web server. It is used to serve \
    # HTML files and CGI.
    # processname: /usr/local/apache/bin/httpd
    # pidfile: /usr/local/apache/logs/httpd.pid
    # config: /usr/local/apache/conf/httpd.conf

    # Source function library.
    . /etc/rc.d/init.d/functions

    # See how we were called.
    case “$1″ in
    start)
    echo -n “Starting httpd: ”
    daemon /usr/local/apache/bin/httpd -DSSL
    echo
    touch /var/lock/subsys/httpd
    ;;
    stop)
    echo -n “Shutting down http: ”
    killproc httpd
    echo
    rm -f /var/lock/subsys/httpd
    rm -f /var/run/httpd.pid
    ;;
    status)
    status httpd
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    reload)
    echo -n “Reloading httpd: ”
    killproc httpd -HUP
    echo
    ;;
    *)
    echo “Usage: $0 {start || stop || restart || reload || status}”
    exit 1
    esac

    exit 0

  6. chua says:

    sorry Sot, if my script disappoint you.
    I’m just a newbie in linux.

  7. Sot says:

    Dude your script sucks in MANY ways. I feel sorry for the newbies that copy paste this piece of crap into their systems.

  8. chua says:

    different Linux distribution have slightly different directory structure.
    It’s normal. as long as your file are located at the system init.d directory, it should be ok.

  9. shuji says:

    is it any of the init.d path should be ok?
    my init.d path located at /etc/init.d only.

  10. shuji says:

    Hi,
    i dont have such path in my ubuntu /etc/rc.d/init.d?
    any idea how to solve this??

    please help

    regards
    Shuji

Leave a Reply