I was wondering how can I disable the apache2 server from starting on boot up? I can't seem to find an option which disables it to auto start when I turn on the machine.

share|improve this question
1  
Perhaps someone can be more specific, but I can point you in the right direction... in /etc, there are directories for rc*.d, which contain all the start/stop scripts, called, I think, init scripts. You'll see links to scripts that are in /etc/init.d, and starting with either "k" or "s", for "kill" or "start", and a number which is the ordering. – Marty Fried Aug 1 '12 at 2:27
    
Yes, I knew about the /etc/rcX.d directories, but I searched for it to find out about some nicer tool, than just manually renaming files (life is too short). update-rc.d has filled this void. – Tomasz Gandor Sep 26 '14 at 8:53
up vote 110 down vote accepted

Under the folder /etc/init.d/ you will find all the init scripts for different boot up services, like apache2, networking, etc.

Depending on which runlevel the computer starts in, different services are started. So from the /etc/init.d/ folder each "service" is linked to one/many/no run level folders named from rc0.d to rc6.d.

To keep things simple there is a tool for removing/adding these links, hence removing or adding scripts to and from start up.

To remove apache2 simply type:

sudo update-rc.d -f  apache2 remove

Doing this will cause all runlevel folders that are linked to apache2 to be removed.

share|improve this answer
2  
chkconfig may also help - " chkconfig {service_name} off " – MCR Aug 1 '12 at 7:10
    
Doesn't work anymore: The script you are attempting to invoke has been converted to an Upstart job, but lsb-header is not supported for Upstart jobs. (...) – TomDogg Apr 29 '15 at 9:34
2  
@TomDogg, can you specify the versions you were working with? This answer works for Apache 2 on Ubuntu 14.04.3 – Dale Anderson Nov 2 '15 at 20:20
1  
How to restore the service? – Eugen Konkov Apr 14 '16 at 8:12
8  
Warning! This will REMOVE the service! Use sudo update-rc.d apache2 disable. – Eduardo Cuomo Jan 17 '17 at 19:37

you could simply disable it by:

sudo update-rc.d apache2 disable

and then if you would like to enable it again:

sudo update-rc.d apache2 enable

depending on the project i am working on, it is handy to have the service conveniently available, if i wish to re-enable it.

share|improve this answer
3  
enable gave me an error like runlevel arguments (none) do not match LSB Default-Start values, but sudo update-rc.d apache2 defaults appears to have re-enabled it successfully. – here Jan 13 '14 at 3:58
22  
+1, this should be the accepted answer. – jutky Jan 19 '14 at 11:34
2  
@here sudo update-rc.d apache2 enable played as expected for me – Georgios Pligoropoulos Feb 9 '14 at 15:12
    
On Ubuntu Trusty it tells me "The disable|enable API is not stable and might change in the future." – Tanner Jun 10 '14 at 0:31
1  
Doesn't work - error: no runlevel symlinks to modify, aborting!. However, apache2 is running and autostarts. – Daniel Kmak Dec 14 '14 at 11:05

With systemd we can now use systemctl commands to prevent a service from automatically starting at boot.

here is an example:

sudo systemctl disable apache2

You will still be able to start and stop the service but it won't start up at boot.

share|improve this answer
    
on Linux Mint (ubuntu based) this doesn't exist and can't install it via apt-get install systemd >> This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: systemd-services systemd-services:i386 – dragonmnl Dec 4 '15 at 11:57
2  
Linux Mint is still based on Ubuntu 14.04. Ubuntu starts using systemd from 15.04 on. – twan163 Dec 6 '15 at 23:01
1  
@dragonmnl as twan163 said, systemd is for the newer versions (debian jessie or equivalent +) – mchid Dec 8 '15 at 21:55
    
@dragonmnl to search for available packages, run the following command: apt-cache search systemd | grep systemd – mchid Dec 8 '15 at 21:57
1  
this worked great on Debian – Anupam Jul 19 '17 at 12:37

Thought I'd just add to the answers by @gsullins and @tomodachi, for future readers who used the accepted answer.

If you've already used:

sudo update-rc.d apache2 remove

You can use the argument defaults to add apache2 back into the autostart

sudo update-rc.d apache2 defaults

Then you're able to enable/disable

sudo update-rc.d apache2 disable
sudo update-rc.d apache2 enable
share|improve this answer

protected by Byte Commander Mar 3 '16 at 12:27

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.