Once again installed PHP 5, MySQL 5 and Apache 2 on my laptop (running Windows XP), and once again I had problems, MySQL was not available in PHP. I’d solved the problem before, but could not remember how.
The problem should not happen at all, the issue is in fact quite trivial. But a series of small problems occur, and the various layers involved make it difficult to see where and why things go wrong. So I’ve put together this checklist.
- Client software
- Grab the latest version of the MySQL libraries for PHP from MySQL, they’re more up to date. Overwrite the existing files PHP/libmysql.dll and PHP/ext/php_mysql.dll
- Note: this is not mandatory, the files shipping with PHP 5 work just fine (if you can get them to).
- MySQL no longer bundled with PHP 5
- As very clearly explained here, the MySQL libary used to be bundled in PHP 4, but is no longer part of PHP 5. The necessary files are still available, it’s only a configuration issue.
- In php.ini, configure the
extension_dirdirective and uncomment the
- This should make the MySQL PHP functions available. But don’t restart Apache just yet, on a brand-new machine it won’t work.
- Path problems
- You are often advised to move libmysql.dll to your Windows\system32 directory. Some people accurately point out that this is not a good idea. But it does solve the problem, when you don’t understand that your path might be updated for your own user, but not for the user SYSTEM, running the Apache service. When you add the PHP directory to your path, you must restart your computer for your changes to affect the Apache service.
- Reboot your machine after you changed your path
- Apache will then be able to locate the required .dlls, without having to stick them in directories that are already in your path.
- Bonus: PHP startup errors in php.ini
- The default
php.inidoes not report startup errors, so it’s difficult at first to pinpoint the problem.
- In php.ini, set
display_startup_errors = On
- This will ensure that you actually get to see the famous
PHP startup: Unable to load dynamic library 'C:\...\PHP\ext\php_mysql.dll' - The specified module could not be found.It’s OK for development machines!
Pfiou, an hour wasted…