Mangopear creative

Working locally with WAMP: Setting up aliases.

Working locally with WAMP: Setting up aliases.

I find it easier to work with my locally hosted websites when they run off of an alias. Instead of visiting http://localhost/local.mangopear.co.uk/ (assuming my build was located at C:/wamp/www/local.mangopear.co.uk/) I visit http://local.mangopear.co.uk.

It’s worth noting that my folder structure for builds is based on their would-be live domain names – for instance the build for this website is stored in C:/wamp/www/www.mangopear.co.uk/.

For working locally I use WAMP (Windows; Apache; MySQL; PHP) as it’s simple to set up and works across my Windows devices. At this point I’d like to mention Finch – which is a great app for testing your local development projects from other devices.

Setting up Aliases

Your folder structure:

The instructions below are based upon the assumption that your folder structure is similar to mine i.e. (if your project is called SiteName) C:/wamp/www/www.sitename.com/ or C:/wamp/www/sitename/

Normally, with the above, you would visit either: http://localhost/www.sitename.com/ or http://localhost/sitename/

Let’s imagine we want to access it at http://local.sitename.com/ we would follow the steps below.

It’s worth noting that you do not want to set your alias to http://sitename.com/ as this would prevent you from being able to access the live domain from your development device as the alias would override the default DNS for that domain name. You should always use a domain name that will not be in use – such as local.(…).

1. Enable VirtualHosts in Apache:

By default WAMP does not enable VirtualHosts. Thankfully it’s very easy to enable them:

  1. Open your favoured text editor (could be Notepad or Sublime Text);
  2. Open the httpd.conf file located at C:/wamp/bin/apache/apache2.4.9/conf/extra/;
  3. Search for “Virtual hosts” and remove the # from the line below which should read:
    Include conf/extra/httpd-vhosts.conf“; and
  4. Save the config file.

2. Register your alias:

  1. In your text editor, now open the Virtual hosts configuration file:
    C:/wamp/bin/apache/apache2.4.9/conf/extra/http-vhosts.conf
  2. At the bottom of this file, add a new VirtualHost. See the Gist below for an example of this.
  3. You will need to change the ServerName; DocumentRoot; and Directory values to match your development instance.

3. Edit your hosts file

  1. Open Notepad in Administrator mode (go to start menu; search for “Notepad”; right click; and select “Run as Administrator”)
  2. Open your hosts file, which is located at:
    C:/Windows/System32/Drivers/etc/hosts
  3. Add a new entry at the bottom of this document:
    127.0.0.1 local.sitename.com

4. Restart your WampServer

  1. Locate the Wampserver icon in your taskbar;
  2. Click to reveal menu;
  3. “Restart all services”;
  4. Wait for the icon to turn green and you’re ready to go.

No comments

Start the conversation.
Be the first to comment.