Adding a Virtual Host (vhost) in XAMPP on a Mac

Recently, I had to set my other mac up with a local dev environment and found it hard to find the correct files to edit on a mac with XAMPP. I want to set up an environment where I can hit localhost.com and get served XAMPP files. So here goes:

Edit your hosts on mac 10.6:

In /etc/hosts – add the following line to the end of the file:

127.0.0.1   localhost.com

Edit your XAMPP vhosts file:

In /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf add the following to the end of the file:

<VirtualHost *:80>
        DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
        ServerName localhost.com
</VirtualHost>

Finally, edit your XAMPP apache config file:

In /Applications/XAMPP/xamppfiles/etc/httpd.conf uncomment the following line:

# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

Now stop apache, restart XAMPP and you should be able to visit:

http://localhost.com/PATH_TO_YOUR_LOCAL_SITE

 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.