Creating a localhost in Windows (Part 1: Installing Apache)


A localhost is a developers best friend when it comes to testing out server side scripts etc. Much like a web-server, a localhost is a space which is offline but allows you to view/test server side code as if it was a real online server, but infact you will be creating a server which can only be accessed by you. There are many ways to create an localhost but there is one easy newbie friendly way to go about it, and that is by installing Apache web server on your computer. This method is very simple and easy to follow.

Step 1: Download Apache

It won’t always be this simple but apache comes in a msi installer, so it’s literally a click and install setup, with a nice and friendly wizard! But let me warn you it won’t always be like this!

First of all head over to:

To download Apache, what we’re going to do is install it as a Windows Service which will allow you control of starting, stopping and restarting your localhost. Download the msi and then run the setup.

Step 2: Setting up Apache

When you run the installer, you’ll be asked if you accept a license agreement, but the more important stage we’re looking for is when you get to server information stage, when you see this window you will want to have these settings:

Network Domain: localhost
Server Name: localhost
Admin Email: (You can use any current registered email e.g. Hotmail a POP3 whatever)

Also make sure that the setting, All Users, on Port 80, as a Service is checked.

Install 1

Once you have installed apache the service will automatically start and you should notice a icon like this in the system tray:

system tray

It is very easy to control the apache service, by right clicking on the tray icon you will get a menu which allows you to open the apache monitor and from there you can restart, stop or start the apache service.

Step 3: Testing Apache

If you see the apache tray icon, and the installer went through without any issues, then you have successfully installed Apache! Now it is time to test it for real and see if it has worked, you will now for the first time, access your localhost. You can do this by either going to, http://localhost or I’d recommend using the http://localhost, but both take you to the same place!

If you go to either of those links and see text that says “It works!” then you have successfully set up Apache.

Step 4: Pointing Apache to your specified location

Apaches location by default to look for files is, C:/Program Files/Apache Software Foundation/Apache2.2/ but this isn’t the best folder structure to save all your localhost files, so if you want to have Apache look in a different location which is easier for you to access you will need edit the httpd conf which is the configuration file for Apache.

To edit the httpd conf you can go to Start > Programs > Apache HTTP Server 2.2 > Configure Apache Server > Editing httpd conf

When you click on this, the configuration of Apache will open in a text editor which for most people will be notepad. To change the directory of where Apache is pointing to you will need to find this line:

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/"


To make things more easier, I decided to create a folder on my C:/ drive called localhost and then within that made another folder called public_html which represents how a web server works. (You put all your webpages in the public_html) so by me doing this my document root is

DocumentRoot "C:/localhost/public_html"

Depending on how you go about it, you will change it to however you’ve set up your folder structure

By editing the DocumentRoot you also need to change the Directory as they are both relative to each other, so whatever you changed the DocumentRoot to you will need to update this line to it also:

This is my DocumentRoot structure:


**Don’t worry about the php folder on there. Because I already have set up a localhost I have certain parts loaded on there already, but as you come to see part 2 you will understand why it’s there.

The folders are located on my C:/, I have then created a folder called localhost and then a folder within that called public_html (This is where all my webpage stuff will go) Once you have changed the DocumentRoot and Directory save the configuration file.

Step 5: Making Apache automatically search for webpages named index

On your localhost you may have certain folders within the public_html folder which have a index.php (Or whatever webpage format it is saved in) page. By deafult, Apache does not automatically look for them so if you came to access a URL like http://localhost/website it would display the root of the folder and all the files within it (Even if it has a index page) to make Apache automatically display them you will need to edit the Apache HTTPD configuration file. This is just below the DocumentRoot line in the config. Replace the default with this:

DirectoryIndex index.html index.php

You can add more webpage file types if you need to!

Step 6: Testing the configuration

To test the configuration you can go to Start > Programs > Apache HTTP Server 2.2 > Configure Apache Server > Testing Configuration

Now the test doesn’t give a straight Yes or no, instead a command prompt window will appear. If the command prompt window appears but instantly disappears then this means that your configuration is fine. If the window appears and text is displayed in the window, it means something is wrong, the command prompt window will display what the problem is (If there is one) and tell you what you need to do

You’ve configured and setup your Localhost!

We have now installed Apache and setup a localhost, in part two we shall be installing PHP on our localhost (One of the main reasons why people use localhosts, to test server side code)

Share This: