How to start Apache server automatically?
Solution 1
The easiest way would be to put:
/server/apache/bin/apachectl start
into "/etc/rc.local". The better way to do it would be to create an /etc/init/apache.conf upstart script, I believe the correct values would be something along the lines of:
start on runlevel [2345]
stop on runlevel [!2345]
expect daemon
exec /server/apache/bin/apachectl start
pre-stop exec /server/apache/bin/apachectl stop
Then run "initctl start apache" to start it and "initctl stop apache" to stop it. For more information on upstart configuration files like the above, see "man 5 init".
Solution 2
sudo update-rc.d httpd defaults
This will use the default run levels that the script provides, which includes starting it up and shutting it down. update-rc.d is the standard for manipulating services on Debian-based systems. Good luck!
Andrew
Related videos on Youtube
Stann
Updated on September 17, 2022Comments
-
Stann almost 2 years
I want to manually install Apache server. I've compiled it into:
/server/apache
http.conf configured correctly. It works. I can open up a browser and navigate to localhost and I can see "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 Ubuntu startup (10.10 64 bit)?
RESOLUTION
I learned a lot. It looks like there are 2 ways of doing it:
1) Historical ways: most Unix/Linix distros historically followed System.V initialization patter. This way all u have to do is write a special start/stop/restart script, chmod +x it and put in under /etc/init.d directory. Then you run update-rc.d command which creates links under different runlevels. and that's how it works. la la la
2) New way. Many linux distros currently switching from old runlevel based system to event based initialization. In my case Ubuntu (also RHEL 6.0 and Fedora) uses system called Upstart which eventually will completely replace systemV version. it uses /etc/init folder. All you have to do is create a script, chmod +x it and put it under /etc/init dir. Upstart information
-
Arenstar over 13 yearsIs there one not included in your src, from where you compiled it?
-
Andrew M. over 13 yearsIs there any reason you're using a custom version? Unless there's a specific reason, NOT using the provided version is not recommended.
-
jgoldschrafe over 13 yearsYou should really look at the Filesystem Hierarchy Standard.
/server
is an incredibly questionable place to put binaries. -
Stann over 13 yearsi'm new to linux. i think the best way to learn is by trying stuff. True - one can use yum or apt-get to get things done quickly. but this way u don't know what's going on behind the scene. As to /server directory - yeah - that wasn't the right place. Afterlooking through Linux hierarchy standard it looks like you'd be better of putting your binaries either into /opt or /usr/local - right?
-
Andrew M. over 13 yearsUnless you're interested in the actual compilation process, I'd say you're better off sticking to the packages. They're provided for a reason--and by circumventing the packages, you're going to clutter up your system even more. For example, the answer that was provided works--but is going to be impossible to maintain. Just keep that in mind.
-
Stann over 13 yearsI respect your opinion. But I really don't see the drawbacks from compiling programs myself. What's wrong with compiling programs and putting them in let's say /usr/local directory? You will aways have the latest versions as well. Can you elaborate why would you use package manager vs compiling aside from apt-get obviusly being faster and easier?
-
-
MShoubaki over 13 yearsupdate-rc.d requires that the init script already exist, including meta information within it formatted for update-rc.d, which the question asker doesn't have because they aren't using the packaged install.
-
Andrew M. over 13 yearsYou're absolutely right; I glazed over the fact that the OP was compiling their own version.
-
Stann over 13 yearsI was wondering about that....:)
-
Stann over 13 yearsnice. that's what worked for me....