How-To: Setup IIS, MySQL and PHP on Windows
Posted on June 18th, 2007 in How-To, Windows Server |
When trying to setup a WIMP (Windows, IIS, MySQL, PHP) server, I was surprised at how difficult it was to find a simple walk through of the setup online. I figured I would take notes as I went along and post them here.
Please note, this is what I got working on a test server, and I’m sure it isn’t secure enough for a production environment. This is just the bare bones setup on how I got everything working together so I could test web apps like Moodle and Wordpress. I suggest you try this on a test machine, such as a Virtual Machine, so you don’t make a mistake and kill a working OS. If something breaks, it isn’t my fault.
I will assume that you have IIS installed and running on your machine. I used Server 2003 R2 with IIS 6 running in a Virtual Machine.
Install MySQL
This one is pretty easy, given that you need a basic setup. I just downloaded the installer for the latest Windows Essentials version of MySQL (I used 5.0.27) from their site. I ran the install, choosing the default settings. In the configuration portion of the setup, I set the root password, and included the bin directory in the Windows path.
After that, I installed the Graphical tools for MySQL, which you can also be downloaded from the website. While not required, these tools will allow you to setup databases and users in a GUI instead of the command line console.
Once that is installed you can move on to setting up PHP.
Install and configure PHP
I chose to go with the ISAPI configuration because most of my reading said it offered better security and speed when used with IIS. If that isn’t true, drop me a line and I will try to set it up the other way. I also hear that the cgi option may be more compatible with applications, but don’t know enough to state that as fact.
- Download and unzip the latest PHP to c:\php (or wherever you want it). I used 5.2.0 for this example.
- Change the name of php.ini-dist to php.ini.
- In php.ini uncomment:
extension=php_mysql.dll(remove the ; at the beginning of the line). This allows PHP to see mysql. You can add the lineextension=php_mysqli.dllto the list as well as some software will need it to work with PHP5. - Check and make sure that
libmysql.dllis in the php directory and thatphp_mysqli.dllis in the php\ext directory. - Add c:\php to the PATH in the windows environment variable and reboot. Only do this if you are comfortable editing this value and do not change any existing values in the PATH. To make the change, right-click on My Computer, choose Properties. Choose the Advanced tab and then Environment Variables. In the System Variables section, scroll down to PATH and click Edit. At the very end of the Value Variable line type:
;c:\phpNote the semicolon at the beginning. Do not modify anything else in that line, as it could seriously mess up the Windows installation. If your unzipped PHP to a different location modify the location above. When done, click OK, OK and OK again. Reboot.
- For PHP5 to work properly I had to create a registry entry so PHP would know where it’s config file was. I found this tip here.
The easiest way to do this is to create a file called inifilepath.reg as shown in step 2.6 on this page.
Save it. Then double-click it to install.
Configuring IIS to Work with PHP
- In IIS Manager, right-click Web Service Extensions and choose Add New Web Service Extension. The extension name can be anything you like (I chose PHP5-ISAPI). In the required files section click Add and browse to the php5isapi.dll file which is in the PHP directory. Once chosen, click OK and the check the box next to set extension status to Allowed and click OK.
- Right click on the site you want to enable PHP in and choose properties. Click on Home Directory tab, and Configuration under Application Settings. Click Add. Browse to the php5isapi.dll (in the php directory) and click Open. Name the extension php and click OK.
- Click on the Documents tab and add index.php to the list for default pages.
That should be it. To test to see if php is working create a page named test.php in the root folder of your website containing the following code:
Open a browser and go to that page. You should see something like the image below. If you do, PHP and IIS are working together.

If not, something went wrong. Try restarting IIS and try again. If that doesn’t work, go back through the steps and check your settings.
You should now be able to setup your database(s) and configure your PHP/MySQL site.
One Response
[...] I did a write-up on setting up a WIMP server, I figured I’d do the same for a WAMP (Windows, Apache, MySQL and PHP) server. In this how-to I [...]