How do I stop Apache2 from automatically starting on boot?

How do I stop Apache2 from automatically starting on boot? I can't seem to find an option that disables the automatic start-up when I turn on the machine.


Solution 1:

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.

Solution 2:

On old,pre systemd distributions under /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 disable apache2 simply type:

sudo update-rc.d apache2 disable

This disables apache2 at startup but is not removed so it can be enabled again. To remove the apache2 startup scripts do the following:

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.

Solution 3:

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.

Solution 4:

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