How To Install MySQL and PHP on IIS 6.0
If you are happy with the choices you have made click Execute to begin configuring your server.
Once the Configuration Wizard has finished click Finish to begin using your new MySQL server.
Now that we have got MySQL installed we need to create a test user account which we will use later in this walkthrough to test connectivity to MySQL from a PHP script. Start by opening the MySQL Command Line Client. When prompted enter your root password and hit enter.
Type the following SQL command and hit enter :
CREATE USER ‘phptest’@'localhost’ IDENTIFIED BY ‘phptest’;
Then type this SQL command and hit enter :
FLUSH PRIVILEGES;
Now type this SQL command and hit enter :
SELECT Host, User, Password FROM mysql.user;
As you can see we have now created a new MySQL user account called ‘phptest’ with a password of ‘phptest’. This user account can log in to MySQL but has not been granted any permissions on any of the existing schema or databases.
Configure PHP for MySQL Connectivity
Now that we have got both PHP and MySQL installed on the server we can move on to the job of getting PHP connected to MySQL.
The first thing we need to do is enable the MySQL extensions for PHP to use. To do this locate the Dynamic Extensions section of your ‘php.ini’ file and either uncomment or add the following lines to the top of the existing list of extensions :
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
You may find that the line referencing php_mysqli.dll is not in your php.ini file - if not you will need to add it to the list. Once you have done this save the changes in the ‘php.ini’file and then either recycle your PHP web site’s application pool or perform an IISReset for the changes to take effect. If you now browse the http://localhost/index.php file we created in the first article you should see that support for MySQL is now enabled.
We are now ready to go ahead with a simple test script to ensure everything is setup correctly. Start by creating a new text file in Notepad in the root of your PHP test web site and then type in the code shown here :
Alternatively, you can download the file from here :
http://www.iisadmin.co.uk/images/phpmysql/dbtest.zip
Save the file as dbtest.php and then browse to http://localhost/dbtest.php on your server. You should see the error message shown below.
This indicates two things. First, that we have successfully connected to MySQL from our test PHP script and second, that the user account we specified in our connection string does not have sufficient privileges to access the ‘mysql’ system database.
So you should now have a working installation of PHP and MySQL running on your IIS 6.0 server. In the final article in this series I will demonstrate how to install WordPress on an IIS 6.0 web server.