Add Apache to Ubuntu's startup

I’m currently learning the Linux environment, and decided to manually install the Apache server. For educational purposes, I’ve compiled it into:


The http.conf location is configured correctly. It works — I can open up a browser and navigate to localhost and see the “It works” message. But how does one goes about adding Apache into Ubuntu’s startup so I won’t have to do:

sudo /server/apache/bin/apachectl start

all the time? Can somebody explain how does one goes into adding programs to the Ubuntu startup (10.10 64 bit)?

Asked By: Stann


Here is a good resource, quite close to what you ask for.
Basically to make apache2 start automatically you need to run

update-rc.d apache2 defaults

This will make the startup script start the service located in /etc/init.d/apache2 after booting up. Beforehand, you need to make an init script and put it in /etc/init.d/. In your case

ln -s /server/apache/bin/apachectl /etc/init.d/apache2

may be good enough.

Answered By: phunehehe

The easiest way is to take the Apache startup script in Ubuntu’s Apache package, and replace /usr/sbin/apachectl by /server/apache/bin/apachectl.

If it’s a learning exercise, you have several options (from most flexible to least flexible):

  • Start Apache through Upstart. You have to write a file /etc/init/my_apache.conf. Given the state of Upstart documentation, I recommend reading existing examples and the man pages in parallel.
  • Start Apache through a SysV script: an executable script in /etc/init.d that starts, stops, restarts or reloads the Apache configuration depending on whether its first (and sole) argument is start, stop, restart, or reload (with force-reload as an alias for reload). To have the script start on boot, run update-rc.d. See also the Ubuntu Bootup Howto.
  • Start Apache from /etc/rc.local.
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.