Apache and php on Windows 7 64-bit

Just because there are Windows .msi installers for versions of software you don’t really need or want doesn’t mean you have to use them. How I installed and configured Apache 2.2 and php 5.3 on Windows 7, below.

Both the Apache HTTPD and php projects don’t officially support 64-bit builds of their software for Windows, so the only sources are 3rd parties who may or may not be as attentive to the infinite details that can ruin your day.

Maybe I got lucky this time.

Note that the zip distributions of these applications were used in my installations1.

First, where I got the software:

1. Apache 2.2.23 for Windows x86_64

This is from the Apache Lounge community site. It is a zip distribution containing 64-bit versions of the binaries. Out of the box it is configured to live in c:apache2, but you can locate it anywhere you want and just do a search and replace for that path (I put mine in C:appsapacheapache2).

2. php 5.3.13 for Windows x86_64

This is from a solo build program by Anindya.

I unzipped the distro to c:php and put both c:php and c:phpext in the global system PATH.

Now to the installation:

The instructions found Installing PHP 5.3 and Apache HTTP Server on Windows 7 are very good and got me started on the right foot, although it assumes the 32-bit versions are good enough and missed a couple of points.

Here are my configurations, in no special order.

1. Add the following to the Apache httpd.conf just under the last LoadModule statement:

LoadModule php5_module "c:/php/php5apache2_2.dll"

	AddType application/x-httpd-php .php
	PHPIniDir c:/php/
	DirectoryIndex index.php index.html

When installing httpd as a service be sure to open the command prompt by right-clicking and selecting “Run as Administrator”. Then execute the following command where httpd is located:

C:/AppsApacheapache2bin>httpd -k install

Start and stop the server using the Windows service manager tool.

2. Copy php.ini-development to php.ini and uncomment/modify the following lines so they wind up looking like this:

include_path = ".;c:phpincludes"
extension_dir = "ext"
date.timezone = America/New_York # YOUR time zone

The module for curl is broken in the base distro, but a replacement is available here for those who need it (remember to uncomment the relevant extension line and restart the web server).

1There are .msi installers available for both Apache and php on Windows, but I wasn’t able to get them to work together. All packages defaulted to installing in the “c:\program files”, or “c:\program files(x86)”, heirarchy and ran afoul of Windows 7’s draconian security policies restricting changes to files stored there. Even when installing to custom paths, multiple errors while trying to load the php5_module into Apache also indicated some fundamental incompatibility even between distros from the same packager. As a result I finally decided to go ahead and try the zip distributions. Lesson learned: statically linked binaries for ports of Unix software to Windows are usually more reliable than installer-based dynamically linked ones (I have also found this to be true of ports of Windows software to Unix — for example, Skype on Linux).