I have been using a Windows computer for development since I first started building websites with Dreamweaver MX back in 2004. When I started using PHP, I needed a web server for testing, so I built up a WAMP server (Windows, Apache, MySQL, and PHP) on my development machine.
There are some good packages that will install all the WAMP components for you, and configure them to work together, but I like to know what’s going on under the hood, so I installed each component separately and configured them myself. Since LAMP is the standard for most production web servers, documentation for configuring a WAMP server is also somewhat scarce. So here is a set of instructions for setting up a WAMP server one component at a time, for people like me, who like to know how things work. It will include the following versions of the software in the stack.
- Windows 7 Enterprise
- Apache 2.4.3
- MySQL Community Server 5.5,28
- PHP 5.4.7
2013-09-30: There is now a 4 part series that includes more recent versions of the software, and more configuration options, like virtual hosts and SSL.
Windows
I am starting with a fresh install of Windows 7 Enterprise (using Windows Virtual PC), and UAC (User Account Control) left on. Other versions of Windows should be similar.
Apache
- Download the latest version of the Apache HTTP server (currently 2.4.3).
- The MSI installer is the easiest way to install Apache, but the latest version that the Apache site links to is 2.2.22, httpd-2.2.22-win32-x86-openssl-0.9.8t.msi, available at http://apache.skazkaforyou.com//httpd/binaries/win32/. Follow the prompts and it will ask you for the necessary information, and install itself as a service on your computer. Then skip to the testing section below.
- If you want the latest version, binary installers for version 2.4.3 (for both 32 bit and 64 bit computers), are available from http://www.apachelounge.com/download/. I will be using the 32 bit version, httpd-2.4.3-win32.zip.
- As noted on the Apache Lounge site, if you don’t already have it installed, you will need to install the Microsoft Visual C++ 2010 SP1 Redistributable Package (x86) from http://www.microsoft.com/en-ca/download/details.aspx?id=8328
- Download and open httpd-2.4.3-win32.zip and extract the contents of the Apache24 folder to your computer. I like to keep all programs inside my Program Files folder, so I created a folder at C:\Program Files\Apache\Apache 2.4 and extracted the files there (the use of spaces in folder names is just fine).
- Open Notepad (you may have to right click it and Run as administrator to be allowed to save the file) and open C:\Program Files\Apache\Apache 2.4\conf\httpd.conf.
- Change ServerRoot to “C:/Program Files/Apache/Apache 2.4” (note that it requires Unix style forward slashes, not Windows style back slashes between folders).
- Change ServerAdmin to your email address.
- Uncomment the ServerName line and change it to your website address.
- Change DocumentRoot to “C:/Program Files/Apache/Apache 2.4/htdocs”
- Change the relevant <Directory line to “C:/Program Files/Apache/Apache 2.4/htdocs”
- Change the ScriptAlias line to “C:/Program Files/Apache/Apache 2.4/htdocs/cgi-bin/”
- Change the relevant <Directory line to “C:/Program Files/Apache/Apache 2.4/htdocs/cgi-bin/”
- Save your changes.
- Open the command prompt, and change to the bin folder with the command CD C:\Program Files\Apache\Apache 2.4\bin
- Install Apache as a service with the command httpd.exe -k install. There should be no errors reported there. Also start Apache with the command httpd.exe.
- These instructions can be found in the ReadMe.txt file inside the .zip file, and more detailed instructions (including the command for uninstalling the service, httpd.exe -k uninstall) can be found at http://httpd.apache.org/docs/2.4/platform/windows.html
- Test Apache by opening a browser and browsing to localhost, or 127.0.0.1. If you get the following message, you have successfully installed Apache.
- One remaining item that is beneficial is to get the Apache Monitor to run on startup.
- In the Start menu, under All Programs, right click the Startup folder, and click Open (or Open all users).
- Right click the white space and select New, then Shortcut.
- Select ApacheMonitor.exe from the C:\Program Files\Apache\Apache 2.4\bin folder, and finish creating the shortcut.
- In the Start menu, find the new shortcut in the Startup folder and click it to start the Apache Monitor. Uncheck Always ask before opening this file, if necessary.
- This will show the Apache Monitor icon in the system tray so you can always see if the service is running, and it gives you the option to stop or restart it.
MySQL
- Download the installer for the latest version of the MySQL community server (currently 5.5.28) from http://www.mysql.com/downloads/installer/ and run it.
- From the Welcome screen, select Install MySQL Products.
- Walk through the next few steps, until you get to Choosing a Setup Type, where I will select Custom, and leave the Installation Path and Data path with their default locations.
- From the Feature Selection step, I will unselect MySQL for Excel 1.1.0, under Applications, and the Connector/NET 6.5.4, under MySQL Connectors. I will also unselect the Documentation, since I always use the online documentation. Basically, I like to install the Server, the Workbench, and the Notifier, although only the Server is required.
- Continue through the next steps, including the Installation step, until you get to the Configurationstep.
- Leave most of the defaults, except check Show Advanced Options, and click Next.
- Set a MySQL root password and click Next.
- Walk through the next few steps leaving the default settings, until you are finished the installation.
- To see if MySQL is running correctly, try out MySQL workbench to see if you can connect to your server with your root password, or just use the Notifier in the next step.
- From the Start menu, under All programs, open the MySQL folder, and the MySQL Notifier 1.0.3 folder, and run the MySQL Notifier 1.0.3 program. Like the Apache Monitor, it will show you if your MySQL service is running.
I would recommend also copying the shortcut to your Startup folder so that it is always available. - In addition to MySQL Workbench, I recommend HeidiSQL or PHPMyAdmin for managing MySQL data, but I won’t explain the installation of those tools here.
PHP
- Download the the latest version of PHP (currently 5.4.7) from http://windows.php.net/download/#php-5.4.
- Download the .zip file for VC9 x86 Thread Safe.
- Like Apache, I like to keep PHP inside my Program Files folder, and I like to have separate folders for different versions, so I can switch between them if necessary. Create a folder at C:\Program Files\PHP\5.4.7, and extract the contents of the php-5.4.7-Win32-VC9-x86.zip to this folder (although the install.txt file recommends against it, the use of spaces in folder names is just fine for this server configuration).
- This package doesn’t currently have a .dll file that is compatible with Apache 2.4, only 2.3 and older, so you will also need to download the php5apache2_4.dll-php-5.4-win32.zip file from http://www.apachelounge.com/download/.
- Open the .zip file, and in the PHP 5.4.7 folder find php5apache2_4.dll and extract it to C:\Program Files\PHP.
- From the Windows Control Panel, under System and Security, then System, choose Advanced system settings to open the System Properties window.
- Switch to the Advanced tab, and click the Environment Variables… button at the bottom.
- At the bottom of the Environment Variables window, in the System variables section, scroll down to find the Path variable, and click the Edit… button.
- In the Edit System Variable window, edit the Variable value field, adding two new items to the end, both the path to your PHP installation, and the path to the extensions folder of your PHP installation, separated by semicolons.
;C:\Program Files\PHP\5.4.7;C:\Program Files\PHP\5.4.7\ext- Click OK to close all these windows.
- Open Notepad (again, you may have to right click it and Run as administrator to be allowed to save the file) and open C:\Program Files\PHP\5.4.7\php.ini-production or C:\Program Files\PHP\5.4.7\php.ini-development (I will choose the production version) and Save As… php.ini in the same folder.
- Configure Apache to run PHP (these instructions are taken from the install.txt file in your PHP folder, under the following headings: Apache 2.0.x on Microsoft Windows, and Installing as an Apache module).
- Open Notepad (Run as administrator) and open C:\Program Files\Apache\Apache 2.4\conf\httpd.conf.
- Below the existing #LoadModule lines, add the following lines (again, note the Unix style forward slashes in the path):
LoadModule php5_module “C:/Program Files/PHP/5.4.7/php5apache2_4.dll”
AddType application/x-httpd-php .php
PHPIniDir “C:/Program Files/PHP/5.4.7” - Scroll down to the DirectoryIndex line (inside an <IfModule dir_module> block) and change it from DirectoryIndex index.html to DirectoryIndex index.html index.php. This will make sure index.php pages are served when directory requests are made.
- Save the file.
- With Notepad still open, create a new file with only one line:
<?php phpinfo(); ?>
Save this file as index.php in the C:\Program Files\Apache\Apache 2.4\htdocs folder. We will use this file to test the PHP installation. - Open the Apache Monitor from the system tray, and restart Apache.
- The status line at the bottom of the Apache Monitor window should now show PHP/5.4.7.
- Test PHP by opening a browser and browsing to localhost/index.php, or 127.0.0.1/index.php. If you get the following page, you have successfully installed PHP.
- Next we will enable MySQL support in PHP.
- Open Notepad (Run as administrator) and open C:\Program Files\PHP\5.4.7\php.ini.
- Scroll down to the Paths and Directories section (about a third of the way through the file), and uncomment the extension_dir line, so it looks like this:
extension_dir = “ext”
This will tell PHP where to look for extension files. - Next, scroll down to the the Dynamic Extensions section (about half way through the file), and uncomment the following two lines to enable the mysql extension, and the mysqli extension (mysqli is the recommended API to use when for connecting to a MySQL database, the i stands for improved). Delete the semicolon to uncomment the lines.
extension=php_mysql.dll
extension=php_mysqli.dll - Save the file, and restart Apache from the system tray.
- Open http://localhost/index.php in a browser again, and you should now see two sections that weren’t there before (about halfway through the page), a mysql section, and a mysqli section.
- Test your installation by editing your index.php file to something like this, using the “root” account, and the password you selected when installing MySQL:
<?php
$mysqli = new mysqli("localhost","root","password");
if($mysqli->connect_error)
{
die("Connect error (".$mysqli->connect_errno."): ".$mysqli->connect_error);
}
print("Success... ".$mysqli->host_info);
$mysqli->close();
?> - If you see the following page in your browser, you have successfully enabled MySQL support in PHP.
- Other recommended configuration changes
- There are a few other PHP extensions that are commonly used. To enable them, uncomment the following lines in the Dynamic Extensions section of the php.ini file.
- extension=php_curl.dll
This extension allows PHP to access other websites. - extension=php_gd2.dll
This extension allows PHP to edit images. - extension=php_exif.dll
This extension allows PHP to access EXIF data within images. - extension=php_zip.dll
This extension allows PHP to read and edit .zip files
- extension=php_curl.dll
- If you are running this on a development machine, scroll up to the Error handling and logging section, and change error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT to error_reporting = E_ALL, to show all errors.
- Change display_errors = Off to display_errors = On, and display_startup_errors = Off to display_startup_errors = On.
- Uncomment the error_log = syslog line so that PHP errors can be logged to the Windows Event Viewer (search for “Event Viewer” in the Start menu). Errors will appear under Windows Logs, Application.
- Lastly, scroll down to the File Uploads section, and change the upload_max_filesize = 2M to at least 8M, to allow larger file uploads.
- Save the file and restart Apache.
- There are a few other PHP extensions that are commonly used. To enable them, uncomment the following lines in the Dynamic Extensions section of the php.ini file.
Congratulations your WAMP web server is now ready to use.
Comments are closed