Add Apache to Ubuntu's startup
Solution 1
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
.
Solution 2
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.
Related videos on Youtube
Jerry Nixon
Updated on September 17, 2022Comments
-
Jerry Nixon over 1 year
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 tolocalhost
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)?
-
Admin over 13 yearsWhile a good learning experience, please don't do this sort of thing long-term. The whole point of the distributions package manager is to keep things patched and up to date. If you start manually building things then YOU need to ensure they stay up to date.
-
Admin over 13 years@develop: Of course, a distribution like Ubuntu is going to keep versions fixed, only doing maintenance updates, and there aren't necessarily bleeding-edge PPAs for every package you care about - so sometimes if you want a new version, you do have to build it yourself.
-
-
Cascabel over 13 yearsYou could also grab the init.d script out of the apache package, and tweak it just a little bit. You'd end up with a much more robust script.
-
Jerry Nixon over 13 yearsthanks. i came to a conclusion that Ubuntu's Upstart is the way to go as well. RHEL 6 is using it as well.