How to enable mySQL in PHP5 on Windows

Apache+mySQL+PHP is for sure among the best and the most popular combinations of web-development products; but sometimes a proper setup is a tricky bit.

Among the things that need a lot of messing around is how to enable mySQL under PHP5. While mySQL is in PHP4 implicitly(?) enabled, under PHP5 you have to do all this:

After installing Apache 2.0/2.2, PHP5, and mySQL (e.g. by installing XAMPP), copy php5apache2.dll or php5apache2_2.dll (depending on your Apache version) to modules directory of Apache.

Then, add the following 2 lines to httpd.conf (typically in <Apache_dir>/ conf/ httpd.conf):

LoadModule php5_module modules/php5apache2[_2].dll
AddType application/x-httpd-php .php

This will enable PHP5 to work properly in Apache 2.

To enable mySQL for use in PHP5, you have to do the following:

  1. [not sure if this is really necessary –] Make sure you have valid php.ini file in <Apache_dir>.
  2. Copy libmysql.dll to the system32 directory (in Windows installation directory). (php_mysql.dll won’t load without doing this!)
  3. Set the extension_dir in php.ini to the ext directory of your PHP installation directory – typically “extension_dir = <PHP_installation_dir>\ ext”.
  4. Enable the mySQL extension in php.ini by un-commenting the line “extension = php_mysql.dll”.
  5. Restart Apache Server.

That’s all… enjoy! πŸ™‚

14 responses to “How to enable mySQL in PHP5 on Windows

  1. Pingback: MySQL is no longer enabled by default -

  2. 1) I have below in php.ini

    extension_dir = “c:/php5/ext”
    extension = php_mysql.dll

    2) Copy php.ini to apache’s conf dir which has httpd.conf

    3) copy libmysql.dll to the system32 directory

    4) restarted apache

    though, i still got the below error. Where php.ini should I copy to?

    Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\order.php on line 14

    Thanks so much for ur help!


  3. You can’t imagine how much unnecessary file transfer you just prevented! πŸ™‚

    Thank you so much – I can now freely develop on my local machine instead of a dev server! I had been exploring all sorts of possibilities as to why I was unable to reach a remote MySQL server from my local WAMP setup – Windows firewall blocking outgoing connections, the MySQL server net-blocking my ip, what not!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s