An issue that has baffled me for the past weeks has finally been solved, thanks to my digital detective friend from Santarago Labs.
This post applies to the following errors:
- WordPress
- “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”
- “Deine PHP-Installation scheint nicht über die von WordPress benötigte MySQL-Erweiterung zu verfügen.”
- OpenCart
- PHP Fatal error: Call to undefined function mysql_connect() in system/database/mysql.php on line 6
The Story
I had been having strange intermittent issues with PHP on my web server. The server runs the absolutely wonderful Lighttpd. On every couple of requests to the PHP CGI backend, there would be an error. The error was basically that PHP could not connect to MySQL because its Shared Object, its mysql.so
, was missing. This error usually pops up if you just freshly installed PHP and forgot to install MySQL, but that was definitely not the case. Besides, that would not explain why it sometimes did work. Very strange indeed.
So, being the blunt sysadmin-in-teaching that I am, I re-installed PHP, Lighttpd and MySQL. No dice. I checked, and double checked PHP, MySQL and Lighttpd configuration files, everything seemed just fine.
At first we thought it might be a time-out thing. Some badly written PHP software open such a large number of connections to MySQL that the system runs out of port numbers. But none of these signs were apparent. No errors of that kind, and when the system did work, it was fast. A struggling application would most assuredly create load, and it wasn’t there.
Turning on all logging, and still nothing out of the ordinary. No errors, except the intermittent complaining about the missing MySQL extension. What a mystery!
So, what was going on?
It turned out that after upgrading Debian to a new version (from 5 to 6, in this case) the web server did not correctly kill off all php5-cgi
processses. The output of pstree -a
showed that there were some stray processes directly under root which sometimes were appointed a request. This would definitely account for the intermittent behavior!
Solution
First, run pstree -a
Then, check the results. The PHP processes should look something like this.
In short, they should all snugly nest under the lighttpd
process. If you find some PHP processes floating around elsewhere, continue to the next step.
Kill off all PHP processes by doing: kilall php5-cgi
And you are done!
I hope this post will help someone with the same problem as me, and that it will save someone the many hours I wrestled with this problem. Again, thanks to Vincent!
Let me know what you think :)