Installing PHP and Mapserver on Windows/IIS

Most of you have figured out by now the PC is an open source proponent. I’m not a blind zealot, however, and here’s a valid criticism of the genre - installing open source software can be a real drag.

For one thing, many open source packages live on top of other open source packages, so to get one thing working you have to install a bunch of other things. Don’t expect any of them to have nice setup.exe files so Windows users can double-click a file, click “I Agree” and “Next” a few dozen times, and then (hopefully) yell “Yipee!” at the end. You’re usually downloading zip files with obscure readme.txt’s directing you to move and do and touch all kinds of things to get it working. If you’re a Linux user you’re probably used to that (if I had a dollar for every make and make install I’ve typed in the last six months…), but it tends to freak Windows users right out. Not to mention support for Windows users on some projects is a bit iffy - many open source developers have gone the Linux route and instructions for Windows users are often an afterthought.

To help you along, this tutorial will take you through the very easy steps to install PHP and Mapserver (PHP-Mapscript) on Windows and IIS. I will presume you either have or know how to get IIS running on your Windows machine (hint - Control Panel -> Add/Remove Programs). I’ve packaged the components for you to make things as easy as possible. Right now the package is the most recent release (PHP 5.1.2 and Mapserver 4.8.1), and I’ll try to keep these files up to date in the future. Enough chit-chat, let’s get started.

The first thing we’ll do is copy some folders to your machine. This zip file has PHP with its configuration file (php.ini) set up with some useful options and the Mapscript dll copied to its extensions folder. Download the zip file and extract the PHP folder to C:\ (i.e. C:\PHP).

Then copy some binaries Mapserver needs from other open source projects. Download this zip file and copy the folder to C:\ (i.e. C:\mapserver_binaries). Mapserver also needs files from another project to handle projections. Download this zip file and move the folder to C:\ (i.e. C:\proj).

Copying three folders - not so bad to start with, huh? Next, we’re going to add a couple of pointers to these folders to your PATH variable. Right click on My Computer and go to Properties. Go to the Advanced tab and click on Environmental Variables. In the System Variables, highlight the Path variable and hit Edit. Add this to the end of the line: “;C:\PHP;C:\mapserver_binaries” (minus the quotes). We’re telling windows to look in those folders when searching for executables.

Finally, we have to tell IIS what to do with PHP files. Go to Control Panel -> Administrative Tools and click on Internet Information Services. Navigate to Default Web Site (unless you’re using something else), right click on it and choose Properties. Click on the Home Directory tab, and then click on Configuration. Click Add. For the Executable, put in “C:\PHP\php-cgi.exe”, and for the extension type “.php” (all minus the quotes). Confirm the All Verbs, Script Engine, and Check That File Exists options are all selected, and keep hitting OK until you are out of the configuration dialogs.

That’s it. You’ll need to reboot your machine for Mapserver to be happy (forcing Windows to re-read the Path variable), and then you’ll be able to write PHP applications and use Mapserver to develop web mapping applications!

To confirm things are working, create a new PHP file in a web folder (such as C:\Inetpub\wwwroot\test.php), and put this code into the file:


This function will give you a report of PHP settings and the installed modules. You should be able to find a section for MapScript. That let’s you know all is well!

There are a lot of different configurations settings for these software packages, and this certainly isn’t the only way it can bet set up. You can run Mapserver as straight CGI or use Mapscript with other languages like Python and Java, and PHP has a miriad of modules and extensions you can use. Check out the PHP and MapServer home pages for more details on options if desired.

In another article I’ll show you what you can do with your new web map server. In frightenly few lines of code, we’ll make a web mapping page with pan and zoom capabilities!