If you have a service/daemon you don't want to be started by default at the startup you probably know that you can use a command like this one to deactivate the service:

Removing any system startup links for /etc/init.d/apache2 ...  

The problem, though, will be with when you update your server with a "aptitude update && aptitude -y safe-upgrade" (or alike). Why? Just check out the post scripts of Apache at /var/lib/dpkg/info/apache2.2-common.postinst:

94 # Automatically added by dh_installinit  
95 if [ -x "/etc/init.d/apache2" ]; then  
96         update-rc.d apache2 defaults 91 09 >/dev/null || exit $?  
97 fi  
98 [...]

You see that update-rc.d command? It enables the service again :( That means that at the next reboot, Apache will start again. Lucky you. And this is exactly what you don't want to.

One possible solution is this one:

cat "DPkg::Post-Invoke {" update-rc.d -f apache2 remove";};  " >

What that does is to create a script that will be executed every time you run apt or aptitude and after its execution (post-invoke) will run the given command. In our case, it will run "update-rc.d -f apache2 remove". So if there is an Apache update, the Apache postscript will activate the Apache service on the startup and we will disable it just after that. Pretty neat, right?

Is you are using upstart its easier. Just execute the following command and you are done:

echo "manual" > /etc/init/apache2.override

Take care!