Linux

Create Virtual Host In XAMPP In Linux, Mac And Windows

create virtual host in xampp

Without any explanations, Let’s jump into the process to create virtual host in XAMPP in Windows, Mac and Linux.

Here, We are going to talk about the method to setup virtual host in XAMPP.

Create Virtual Host In XAMPP In Linux, Mac And Windows

At first let check out the process for Windows.

How To Create Virtual Host In XAMPP In Windows

We generally install XAMPP in C: drive which means that the virtual host file ( (httpd-vhosts.conf) will be in C:/xampp/apache/conf/extra

Open this file in your favorite editor. You need to paste the following code at the bottom of the file. Here we are creating omgfoss.local virtual host.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/omgfoss"
    ServerName omgfoss.local
    ErrorLog "logs/omgfoss-error.log"
    CustomLog "logs/omgfoss-custom.log" common
 </VirtualHost>

For Linux based operating systems:

How To Create Virtual Host In XAMPP In Linux.

In Linux the process is little tricky. By default, XAMPP in Linux is not configured to use the httpd-vhosts.conf file which means that we need to include this file so that it can be loaded during the runtime.

To include it, You need to open the httpd.conf in your favorite editor file. This file is located /opt/lampp/etc. You can simply run the following command to open this file.

sudo gedit /opt/lampp/etc/httpd.conf

and locate the following lines:

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

Now, You need to remove the # from above line and save it.

Virtual hosts
Include etc/extra/httpd-vhosts.conf

Finally, We can create the virtual host on Linux. Locate and open the file /extra/httpd-vhosts.conf with your editor and add the following lines.

READ THIS ALSO  Download Free Kubernetes Tutorial Ebook For Beginners
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/omgfoss"
    ServerName omgfoss.local
    ErrorLog "logs/omgfoss-error.log"
    CustomLog "logs/omgfoss-custom.log" common
 </VirtualHost>

How To Create Virtual Host In XAMPP In Mac.

For Mac based systems, You also need to include httpd-vhosts.conf file so that it can loaded during run time. It is located in /Applications/XAMPP/xamppfiles/etc/httpd.conf

Locate the following line and update it without the comment section.

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

Now, You need to remove the # from above line and save it.

Virtual hosts
Include etc/extra/httpd-vhosts.conf

Now, Open the file /extra/httpd-vhosts.conf with your editor and add the following lines.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/omgfoss"
    ServerName omgfoss.local
    ErrorLog "logs/omgfoss-error.log"
    CustomLog "logs/omgfoss-custom.log" common
 </VirtualHost>

At last you need to update the host file of the operating system.

For Windows based operating system, host file is located in  C:\Windows\System32\drivers\etc\hosts

Add the following line at the end of the file and save it.

127.0.0.1 omgfoss.local

For Linux based operating system, host file is located in  /etc/hosts

Add the following line at the end of the file and save it.

127.0.0.1 omgfoss.local

For Mac based operating system, host file is located in  /etc/hosts

Add the following line at the end of the host file and save it.

127.0.0.1 omgfoss.local

Now, Restart your XAMPP and enjoy.