How to WIMP – on Windows XP, that is (Updated)
Thursday 19 March 2009 - Filed under Tech Notes
Linux + Apache + MySQL + PHP, also known as LAMP, is probably the most cost-effective way of running big and small Internet applications, including this blog. I once mentioned I also have a “staging” blog, an exact replica of the live one, configured on my MacBook. Now that’s MAMP, i.e. Mac OS X instead of Linux. Setting that up was incredibly easy thanks to a free zero-configuration product called MAMP. Lately, I’ve been travelling with my Windows laptop a lot, and thought perhaps I could set up my staging blog on it, too, in which case it would be WAMP. After all, there’s no reason to have content tied up to a single physical machine if I can reliably back up, carry around, and restore it. One might call it Disaster Recovery 101. In this case, it means crossing over two different universes, namely, Mac and Windows. Nothing wrong with that.
From MAMP to WAMP to WIMP
Reflecting on the memories of MAMP and thinking there must be something as easy as that available on the Windows platform, I searched for the easiest way of configuring WAMP. I did stumble across WampServer, which I decided not to use after a 10-minute test-drive because it was not quite what I expected of a zero-configuration solution. As much as I would have liked to avoid it, manually configuring the individual pieces on top of Windows’ native IIS was the way to go. Besides, if I were to configure MySQL on Windows, I would prefer to have it not hardwired just for PHP but generically available to other types of non-Microsoft applications such as ColdFusion.
PHP: The installer that never works
Now, I hadn’t used PHP on Windows for years. Last time I ran the PHP installer on Windows was before PHP 5 earned the “generally available” status. The PHP 4 installer never did a clean job for me and I always ended up jumping through the hoops of manual configuration. Unfortunately, the PHP 5 installer did not change that and once again made me go through the headache of troubleshooting all kinds of seemingly random errors. So, here I am documenting a tried-and-tested account of how to configure PHP properly on Windows once and for all. This is, of course, in a development context and the components are Windows XP, IIS 5.1, PHP 5, and MySQL 5.1 (= WIMP).
The hoops of configuring PHP on Windows
Forget the installer. The goal here is to configure PHP and phpMyAdmin on top of IIS and MySQL. These are the steps, starting from scratch:
- Ensure that IIS 5.1 has been installed.
- Install MySQL. This is an atomic step because unlike PHP, the MySQL installer simply works. After the installation, configure the MySQL instance appropriately, i.e. at least change the root password.
- Download the PHP Windows binary package. This refers to .zip, not the .msi installer. Extract the contents to C:\php\.
- Add C:\php\ to the PATH environment variable.
- In C:\php\, make a copy of php.ini-recommended and name it php.ini.
- Move php.ini to C:\Windows\. Don’t copy it. Move it.
- Open php.ini in a text editor and change the value of cgi.force_redirect to 0. If the line has been commented out, uncomment it.
- Uncomment extension=php_mysql.dll in php.ini.
- Uncomment extension=php_mcrypt.dll in php.ini.
- Uncomment extension=php_mbstring.dll in php.ini.
- Still in php.ini, set the value of extension_dir to “C:\php\ext” (including the quotes). Save and close the file.
- Open IIS Manager.
- In Default Web Site Properties > Home DIrectory > Configuration, add a new mapping to C:\php\php-cgi.exe and set its extension to .php (including the dot).
- In Default Web Site Properties > Documents, add index.php.
-
Using a text editor, create a script called phpinfo.php in C:\inetpub\wwwroot. Open it and type:
<?php echo phpinfo(); ?>
Save and close it.
- Restart IIS.
- From a browser window, navigate to http://localhost/phpinfo.php. Verify that the page loads with PHP configuration information. Ensure that the location of the configuration file is set to C:\Windows and the Server API set to CGI/FastCGI. Also ensure that there is a section on the mysql extension.
- Download and extract phpMyAdmin to a folder, preferably somewhere in C:. In IIS Manager, create a virtual directory called pma under the Default Web Site pointing to the phpMyAdmin folder.
-
From Windows Explorer, navigate to the phpMyAdmin folder and make a copy of the config.sample.inc.php file. Name it config.inc.php. Open it with a text editor and make sure these lines are included:
$cfg['blowfish_secret'] = ‘SOME_SECRET’; // Anything other than an empty string
$cfg['Servers'][$i]['host'] = ’127.0.0.1′;
$cfg['Servers'][$i]['connect_type'] = ‘tcp’;
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['extension'] = ‘mysql’; - Still in config.inc.php, comment out all other lines starting with $cfg['Servers'].
- Restart the computer. This is a must.
- Open a browser window, load http://localhost/pma and authenticate into MySQL.
Miscellaneous tips
- Check NTFS permissions. The Internet guest account (IUSR) needs read-and-execute on all virtual directories, C:\php\, C:\php\ext\, and C:\Windows\php.ini.
- If you want an address that is sexier than “localhost”, edit the hosts file buried under C:\Windows and add an entry pointing to 127.0.0.1. This may be a necessary step if you are transferring a WordPress blog and if it was previously known as something other than localhost.
- Configuring PHP on Windows Server 2003 should be very similar to this. The notable additional step is to register and enable the PHP Web service extension alongside ASP.NET in IIS Manager.
Separation of content and platform
This one-off setup can be confusing and painful especially if you haven’t done it before. It works, nevertheless. After a simple database export/import and some minor fine-tuning, I now have my staging WordPress blog on Windows. Taking the content back to the Mac is just another database export/import in phpMyAdmin. That’s the way it should be.
Update: I prefer to register PHP as a CGI as opposed to an ISAPI filter in IIS. ISAPI is known to perform better than CGI but it’s less stable and tends to cause the mysterious “inetinfo.exe” error and the dreaded “access violation” error.
2009-03-19 » JK