How do I prevent Apache service from auto-starting on Linux?

My problem is that I don't want to stop the apache daemon with the command ./apache2 stop from /etc/init.d (I know to do this). I don't want the apache service start automatically in /etc/init.d on the system startup. But I also need to keep the service in the init.d folder. How can I do this? Do I have to change some fields in the service script ?


Depending on your distro, you should be able to execute a command to disable the service on startup. Doing this it will be stopped until you manually start it. Here are some examples on different distros:

  • Ubuntu/Debian: update-rc.d -f apache2 remove
  • Gentoo: rc-update del apache2
  • ArchLinux: systemctl disable apache2

This is an old thread, but I’ll add what I've just learned to help others who come here.

For Debian, the problem with the answer given is that the change will be undone the next time there's an update to the software. From the man page for update-rc.d:

A common system administration error is to delete the links with the thought that this will "disable" the service, i.e., that this will prevent the service from being started. However, if all links have been deleted then the next time the package is upgraded, the package's postinst script will run update-rc.d again and this will reinstall links at their factory default locations.

I believe that it’s better to use the disable directive:

sudo update-rc.d apache2 disable

This has the advantage that the enable directive can reverse the change.