Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have installed apache2 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 redhat distribution:

Linux <hostname> 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux

share|improve this question
Which distribution? – ayaz Jun 1 '09 at 14:18
up vote 29 down vote accepted

you want to add its init script to the approriate 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:

rc-update add apache2 default

On Ubuntu/Debian this works:

sudo update-rc.d apache2 defaults

on Redhat/Fedora/CentOS a little googling shows this:

chkconfig --add httpd

It varies a little bit from distro to distro, but the idea is usually the same. Basically what all these commands do is make a symbolic link from /etc/init.d/ to the appropriate run-level folder in /etc/.

share|improve this answer
Thanks for the answer it got me pointed in the right direction. I summarized what I did below. – grieve Jun 1 '09 at 15:29
If you have built apache from source there won´t be any init script, the part you covered is only the configuration as a service once you have a init script correctly set up in /etc/init.d/ and that's precisely what isn't really well documented for apache 2 – Jaime Hablutzel Jan 10 '12 at 17:53

Here is what finally worked for me. This assumes you are the root user.

  1. touch /etc/init.d/apache2
  2. chmod 755 /etc/init.d/apache2
  3. vi /etc/init.d/apache2 (edit it as shown below)
  4. chkconfig --add apache2
  5. chkconfig --list apache2 (to verify that it worked)

Contents of /etc/init.d/apache2:

# apache2        Startup script for the Apache HTTP Server
# chkconfig: 3 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.

/usr/local/apache2/bin/apachectl $@

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:

share|improve this answer
I really hate to accept my own answer, but it is the one that worked. – grieve Jun 9 '09 at 22:33
Great work +1 from me. – pregmatch Oct 8 '13 at 20:45
This was exactly what I needed! (had to recompile and install a 2.2.27 Apache in /usr/local/apache2). Thanks a lot. – Christophe Muller Dec 3 '14 at 16:11
does this line "/usr/local/apache2/bin/apachectl $@" actually starts httpd? do you need to issue: sudo chkconfig apache2 start or sudo chkconfig apache2 on? – olala Jul 14 at 4:59

Check if you have the httpd init script in the /etc/rc.d directory. If yes then you can just run following command which enables the httpd service to start at boot time.

chkconfig --level 345 httpd on

If you don't have init script then just append /etc/rc.local file with apachectl -k start (the command to start apache).

share|improve this answer

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

Starting at Boot-Time

If you want your server to continue running after a system reboot, you should add a call to apachectl to your system startup files (typically rc.local or a file in an rc.N directory). This will start Apache as root. Before doing this ensure that your server is properly configured for security and access restrictions.

The apachectl script is designed to act like a standard SysV init script; it can take the arguments start, restart, and stop and translate them into the appropriate signals to httpd. So you can often simply link apachectl into the appropriate init directory. But be sure to check the exact requirements of your system.

share|improve this answer
Thanks for the answer it got me pointed in the right direction. I summarized what I did below. – grieve Jun 1 '09 at 15:29

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.

share|improve this answer
This generates the following error with me on CentOS 6: "only one runlevel may be specified for a chkconfig query". However, adding "on" to the end of the command ("chkconfig --levels 345 httpd on") worked like a charm. – akame Jun 16 at 7:26

It depends on your flavour of linux. Assuming the file /etc/init.d/apache2 has been created, try:

chkconfig -a apache2


update-rc.d apache2 defaults

One of them should work.

share|improve this answer
The chkconfig answer is for Red-Hat like systems (ie CentOS) and update-rc.d is for Debian like systems (ie Ubuntu) – Kyle Brandt Jun 1 '09 at 14:20

On Redhat 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 so a star appears in the left hand box. Then to OK. Press 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:

chkconfig --add <script name>
share|improve this answer

protected by Sven Apr 4 at 15:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.