I have installed Apache 2 from source on my Linux box. apachectl -k start
works just fine, but how do I get Apache to start at boot time?
This is on a Red Hat Linux distribution:
Linux <hostname> 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
You want to add its init script to the appropriate run level. The init script is typically
/etc/init.d/apache2
where you could manually run/etc/init.d/apache2 start
to start it.On Gentoo you would write:
On Ubuntu/Debian this works:
On Red Hat Linux/Fedora/CentOS a little googling shows this:
It varies a little bit from distribution to distribution , but the idea is usually the same. Basically, all these commands make a symbolic link from
/etc/init.d/
to the appropriate run-level folder in/etc/
.Here is what finally worked for me. This assumes you are the root user.
Contents of /etc/init.d/apache2:
You can get the runlevel by running /sbin/runlevel, which in my case was 3. And of course you need to call your version of apachectl, which in my case was /usr/local/apache2/bin/apachectl
Thanks to the following:
Check if you have the
httpd
init script in the/etc/rc.d
directory. If yes, then you can just run the following command which enables the httpd service to start at boot time.If you don't have the init script, then just append the
/etc/rc.local
file withapachectl -k start
(the command to start Apache).As you have installed by source there will not be an init script installed in the /etc/init.d/ directory. The apachectl binary is designed to be compatible with standard init script options so you may well be able to simply symlink to it rather than creating a wrapper script (e.g ln -s /usr/local/sbin/apachectl /etc/init.d/apache)
You can then follow the procedures outlined in the other posts for adding links to invoke the init script at the correct runlevels.
Citation: Apache Documentation http://httpd.apache.org/docs/2.2/invoking.html
It depends on your flavour of Linux. Assuming the file /etc/init.d/apache2 has been created, try:
or
One of them should work.
chkconfig --levels 345 httpd
will start httpd in runlevels 3,4,5.
chkconfig --list will show all services and their current startup runlevels. 345 is typical for a network service.
On Red Hat Linux there is a useful utility called ntsysv which lets you select which services you want to start in your current run level. You call also specify which run level you want to edit when you start the utility using
--level
.Scroll down to httpd and press Space so a star appears in the left hand box. Then Tab to OK. Press Return to save and return to the shell.
I've found that it installs pretty much by default. I've never been in a position where it wasn't installed.
You would need to install the service first though by copying the service script into /etc/init.d then running: