Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

jobs.webdeveloper.com

e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Install A Custom Apache, PHP, MySQL WebServer on Windows XP, Vista, 2007

Bookmark and Share

by Marc Plotz

October 22, 2009

Setting up a custom Web server on your development computer not only means you have complete control of your development environment, but also that you are able to emulate a production server as closely as possible. Read on to learn how.

Introduction

Surprisingly many developers I come across in my daily work do not run a local server. This always amuses me, mostly because if you took my local server off my laptop I would probably go into death throws fairly soon thereafter. Maybe it is just the way I have come to code over the past few years, or maybe it is relying too much on something familiar. Whatever it is, I like it and I refuse to let it go.

But why would you want a local server on your laptop or home PC? Quite simply, what better way is there to test your work? Let me quickly explain how I work on a project and I'll shorten the story quite a bit for the sake of interest. I have a subversion repository where I keep my libraries, projects, etc. Assuming I have tagged a certain project to be built on a certain library, I would check that library out of the SVN, disconnect, and then re-commit that library as a new project. Using Zend Studio 7 (or Aptana, or any implementation of Eclipse, they all work more or less the same) I then have a project on my localhost (my laptop server) connected to a repository on our local office server. As I develop, I commit the changes to the SVN, making it possible to roll back should it be necessary. Then, one day when the project is ready to go live, I simply sync to the live server via Zend Studio and upload the project. Then, should changes, bugfixes or anything else be required, I have an exact copy of my site on my laptop-- which is ALWAYS WITH ME. All I need to do is complete and test the changes on my local server and when I am sure it is working I simply upload it via Sync Connection and Zend, and it is done.

Most of you will not require all this commotion, though. What will be handy is your own localhost setup. Again mine is different (are you surprised yet?). I have only operating system stuff in my C: drive. My localhost is on my D: drive, which is a 50 gig partition I created when setting up the laptop. There is nothing more annoying than having to sift through realms of folders in the C: directory when there is work to get done. That is why my localhost sits on the D: drive, all alone, ready for action. Today we are going to do the same setup, altough you could put it on any drive you like--just change the paths accordingly.

A word to the wise: Once the downloading is done, the setup takes a good few minutes to complete. Please make sure you do have time on hand and are ready to follow each step precisely, or this will not work. Missing just one step WILL break either Apache, PHP or MySQL, or all of them, be warned.

Step 1: Getting The Files

We are going to need Apache, PHP and MySQL. These are all free, open-source development programs, so all its going to cost you is the download bandwidth.

For our actual Web server we are going to use Apache_2.2.11-win32-x86-no_ssl. You can download that HERE.

The PHP version we are going to use is the PHP 5.2.9 zip package - no installer. Download that HERE. Once we have this installed the upgrade to PHP 5.3 is rather simple. We will cover that another time though.

For database support we are going to be installing MySQL essential 5.1.31. Get this HERE.

Now let us get down to it.

Directory Structure

I am going to be talking about creating this server in my D: drive, which is a primary partition. You can do it on any drive you like, simply interchange the drive letters in the examples that I supply.

So I begin by creating a drive called server in my D: drive. Inside server, I create a folder called www and inside www I create a folder called public. It doesnt really matter what you call these folders, as long you remember what you have been doing and name them correctly all the way down the line. The public folder is going to be the folder that your websites will reside in.

Step Two: Install Apache

Double click on the Apache Installer that you downloaded. A window will pop up. Insert the following information:

Network Domain (eg somenet.com):  server

Server Name (eg www.somenet.com): www.server
Administrator's Email Address (eg: webmaster@somenet.com): admin@server.com

Click Next, you will be asked what type of server setup you require. Select Typical, and click next all the way through to finish without changing anything.

Checkpoint: Fire up your favorite browser and navigate to http://localhost. You should see a message saying It Works!. Congratulations!

Step Three: Install and Configure PHP

Now we need to install PHP. Because PHP usually needs to be somewhere above your WEBROOT, in our case the D:\server\www\public folder, we are going to extract the PHP zip file that we downloaded to D:\server\php

Next, rename D:\server\php\php.ini- recommended to php.ini. Open php.ini in a text editor and apply the following changes.

Search for extension_dir = "./" and replace it with extension_dir = "D:/server/php/ext"

Find the following lines and remove the ';' from each one of them. This is effectively uncommenting them, or ENABLING them, so this:

;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll

must become

extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll

The first enables the Image GD library, the second enables mbstring, and the third and forth enable us to use the MySQL database.

You can now save the php.ini file.

Perfect! We are getting there! Now let us tell the computer to start PHP everytime the computer reboots. So, click on Start, then Control Panel, System, Advanced System Settings. Click on the Environmental Variables button, then scroll down in system variables to find PATH, Edit it and then Add the following Code to it:

D:\server\php;

Now PHP will start everytime your computer boots. Click OK all the way out and then reboot your system. This is IMPORTANT. If you do not restart your computer RIGHT NOW, PHP and MySQL will never start and never find each other. You have been warned.

Step Four: Setup Apache

Now we are going to set Apache Server up and tell it where it needs to look for our local scripts, etc. Note that the .conf files are generally a mission to edit with notepad, so please, please, please use something like Aptana Studio, Dreamweaver, etc. Aptana Studio is free, and can be found HERE. If you are going to all the trouble of setting up a local server it makes sense to just setup a decent editor too. Dreamweaver, notepad++ etc. will also work. Notepad as found in your applications menu under start, will not do the trick.

Ok, in your text editor, go to C:\Program Files\Apache Software Foundation\Apache2.2\conf and open httpd.conf. This is the config file that runs Apache.

Search for #LoadModule rewrite_module modules/mod_rewrite.so and remove the comment #, making it LoadModule rewrite_module modules/mod_rewrite.so This enables mod rewrite.

Next, Add these lines immediately after the previous step. LoadModule php5_module "D:/server/php/php5apache2_2.dll" PHPIniDir "D:/server/php"

Now look for AddType application/x-gzip .gz .tgz After that add AddType application/x- httpd-php .php and AddType application/x-httpd- php-source .phps

Now look for DirectoryIndex index.html and change it to DirectoryIndex index.html index.php

Next, this line #Include conf/extra/httpd- vhosts.conf must become Include conf/extra/httpd-vhosts.conf

Step Five: Virtual Hosting

At this point we want to tell Apache that we are going to have a localhost named server, and that when we call it in the URL it must treat server as is it is localhost. We do this by going to C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra and opening httpd-vhosts.conf.

Replace all the existing code there with the following:

<virtualhost *:80>
DocumentRoot "D:/server/www/public"
ServerName server
ServerAlias www.server
<directory "D:/server/www/public">
AllowOverride All
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</directory>
</virtualhost>

Save and close this file.

Step Six: Hosts File

The next step takes us slightly out of my comfort zone, yet what we are doing is completely safe, reversable, and has only resulted in one nuclear explosion (that I know of). Navigate to C:\Windows\System32\drivers\etc and open hosts and add the following

127.0.0.1 server<>
127.0.0.1 www.server

Checkpoint: restart Apache. If all is right, Apache will restart without a glitch.

Step Seven: Install MySQL

Unzip the MySQL file you downloaded and run the installer.

For Setup Type, select typical, and then hit next all the way, and don't worry about skipping the sign up.

The MySQL Server Instance Wizard will start after the sign-up page. Select Detailed Configuration, then Developer Machine, next select Multifunctional Database. Leave the InnoDB TableSpace Settings on Installation Path. On the next page select Decision Support (DSS)/OLAP, and on the next check Enable TCP/IP Networking. Make sure the Port on this page is set to 3306 and be sure to check the box to Add A Firewall Exception for this port, otherwise MySQL will not run.

Next, select the Standard Character set, then check both Install as a Windows Service and Include Bin Directory In Windows Path. Leave the service name as MySQL and be sure to check the box so that Windows can Launch The MySQL Server Automatically on Startup.

On the next page, Modify Security Settings by entering root as the root password. Do not create an anonymous account, there is no real point.

Now hit execute and let the MySQL Wizard build up everything. If there is a problem, the wizard can be accessed under start, all programs, MySQL.

OK, we are almost done. As a test, create a file called index.php in D:\server\www\public (or wherever you have created your server), and inside the file paste the following:

<?php 
phpinfo();
?>

Let us restart Apache by clicking on the little feathered icon in our task bar, and then clicking on restart.

Fire up your browser and in the URL type http://server and then hit enter. You should now be looking at your very own custom webserver showing the PHP Info page.

Congratulations! It has been a long journey, but a worthy one, and if you have learned anything close to what I have through this exercise, then I will be happy.

Until Next Time,
All the Best

About the Author

Marc Steven Plotz is a Senior Software Developer for a major South African web development company specializing in the development of enterprise-class web applications and rapid application development frameworks. He is also a technical writer for various developer websites focusing on open source topics like PHP, CSS, HTML and Javascript. He lives in Pretoria, South Africa, with his wife and two children.



Up to => Home / Authoring / Tutorials / JavaScript



Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers