This site has been running on nginx with php5-cgi for some time now. I’ve added and removed sites and features over the years, and when trying to stand up a new site recently, I realised the webserver’s franken-configuration could do with a thorough refactoring. In reading up on how to do this I stumbled across a post on ArsTechnica that suggested php5-fpm is the CGI binary all the cool kids are using these days. I decided to replace php5-cgi as part of my
spring autumn cleaning.
I installed php5-fpm and got it running with minimal fuss. I then stopped php5-cgi and tested all my sites were still working. They were, so I tried to finish the job by uninstalling php5-cgi, however apt wanted to install Apache2 at the same time. It didn’t seem to care that I had a perfectly good webserver already!
Googling around I found an Ubuntu bug describing similar symptoms. If I’d have read the comments carefully I might have found the clue I was looking for at this stage. Instead I ended up doing a bit more work. I ran this command as suggested in the bug discussion:
sudo apt-get remove -o=Debug::pkgProblemResolver=1 php5-cgi
This reported that the Squirrelmail package was complaining about an unmet dependency. Squirrelmail depends on the following packages:
apache2 | httpd, libapache2-mod-php5 | php5 | php5-cgi, perl
While nginx satisfies the httpd dependency, removing php5-cgi meant the middle set of options was left unmet, and apt was therefore trying to pull in libapache2-mod-php5 – which pulls in apache2.
Fortunately the fix was simple: install the php5 metapackage (the third package that can satisfy this dependency group). Removing php5-cgi then worked as expected.
From its description, php5 is “a metapackage that, when installed, guarantees that you have at least one of the four server-side versions of the PHP5 interpreter installed. Removing this package won’t remove PHP5 from your system, however it may remove other packages that depend on this one.” When I switched from apache2 to nginx I suspect I managed to do so without needing to install this metapackage, or if not, then I’d removed it during a previous tidying up exercise. D’oh!
The reply to this Debian bug flicked on the lightbulb for me, but a number of similar threads were returned when I started searching for answers to this problem, so I thought it would be worth posting my experience in case it helps anyone in a similar situation.