Remove Apache and PHP installation from Ubuntu Server

Trying to get a fresh start.

$ dpkg -l | grep 'apache2|php5' | awk '{ print $2}' | sed ':a;N;$!ba;s/n/ /g' | xargs apt-get -y autoremove

$ dpkg -l | grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge

I think this works. Well it works once.

(or use apt-get purge -y instead of dpkg --purge)