Start Apache Web Server on boot in Linux

Start Apache Web Server on boot in linux tutorial helps developers to configure  apache web server on linux boot.

High Level Steps:

  1. create the httpd script in /etc/init.d
  2. add the httpd symbolic link in rc.d directories

 

Start Script creation Steps:

  • Log in as root user and create httpd script
    1. cd /etc/init.d
      vi httpd
  • below  is the script:
    1. ARGV="$@"
      
      # this is path to your apache directory, including options if necessary
      HTTPD=/usr/local/apache/bin/apachectl
      #
      # pick up any necessary environment variables
      if test -f /usr/local/apache/bin/envvars; then
       . /usr/local/apache/bin/envvars
      fi
      
      # Set this variable to a command that increases the maximum  number of file descriptors allowed per child process. This is
      # critical for configurations that use many file descriptors, such as mass vhosting, or a multithreaded server.
      ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"
      
      
      # Set the maximum number of file descriptors allowed per child process.
      if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
       $ULIMIT_MAX_FILES
      fi
      
      ERROR=0
      if [ "x$ARGV" = "x" ] ; then
       ARGV="-h"
      fi
      
      case $ARGV in
      start|stop|restart|graceful|graceful-stop|status|fullstatus)
       $HTTPD -k $ARGV -DSSL
       ERROR=$?
       ;;
      *)
       $HTTPD $ARGV
       ERROR=$?
      esac
      
      exit $ERROR
  • save and exit

Create Symbolic links in Linux BOOT folders:

  • Add symbolic links to rc.d directories and below are commands: Click here to know about this rc.d directories
    • Kill Process Links:
      • ln -s /etc/init.d/httpd /etc/rc.d/rc6.d/K26httpd
         ln -s /etc/init.d/httpd /etc/rc.d/rc0.d/K26httpd
    • Start Process Links:
      • ln -s /etc/init.d/httpd /etc/rc.d/rc3.d/S81httpd

        ln -s /etc/init.d/httpd /etc/rc.d/rc2.d/S81httpd ln -s /etc/init.d/httpd /etc/rc.d/rc5.d/S81httpd

  • you can issue the below commands to start or stop servers: service httpd {command-name}

List of Commands:

  • start – Start the Apache httpd daemon and gives error if it is already running. This is equivalent to apachectl -k start.
  • stop – Stops the Apache httpd daemon. This is equivalent to apachectl -k stop.
  • restart – Restarts the Apache httpd daemon . If the daemon is not running, it is started. This is equivalent to apachectl -k restart.
  • fullstatus – Displays a full status report from mod_status. For this to work, you need to have mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report can be set by editing the STATUSURL variable in the script.
  • status – Displays a brief status report. Similar to the full status option, except that the list of requests currently being served is omitted.
  • graceful -Gracefully restarts the Apache httpd daemon. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files as in configtest before initiating the restart to make sure Apache doesn’t die. This is equivalent to apachectl -k graceful.
  • graceful-stop – Gracefully stops the Apache httpd daemon. This differs from a normal stop in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This is equivalent to apachectl -k graceful-stop.
  • startssl  – This command is not available latest version.

 

Hope this helps

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *