How do I stop Apache2 from automatically starting on boot?
Solution 1
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 2
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 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
Related videos on Youtube
chip
Currently working as a software developer and tester, we're applying the concepts of scrum in our work and it's awesome
Updated on September 18, 2022Comments
-
chip almost 2 years
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.
-
Admin almost 12 yearsPerhaps 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.
-
Admin almost 10 yearsYes, 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.
-
-
Vitaliy almost 12 yearschkconfig may also help - " chkconfig {service_name} off "
-
here over 10 years
enable
gave me an error likerunlevel arguments (none) do not match LSB Default-Start values
, butsudo update-rc.d apache2 defaults
appears to have re-enabled it successfully. -
George Pligoropoulos over 10 years@here
sudo update-rc.d apache2 enable
played as expected for me -
Tanner about 10 yearsOn Ubuntu Trusty it tells me "The disable|enable API is not stable and might change in the future."
-
Daniel Kmak over 9 yearsDoesn't work -
error: no runlevel symlinks to modify, aborting!
. However, apache2 is running and autostarts. -
TomDogg about 9 yearsDoesn't work anymore:
update-rc.d: error: no runlevel symlinks to modify, aborting!
-
TomDogg about 9 yearsDoesn'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. (...)
-
Incerteza almost 9 yearswhat's the difference between "disable" and "remove"?
-
mchid almost 9 years@AlexanderSupertramp well, with systemd, disable will stop the service from automatically starting at boot and mask will disable the service completely by creating a simlink to /dev/null.
-
Dale Anderson over 8 years@TomDogg, can you specify the versions you were working with? This answer works for Apache 2 on Ubuntu 14.04.3
-
Dale Anderson over 8 yearsIt's worth noting, the
-f
here meansForce removal of symlinks even if /etc/init.d/name still exists.
As in, "if you're going to leave Apache2 installed, you gotta do it like tomodachi says.". Without the-f
, you're telling it you've already uninstalled Apache 2, and it results in errors. -
dragonmnl over 8 yearson 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
-
twan163 over 8 yearsLinux Mint is still based on Ubuntu 14.04. Ubuntu starts using systemd from 15.04 on.
-
mchid over 8 years@dragonmnl as twan163 said, systemd is for the newer versions (debian jessie or equivalent +)
-
mchid over 8 years@dragonmnl to search for available packages, run the following command:
apt-cache search systemd | grep systemd
-
nealmcb over 8 years@jutky can someone explain why this is better than tomodachi's answer, given the comment there that says the
-f
option is necessary if you want to keep apache2 around? -
jutky over 8 years@nealmcb nothing personal, but "disable" sound less dangerous to me than "remove"
-
Eugen Konkov about 8 yearsHow to restore the service?
-
Eduardo Cuomo over 7 yearsWarning! This will REMOVE the service! Use
sudo update-rc.d apache2 disable
. -
Anupam almost 7 yearsthis worked great on Debian
-
John over 6 yearsthe right answer for debian 9+
-
smac89 about 6 yearsYou might want to stop it first, and THEN disable it.
sudo service apache2 graceful-stop
-
Amil Waduwawara almost 6 yearsIf encounter
update-rc.d: error: no runlevel symlinks to modify, aborting!
, recreate any below missing simlinks; then retry: /etc/rc0.d/K01<service> /etc/rc1.d/K01<service> /etc/rc2.d/S99<service> /etc/rc3.d/S99<service> /etc/rc4.d/S99<service> /etc/rc5.d/S99<service> /etc/rc6.d/K01<service> -
Amil Waduwawara almost 6 yearsIf encounter
update-rc.d: error: no runlevel symlinks to modify, aborting!
, recreate any below missing simlinks; then retry: /etc/rc0.d/K01<service> /etc/rc1.d/K01<service> /etc/rc2.d/S99<service> /etc/rc3.d/S99<service> /etc/rc4.d/S99<service> /etc/rc5.d/S99<service> /etc/rc6.d/K01<service> -
whyer about 5 yearsthank you! i use xampp for dev purposes. when i installed php7.3 from ondrej ppa (to use it with composer), the apache2 began to start on system boot, thus conflicting with xampp's embedded httpd. your proposed solution has worked for me: after running
sudo systemctl disable apache2
and rebooting, apache doesn't start up on boot anymore and thus xampp's embedded httpd has continued to work as it did earlier. thank you! 👍 (ubuntu 18.10) -
Carolus almost 4 yearsI did this for sshd and it no longer autostarts, but I also cannot start it manually with
sudo systemctl start sshd
becauseFailed to start sshd.service: Unit sshd.service not found.
. Fixed it by reinstalling.