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
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
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)
Normally, with the above, you would visit either:
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:
- Open your favoured text editor (could be Notepad or Sublime Text);
- Open the
httpd.conffile located at
- Search for “Virtual hosts” and remove the # from the line below which should read:
Include conf/extra/httpd-vhosts.conf“; and
- Save the config file.
2. Register your alias:
- In your text editor, now open the Virtual hosts configuration file:
- At the bottom of this file, add a new VirtualHost. See the Gist below for an example of this.
- You will need to change the
Directoryvalues to match your development instance.
<VirtualHost *:80> # The name to respond to ServerName local.sitename.com # Folder where the files live DocumentRoot "c:/wamp/www/www.sitename.com" # A few helpful settings... <Directory "c:/wamp/www/www.sitename.com"> allow from all order allow,deny # Enables .htaccess files for this site AllowOverride All </Directory> # Apache will look for these two files, in this order, if no file is specified in the URL DirectoryIndex index.html index.php </VirtualHost>
3. Edit your hosts file
- Open Notepad in Administrator mode (go to start menu; search for “Notepad”; right click; and select “Run as Administrator”)
- Open your hosts file, which is located at:
- Add a new entry at the bottom of this document:
4. Restart your WampServer
- Locate the Wampserver icon in your taskbar;
- Click to reveal menu;
- “Restart all services”;
- Wait for the icon to turn green and you’re ready to go.