Here are a few neat tricks for using Aptitude (Debian Package managment tool).
If you need to install all packages with a certain prefix, like say all the packages relating to php5, you would type this:
sudo aptitude install ~n^php5
Of course, if you find that a single package, like say php5-fpm causes seriousl problems.... when you are prompted by aptitude if you want to install the listed files (Y/N/Q) rather then typing 'y' type:
That '-' is important because it says to remove php5-fpm from the list.
After this you will be presented with another list of packages...without php5-fpm. If you want to remove another package, you can do so again.