Redhat – httpd service is not starting automatically

apache-2.2apache-2.4init.dredhat

I compiled Apache and PHP from source on a RedHat server, but in doing that, I forget to install the httpd as service.

Files used to compile Apache 2.4.7

files to compile apache 2.4.7

Command used to compile Apache 2.4.7

./configure --prefix=/etc/apache247 --with-included-apr --with-pcre --enable-so --enable-rewrite=shared --with-layout=Apache --enable-modules=most --enable-mods-shared=all;

Directory of Apache 2.4.7

apache 2.4.7 directory

Script of init.d to start Apache 2.4.7

I found this script in stackoverflow. It's not mine and not official.

Some users have told me that there is a script in the apache folder, but I have not found.

init.d apache script

If you prefer the text:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          apache247
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: apache247
# Description: Start apache247
### END INIT INFO

case "$1" in
start)
        echo "Starting Apache ..."
        # Change the location to your specific location
        /etc/apache247/bin/apachectl start
;;
stop)
        echo "Stopping Apache ..."
        # Change the location to your specific location
        /etc/apache247/bin/apachectl stop
;;
graceful)
        echo "Restarting Apache gracefully..."
        # Change the location to your specific location
        /etc/apache247/bin/apachectl graceful
;;
restart)
        echo "Restarting Apache ..."
        # Change the location to your specific location
        /etc/apache247/bin/apachectl restart
;;
*)
        echo "Usage: '$0' {start|stop|restart|graceful}"
        exit 64
;;
esac
exit 0

ntsysv

I use this command to check the services on RedHat. So, I put the init.d script in the correctly folder – /etc/init.d/ – but the apache2 script not appear here.

enter image description here

And after I restart the server, apache was not started automatically.

So, whats wrong?

I don't know in what log I get this errors of startup scripts.


Best Answer

It sounded like you needed to register the init script with chkconfig --add apache247. You can then mark it as 'on' for the default run-levels with chkconfig apache247 on. A reboot should verify this will work as expected.