DJ Quilter

Front-End Developer

Setting Up A PHP Site On IIS

If I was going to set up a PHP site locally, I’d generally use WAMP. It’s a quick install, it’s easy to use and I’m familiar with it. However I’ve recently been prevented from doing this on a couple of occasions because I’ve also needed to use IIS to run sites locally.

The issue has to do with the two using the same port; I won’t pretend to know a great deal about the technicalities here. The long and that short of it is that, having trawled Stack Overflow for hours (and come up short with every ‘solution’), I came to the conclusion that IIS and WAMP just don’t work together.

The Solution

You can however, run PHP on IIS, although, as is often the case with these situations, there’s no one resource that tells you everything that you need. I’ve tried to bring together all of the articles that I found useful, so that the following instructions are that one resource:

Install PHP

Install PHP Manager for IIS

Of the two links above, the first installs a version of PHP on your machine (be sure to note the location that it’s installed, as you’ll need it for later). The second installs PHP Manager for IIS. The instructions in the second link are very good, the only thing they don’t explain is that for PHP to run, you’ll need Fast CGI enabled, which you can find out how to do here:

Install Fast CGI

Once you’ve done all that, you’ll need to restart IIS. You should then be able to set up your site normally (host file etc), and you’ll be away!

WordPress

If you’re setting up a WordPress site (and I have been when I’ve needed to do this), you will probably also need to install the URL Rewrite Module for IIS, otherwise you won’t be able to get to any internal pages:

IIS’ URL Rewrite Module for IIS

When the module is installed, go to your site in IIS, and click on the ‘URL Rewrite’ option in the centre panel and then the ‘Import Rules’ button in the right-hand column on the subsequent page. Then import your .htaccess file. Assuming it’s the standard .htaccess file (and you’re not doing anything too crazy), you should just need to delete the following IF statement (but not the contents of the statement) as IIS won’t recognise it:

<IfModule mod_rewrite.c>
...
</IfModule>

You should then have something like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

When IIS gives you the thumbs-up click on the ‘Apply’ button in the right-hand column, and you should be done with this bit.

MySQL on IIS

If you’re after WordPress, you probably need a database too. Yet again, you can set this up on IIS. It’s pretty scary, but (probably) not as bad as it sounds.

If you don’t already have it installed, you’ll need to get .Net 4.0:

Install .Net 4.0

Once that’s done, you can install MySQL:

Get the install file for MySQL

Step-by-step instructions for the install

The final thing you’ll need to do is set up PHPMyAdmin. I followed the below instructions up to step 3; after that it gets pretty dense, but I didn’t seem to need to do it to get everything working. Having said that, I would possibly have a quick look at steps 8 and 9, as they seem like they might be fairly important if the settings aren’t already there for you.

Install PHPMyAdmin

And if you want to go to PHPMyAdmin, you’ll probably find it here:

http://localhost/phpmyadmin/

But if you’ve gotten this far, you’ve probably already worked that out.

Disclaimer

I don’t pretend to be more than a humble front-ender, and as such, the above instructions are intended for someone with about as much knowledge (and bravery) as me to get a site working locally. If you need more than that, and you might be best of finding someone who knows how this stuff all works.