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 “http://myapp.dev”. Here is how to do it.
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
SetEnv APPLICATION_ENV "development"
Allow from all
Be sure to change “myapp.dev” to your own application name as well as the DocumentRoot and Directory path to your own path.
Open your “/etc/hosts” file if on *nix or “C:WINDOWSsystem32driversetc” file on Windows. Add the following line right after the similar looking ones:
Restart your Apache server and open a browser. Navigate to “http://myapp.dev” and, if everything went well, you should see your site!