• More shocking case studies – how to game Klout

    Last week I posted an article highlighting how you could game Klout. In my post and the subsequent commentary I argued that: Klout’s model of scoring seems to be based predominantly on levels of network activity which is a rather primitive appr…

    Posted in Google Read More
  • Klout: Here is how you can game Klout

    Dear SEO consultants, If you are taking a healthy dose of digital marketing every fortnight or so then you have probably heard of the new boys in town, yes the infamous Klout! Klout hasĀ receivedĀ a lot of good PR, if I can recall correctly they have…

    Posted in Google Read More
  • Query deserves freshness (QDF) in practice

    Search engine & informational retrieval technologies have come a long way yet they are still in their infancy, particularly when it comes to sentiment and intent analysis. Very often users with different search intents may submit the same search quer…

    Posted in Google Read More

Setting up a localhost

Posted on November 22, 2011 by under Web Design

Windows computers don’t nativly process PHP files so a few tricks are required to allow working on them as if using a web server. Once setup you can use your PC as an ad-hoc host to test and work on scripts or even run a website or two.

There are many programs to do a majority of the hard work such as installing and configuring PHP, MySQL, and PHPMyAdmin so we should start there.
I suggest using WAMP as it has interchangeable components and is fairly easy to setup.

Installing WAMP

  » Download and install WAMP – http://www.wampserver.com/en/download.php

I find it easiest to install WAMP to the suggested directory of C:\wamp as your final “web” folder will be C:\wamp\www.
We will need to make a few changes after it has finished installing to emulate a web server a little more.

We can start by creating a folder called “example.com” in the C:\wamp\www folder to store the files we are testing.
Inside the example.com folder create a file called index.php and insert some random data such as “hello world” so we can see if it’s working or not.

Allowing Virtual Hosts

Allowing virtual hosts will enable multiple websites, or hosts, to run from one machine so we need to enable it in the httpd.conf file.

  • Click the WAMP icon in your taskbar
  • Click Apache
  • Click http.conf to open the file
  • Find:
    #Include conf/extra/httpd-vhosts.conf
  • Change to:
    Include conf/extra/httpd-vhosts.conf

WAMP virtual hosts

Now we have allowed virtual hosts we can create a fake website to test on so we need to tell Windows we want to see our fake domain.

Editing the hosts file

The file we need to edit is protected; it is easiest to copy the file to the dekstop then edit and copy it back, replacing the original.
Find and edit:
C:\system32\drivers\etc\hosts
Adding the following to the very last line of the file:

127.0.0.1     example.com

This will make sure example.com is loaded from our computer instead of the remote website.

Note: We can also copy the above line with www.example.com but it’s good practice to test offline with non-www and online with www urls.

Setting up virtual hosts

Next we need to tell PHP and associated software where the files are located on our computer and where to store the error and access files, so we need to edit another file.
Find and open:
C:\wamp\bin\Apache2.2.17\conf\extra\httpd-vhosts
Adding the following to the bottom of the file:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "C:/wamp/www/example.com"
    ServerName example.com
    ErrorLog "C:/wamp/logs/example.com-error.log"
    CustomLog "C:/wamp/logs/example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "C:/wamp/www/example.com"
    ServerName example.com
    ServerAlias www.example.com
    ErrorLog "C:/wamp/logs/example.com-error.log"
    CustomLog "C:/wamp/logs/example.com-access.log" common
	<directory "C:/wamp/www/example.com">
	 Options Indexes FollowSymLinks
	 AllowOverride all
	 Order Deny,Allow
	 Deny from all
	 Allow from 127.0.0.1
	</directory>
</VirtualHost>

The above code will tell PHP, MySQL and PHPMyAdmin where the files are located on our computer. It handles both www and non-www urls but we won’t need both yet.

Wrapping up

The final step is click the WAMP taskbar icon and then “restart all services”.

Typing http://example.com in your browser should open our example “hello world” page
Typing http://www.example.com in your browser should show the official test page, which is useful for testing purposes if you plan to get a little more involved with coding.

A little about adamdavies …

Adam is a new member of the webdesign team. He has a passion for standards compliant code and the more technical aspects of webdesign.
This post was tagged under: , , , ,
No comments have been made on this post.

Want to Contribute? Leave a Comment…

Your email address will not be made public or shared. Inappropriate and irrelevant comments will be removed.