Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Setting up local domains for development

Tuesday, May 10th, 2011 by Servage

In this previous article I discussed some easy solutions to get started with local development for PHP and MYSQL applications. However, following the default installation instructions for the available server software, often just gives you a standard setup without local domains. For example a default Apache webserver shows the global webroot when accessing http://your-ip or http://localhost (or any domain pointing to your computer).

This article will show you the basics of setting up your system to work with local domains, so you can work on multiple projects on your system in parallel. For this purpose, let’s say you have two projects, called “Aproject” and “Beeproject”.

We want to access these two projects on the local computer by using the addresses http://aproject.local and http://beeproject.local. Therefore we need to tell your computer to route these domains to itself. On a Unix-system you open a console and enter:

vi /etc/hosts

You need to add the two local domains:

127.0.0.1   aproject.local
127.0.0.1   beeproject.local

If your webserver runs, entering either of those addresses into your browser should display the global webroot (like typing http://localhost).

Now we need to tell the Apache webserver that it has multiple domains. This concept is called VirtualHost in Apache. Open your Apache configuration file (i.e. /Applications/MAMP/conf/apache/httpd.conf for MAMP on Mac) and make sure you have the following settings:

Listen *:80
NameVirtualHost *:80

<VirtualHost *:80>
  ServerName aproject.local
  DocumentRoot "/fullPath/to/aproject"
</VirtualHost>

<VirtualHost *:80>
  ServerName beeeproject.local
  DocumentRoot "/fullPath/to/beeproject"
</VirtualHost>

After restarting your webserver it will respond accordingly for the two local domains on port 80 for any IP on your local machine. Try http://aproject.local

Problems?

Check out the Apache Documentation for detailed help. Maybe the configuration for Directory is a good place to start, in case your webroots are outside the default webroot, and therefore might be more restricted.

Setting up local domains for development, 3.8 out of 5 based on 9 ratings
Categories: Guides & Tutorials, Tips & Tricks

Keywords:

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.