Running Apache, PHP and MySQL on Windows.
Here at home, I run a local apache install to make building and testing my web projects easier. Instead of having to constantly upload files to my web host, I can save them locally and refresh my browser to see the result. It’s easier, and because I run my local server off of my laptop, it provides the added bonus of allowing me to work on projects while I’m out of the house, on a plane, or otherwise don’t have Internet access.
There seems to be a lot of confusion about getting Apache and PHP up and running in a Windows environment, and a lot of people give up and use bundled packages like WAMP or XAMPP. These are fine choices, but I like to do things myself, and install just the components I need or want. I also think it’s important to have a good understanding of Apache and PHP configurations, as they can come in handy when you’re trying to debug your application after it’s gone live on a web host.
So, here’s a quick step-by-step on getting Apache, PHP and MySQL up and running in Windows 2000 or better. While this page may seem long, getting an Apache environment up and running is actually very simple. I go in to detail to make sure you don’t get lost; just follow my instructions line by line and you’ll be up and running in minutes. Begin by downloading the various software you’ll need:
- Grab the latest version of Apache 2.0.*, but not Apache 2.2. Apache 2.2 has a lot of incompatibilities still, and it’s much more of a headache than it’s worth at this point.
- Download the latest ZIP version of PHP4 (right now it’s 4.4.7.) I still develop with PHP4 since most web hosts haven’t upgraded to PHP5, and I like to ensure my apps are broadly compatible. PHP4 support will be discontinued on December 31st, 2007, so by then most web hosts will likely have updated their environments to run PHP5.
- Download whichever version of MySQL you’d like, version 4 or newer. I run MySQL v5 as most web hosts have already made the upgrade.
Now that you’ve got all your files downloaded and ready, it’s time to install. Before you begin, create a directory at C:\WWW on your hard drive. This will be your document root- where you’ll store all your web pages.
Installing MySQL
Setup should be fairly self-explanatory. When the configuration process begins, chose Detail Configuration.
- Choose “Developer Machine”.
- Choose “Multifunctional Database”.
- Leave the InnoDB Tablespace Settings as-is.
- Choose Decision Support (DDS)/OLAP.
- Enable TCP/IP Networking on port 3306.
- Choose “Best Support for Multilingualism”.
- Install as Windows service and “Include Bin Directory in Windows PATH” (very important)
- Give your new root account a password. For this walkthrough, I’ll use “1234″.
- Continue to save your configuration, and Finish to close.
Now go to Start, Run and enter “cmd”. Type “mysql -u root -p” and hit Enter. You’ll be asked for your password, type it in and press enter again. You’ll now be at a prompt starting with ‘mysql >’. Enter this command: (If your password isn’t 1234, enter the appropriate password in it’s place.)
SET PASSWORD FOR 'root'@'localhost' = OLD_PASSWORD('1234')
MySQL is now setup! Let’s move on to PHP.
Installing PHP4
Note: These instructions are only for PHP4. PHP5 is different. See the PHP5 installation instructions for information on that.
- Move the files in your PHP zip file to C:\PHP. Your files should be directly in C:\PHP, not in C:\PHP\php-4.4.7-Win32. For example, php.exe should be at C:\PHP\php.exe.
- Move all the files inside C:\PHP\dlls and C:\PHP\sapi into C:\PHP. You can now delete the dlls and sapi directories, if you like.
- Rename “php.ini-recommended” to “php.ini”.
- Open “php.ini” in Notepad.
- Search for a line that says “display_errors = Off”. Change this to “display_errors = On”.
- A few lines down you’ll see “display_startup_errors = Off”. Also change this to On.
- Further down, find extension_dir = “./” Change this line to extension_dir = “C:\PHP\extensions\”.
- A bit further down you’ll find a series of lines beginning with “extension=”. At the end of this list, add the following lines:
extension=php_gd2.dll
extension=php_mbstring.dll
Save the file, and close it.
This next step is a bit sensitive, so please follow these instructions carefully. Go to Start, and right click My Computer. Go to the Advanced tab and hit the “Environment Variables” button near the bottom of that window. A new dialog will appear with two scroll boxes. On the bottom scroll box, find a line beginning with “Path”. Double click this line. Another window will appear, with two text boxes. On the bottom text box there will likely be a very long string of text. You don’t want to delete the text that is there, as some of your applications rely on this information. Instead, press End to go to the end of that line of text, and add this:
;C:PHP
Press OK to get out of the Path window, OK again to leave the Environment Variables dialog, and OK once more to get out of System Properties. PHP4 is now ready!
Installing Apache
I highly recommend closing out all your instant messengers and other applications before starting to install Apache, as some tend to run on port 80; the same port Apache does. This can conflict with the Apache installation.
Run the Apache installer, and continue until you’re asked for Server Information. For “Network Domain” and “Server Name”, enter “localhost”. Enter your email address for “Administrator’s Email Address”, and leave the default service options. Use the Typical install option, and install to the default directory. Once install is complete, press Finish to leave setup.
Open C:\program files\Apache Group\Apache2\conf\httpd.conf in Notepad.
- Search for the line “#LoadModule rewrite_module modules/mod_rewrite.so” and remove the # before it. This will enable the Rewrite module which used in many web apps, including WordPress (for fancy urls.)
- At the end of the series of LoadModule lines, add these lines:
LoadModule php4_module “C:/PHP/php4apache2.dll”
AddType application/x-httpd-php .php
PHPIniDir “C:/PHP” - Further down, find the line DocumentRoot “C:/Program Files/Apache Group/Apache2/htdocs”. Change this to DocumentRoot “C:/WWW”.
- A few lines down, find the line directory “C:/Program Files/Apache Group/Apache2/htdocs”. Change this to directory “C:/WWW”.
- Just a few lines down you’ll find “AllowOverride None“. Change this to “AllowOverride All“.
- Finally, look for a line beginning with “DirectoryIndex“. Change this line to read “DirectoryIndex index.php index.html“.
Using the Apache Monitor in your system tray, left click it and restart the service. If there’s any problems, a message will pop up. Otherwise, everything has gone as planned, and you now have a working Apache environment.
Testing Your Setup
To quickly test your new setup, create a index.php file in your C:\WWW folder. Open this file in Notepad, and enter:
< ? phpinfo(); ?>
Load http://localhost/ in your web browser, and you should be presented with PHP’s information screen. You’re environment is setup and ready to go!
I am currently available for contract work! I have over a decade of experience in building appealing, standards-based web designs and applications. Check out
RSS Feed
Email Updates
Add New Comment
Viewing 2 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)