Blog

How to Setup Virtual Hosts on mac using xampp

Virtual Hosts allow you to host more than one website on a single server or machine.

In this article lets discuss step-by-step process to setup virtual host on mac with xampp.

Step 1 – Open httpd.conf file available in “ /Applications/XAMPP/xamppfiles/etc/httpd.conf ”

Search for “# Include etc/extra/httpd-vhosts.conf ” and remove “#” (uncomment).

Step 2 – Open httpd–vhosts.conf available in /Applications/XAMPP/xamppfiles/etc/extra/httpd–vhosts.conf

The code shown below is the default virtualhost setup


    ServerName localhost
    DocumentRoot “/Applications/XAMPP/xamppfiles/htdocs”
    
    Options Indexes FollowSymLinks Includes execCGI
    AllowOverride All
    Require all granted
    

From this point, we are using the localhost as our default named Virtual host.

Now if you want to add new virtual host for your new project you can add.

For example, local.mysite.com


 ServerName local.mysite.com
 DocumentRoot “/Applications/XAMPP/xamppfiles/htdocs/local.mysite.com”
 
  Options Indexes FollowSymLinks Includes ExecCGI
  AllowOverride All
  Require all granted
  
  ErrorLog “logs/local.mysite.com-error_log”

So our virtual host is almost done lets take a look at step 3.

Step 3 – Open “hosts” file

Open up your terminal in your macOS and type this code.

sudo nano /etc/hosts

after opening of this file add your virtual host name. Check the code below

127.0.0.1 local.mysite.com

Step 4 – Restart your apache server and check your virtual host