Web Design

Archived Posts from this Category

IIS, PHP, MySQL and Windows Server 2003

Posted by walsh_r on 16 Oct 2007 | Tagged as: Databases, Web Design

The creation of a database driven website is very simple in concept; add content to the database, and display the content on pages. The work going on behind the scenes to make this concept function, is not always so simple. There are numerous methods and products that can be used to accomplish different parts of this task, but getting them all to work nicely together can deliver headaches to anyone.

One popular combination often chosen by developers is the use of the PHP scripting language, and MySQL database. Both products are free, open source, cross platform, and have a large base of corporate and personal users.

Getting PHP and MySQL to work nicely with Windows Server 2003 and IIS can be troublesome, mostly due to the many different versions of PHP and MySQL, and the frequency that each product is updated (don’t get me wrong, free updates to products are great, once they are configured and working as expected). After experiencing some problems related to versions myself, I decided to write this tutorial on how to configure an operational MySQL database capable of interacting with PHP, IIS 6.0 on Windows Server 2003.

Required:

Background:

  1. IIS 6.0 previously installed on a Windows 2003 Server.

PHP Installation

  1. Create a folder on your root (C:) and name it PHP. (C:\PHP)
  2. Unzip the contents of the PHP 5.2.3 ZIP file to the PHP folder created in step 1.
  3. Open the IIS MMC snap-in.
    1. In the properties of the website you wish to use PHP with (most likely the default website), go to the Home Directory tab, and select Configuration.
    2. Under Application Configuration, check to see if .php is in the list. If it is, you will need to click edit and modify the Executable to C:\php\php5isapi.dll. If it is missing from the list, click add, and use C:\php\php5isapi.dll as the Executable and .php as the extension.
  4. Copy php.ini-recommended from C:\PHP to C:\Windows and rename to php.ini .
  5. Reboot.

To test the PHP installation, create a new file in notepad that contains the code below. Save the file as test.php in the root directory of your website.

<?PHP
phpinfo();
?>

Open a web browser from your web server and test http://127.0.0.1/test.php . If PHP is installed correctly, you will get a listing of the PHP configuration.

MySQL Installation

  1. Install MySQL 5.0
  2. Install the GUI tools for MySQL 5.0
  3. Run the MySQL Server Instance Config Wizard from the Start menu.
    1. Detailed Configuration
    2. Developer Machine
    3. Non-Transactional Database Only
    4. Decision Support (DSS)/OLAP
    5. Check Enable TCPIP Networking
    6. Port 3306
    7. Standard Character Set
    8. Install as a Windows Service
    9. Assign a root password (remember this password!!)

    *Remember the password that you assign to the root account! Document the password in a secure, reliable location.

  4. Launch the MySQL Administrator Program (the GUI tools installed earlier)
    1. Server host: localhost
    2. username: root
    3. password: use the password assigned above.
  5. If the tool connects and lists information about your MySQL server, then MySQL has been configured correctly.

To finish things off, we need to configure PHP to load some MySQL extensions. This will enable the web server, PHP, and MySQL to work together while server content to web pages from the MySQL database.

  1. Copy C:\PHP\libmysql.dll to C:\windows\system32\ .
  2. Open C:\Windows\PHP.ini in Notepad.
  3. Search the INI file for the following lines, and edit them to read as follows. If there is a semi-colon in front of the line, remove it.
    1. extension_dir=”c:\php\ext\”
    2. extension=php_mysql.dll
    3. extension=php_mysqli.dll
  4. Reboot.

To test the configuration, create a new file in notepad that contains the code below. Save the file as mysqltest.php in the root directory of your website. Edit the code to replace the root password with the one previously assigned.

<?PHP

//(”server name”,”username”,”password”)
$rst = @mysql_connect(”localhost”,”root”,”insert_password_here”);

if (!$rst){
echo( “<p>Unable to connect to database manager.</p>”);
die(’Could not connect: ‘ . mysql_error());
exit();
} else {
echo(”<p>Successfully Connected to MySQL Database Manager!</p>”);
}

if (! @mysql_select_db(”mysql”) ){
echo( “<p>Unable to connect database…</p>”);
exit();
} else {
echo(”<p>Successfully Connected to Database ‘MYSQL’!</p>”);
}
?>


Open a web browser from your web server and test http://127.0.0.1/mysqltest.php . If everything is configured correctly, your web browser will display Successfully Connected to MySQL Database Manager and Successfully Connected to Database ‘MYSQL’.

The Web Server is now ready to serve PHP web pages and communicate with a MySQL database.