How To Setup a VirtualHost on Apache For Your Development Environment

I recently got tired of my URL’s on my local dev machine (Ubuntu 11.04) looking like “http://localhost/projects/someproject/public/” and decided to setup virtual hosting. Now my projects are configured to be accessed like “”. Here is how to do it.

Step 1:

You need to edit your Apache server’s configuration file. Here are some common locations:

  • /etc/httpd/httpd.conf (Fedora, RHEL, and others)
  • /etc/apache2/httpd.conf (Debian, Ubuntu, and others)
  • /usr/local/zend/etc/httpd.conf (Zend Server on *nix machines)
  • C:Program FilesZendApache2conf (Zend Server on Windows machines)

On Ubuntu 11.04 I ended up having to edit “/etc/apache2/sites-available/allsites” because for some reason my httpd.conf file wasn’t working correctly. Either way, you’re going to want to put the following into your configuration file

Be sure to change “” to your own application name as well as the DocumentRoot and Directory path to your own path.

Step 2:

Open your “/etc/hosts” file if on *nix or “C:WINDOWSsystem32driversetc” file on Windows. Add the following line right after the similar looking ones:

Step 3:

Restart your Apache server and open a browser. Navigate to “” and, if everything went well, you should see your site!

Leave a Reply

Your email address will not be published. Required fields are marked *