Install MySQL Server 5.0 in IIS 5.1 and PHP 5.3


Yay! We're already done setting up PHP 5.3 to IIS 5.1, now this guide is for Installing MySQL Server 5.0 in  IIS 5.1 and PHP 5.3. I'm assuming you have IIS 5.1 already installed in your system and if you still need to setup PHP 5.3 then please check the Installing PHP 5.3 in IIS 5.1 guide. Now for installing MySQL Server 5.1 you will need to download latest stable release version here: http://dev.mysql.com/downloads/mysql/5.1.html. In this tutorial I am going to be using the Windows Essentials (x86) version which has all the core functionality you need to run a MySQL database server. Launch the mysql-essential-5.0.26-win32.msi installer file to start the MySQL Setup Wizard.


Click Next and then choose a custom installation as this will allow us to specify an installation directory of our own choosing. In this example I will be using installing MySQL into the "C:\MySQL" folder.

 

 On the Custom setup dialog box click Change to specify the preferred installation directory.

 


 Select the directory you want to use and then click OK to go back to the Custom setup dialog box.

 

Click next. MySQL is now ready to be installed. Click Install to begin the installation.



At the MySQL.com Sign Up screen click Skip Sign-Up and then click Next.


On the next dialog box ensure that ‘Configure the MySQL Server now’ tick box is checked and click Finish, then this will open the Server Instance Configuration Wizard. Click Next to begin configuring your MySQL server.



Choose Detailed Configuration and click Next.

 

In this example I am installing MySQL on the same machine as my IIS web server so I opt for the Server Machine option. Choose a server type which is appropriate for your requirements and click Next.

 

Choose the type of database which best suits your needs and click Next.

 

Leave the default setting of the MySQL installation path for the InnoDB Tablespace settings (unless you wish to change it) and click Next.


Select the appropriate number of concurrent connections you want to allow and click Next.


Leave the default networking options settings (unless you have reason to change them) and click Next.

 

Choose the appropriate character set for your requirements and click Next.

 

On the Windows options dialog box ensure that both ‘Install As Windows Service’ and ‘Include Bin Directory in Windows Path’ tick boxes are selected and click Next.


In the security options dialog box ensure that ‘Modify Security Settings’ is ticked and type in your new root password. Decide whether or not you wish to allow root access from remote machines or create an anonymous account and click Next.
 

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 codes and save it as 'dbtest.php'.
<?php
// Establish a connection and select a database
$link = mysql_connect('localhost', 'phptest', 'phptest') or die('Could not connect to the MySQL Server: ' . mysql_error());
mysql_select_db('mysql') or die('Could not Select the Database.<br><br>The error returned by MySQL was: <br>' . mysql_error());
// Close the connection
mysql_close($link);
?>
Browse to http://localhost/dbtest.php on your server. You should see the error message shown below.

 

his 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 5.1 server. In the final article in this series I will demonstrate how to install phpMyAdmin in IIS 5.1 and PHP 5.3. Thanks again for sticking around! If you have any comments, questions about the installation and suggestions please feel free to post here.

No comments:

Post a Comment