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:
/server/apache
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)?
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.
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 isstart
,stop
,restart
, orreload
(withforce-reload
as an alias forreload
). To have the script start on boot, runupdate-rc.d
. See also the Ubuntu Bootup Howto. - Start Apache from
/etc/rc.local
.