Notice: I'm using Mac OSX 10.6.8
Whenever you are developing different websites or testing same website with different versions, having virtual hosts become useful. Here's the simple procedure how you can create such hosts on your local system.
First of all, you have to start Apache server. You can do it by enabling websharing:
System Prefrences —> Sharing —> Check Enable Web Sharing
Or by typing this command in Terminal.app
>sudo apachectl start
Now enable virtual hosts for the server by commenting out the following line in /private/etc/apache2/httpd.conf
Include /etc/apache2/extra/httpd-vhosts.conf
You have to give now in Apache configuration file to the default folder, which behaves like default webroot folder. In OSX these files are mostly User specific. So edit the file /etc/apache2/users/[USER].conf, to give right permissions
<Directory "/Users/[USER]/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Now move over to /etc/apache2/extra/httpd-vhosts.conf to define the virtual hosts you want to configure by adding these lines:
<VirtualHost *:80>
<Directory /Users/[USER]/Sites/[YOUR_WEBSITE.COM]>
Options +FollowSymlinks +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
DocumentRoot /Users/[USER]/Sites/[YOUR_WEBSITE.COM]
ServerName [YOUR_WEBSITE].local
</VirtualHost>
Now you just have to add the server name to the /etc/hosts file:
127.0.0.1 [YOUR_WEBSITE].local
Check the consistency of config file syntax by running the command
>sudo apachectl -t
If all went well, then restart the Apache server by issuing the following command:
>sudo apachectl restart
Your virtual site is finally working. Just go to your favorite browser and enter your preferred URL http://[YOUR_WEBSITE].local/ and you are ready to go!