If you’re like me, you prefer installing Apache and PHP on your own without the use of WAMPServer. The goal is to setup the latest Apache server with PHP 5 and PHP 4 using FastCGI.
If you’re like me, you prefer installing Apache and PHP on your own without the use of WAMPServer. Typically I install PHP as an Apache module, but this time I wanted to try using FastCGI and get acquainted with the setup. I’ve just finished setting up my laptop as an extra dev machine and have been using it with no issues.
The goal is to setup the latest Apache server (2.2.17 as of this writing) with PHP 5 and 4 (5.3.3 and 4.4.9) using FastCGI (2.3.6). I will be making the assumption that you’re pretty familiar with computers and perhaps have done this once or twice before.
Getting It All Installed
- Installing Apache is pretty straight forward, I am using the MSI installer and the wizard pretty much guides you through the installation. I generally install Apache at “C:/bin/apache”.
The PHP 5 installation is also pretty straight forward, I like to use the MSI installer to make things go a little quicker and I like being able to select/deselect the extensions I want activated.
During the wizard setup you will be prompted select a web server setup, select “Other CGI” (if Apache is currently running, stop the service so the installer can properly access the httpd.conf file). I generally install PHP at “C:/bin/php”.
- If you want to install PHP 4, simply get the latest ZIP release (4.4.9 as of this writing), unzip it and set it up at “C:/bin/php-4.4.9″.
- Open up the FastCGI ZIP package, you will need to place the “manual” and “modules” folders in “C:/bin/apache”.
Open up “C:/bin/apache/conf/httpd.conf” and do the following:
- Find the default
<Directory>block, find the
Optionsdirective and add
- Find the
DirectoryIndexdirective and add
- Find the
#Include conf/extra/httpd-vhosts.confand uncomment the line
At the bottom of your httpd.conf file add the following, my PHP installation is at “C:/bin/php” (if yours is different you may need to make adjustments):
LoadModule fcgid_module modules/mod_fcgid.so FcgidInitialEnv PHPRC "c:/bin/php" AddHandler fcgid-script .php FcgidWrapper "c:/bin/php/php-cgi.exe" .php
Important: If you install PHP in “Program Files” or any directory containing a SPACE in the name, you will need to use an 8-char DOS directory name.
This won’t work:
FcgidWrapper “C:/program files (x86)/php/php-cgi.exe” .php
But this will:
FcgidWrapper “C:/progra~2/php/php-cgi.exe” .php
If you are having problems restarting the apache service, I find that a computer reboot helps.
Virtual Hosts Setup, With PHP 4
I am going to show you the way I setup virtual hosts on my system. I use the “httpd-vhosts.conf” file to define the vhosts that I need. I typically assign a project to its own dedicated virtual host.
I also use the system “hosts” file to assign custom domain names to each vhost. I use “.dev” as the TLD for all my vhosts (you’ll see what I mean shortly).
First off lets setup the vhosts, here is my “httpd-vhosts.conf” file:
NameVirtualHost *:80 <Directory "C:/bin/apache/projects"> Options FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> <VirtualHost *:80> ServerName farinspace.dev ServerAlias *.farinspace.dev DocumentRoot "C:/bin/apache/projects/dimas/farinspace" </VirtualHost> <VirtualHost *:80> ServerName wpalchemy.dev ServerAlias *.wpalchemy.dev DocumentRoot "C:/bin/apache/projects/dimas/wpalchemy" FcgidInitialEnv PHPRC "C:/bin/php-4.4.9" FcgidWrapper "C:/bin/php-4.4.9/php.exe" .php </VirtualHost>
So lets talk about the file … you’ll notice that I setup a “projects” folder at “C:/bin/apache/projects”. Each of my projects are then subdivided in this folder, see “farinspace” and “wpalchemy”.
Also notice the
ServerAlias directives, when I type “http://farinspace.dev” or “http://wpalchemy.dev” in my browser I am able to access each vhost by name (remember, before you can do this you will still need to setup your “hosts” file, see below).
The second vhost above uses PHP 4 (you can setup a vhost with any version of PHP that you need). The two directives that you need to use are
FcgidWrapper, you will have to make adjustments depending on the version and location of your PHP installation.
Here is my “hosts” file:
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 126.96.36.199 rhino.acme.com # source server # 188.8.131.52 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 farinspace.dev 127.0.0.1 www.farinspace.com 127.0.0.1 assets.farinspace.dev 127.0.0.1 wpalchemy.dev 127.0.0.1 www.wpalchemy.dev
As you add more Apache vhosts, simply modify your “hosts” file with new names (you will likely need administrator rights to edit this file, run your editor as administrator).
At this point you will need to restart Apache and create yourself a “phpinfo.php” file to test your installation.