Skip to content

Instantly share code, notes, and snippets.

Last active October 20, 2021 10:13
Show Gist options
  • Save salahineo/3ee4333450a13d4cfedf330da191e822 to your computer and use it in GitHub Desktop.
Save salahineo/3ee4333450a13d4cfedf330da191e822 to your computer and use it in GitHub Desktop.
XAMPP Virtual Host For Linuix

I’ll go step-by-step on how to create a virtual host in the XAMPP environment For Linux.

As we know, the default http://localhost points to /opt/lampp/htdocs as the root directory. The desired result is to be able to visit http://examplevhost.local, with the root directory being /opt/lampp/htdocs/examplevhost.

Note: The steps below are done on Ubuntu 20.04, but they should also work on most other Linux distributions (Debian, Mint, Arch).

Note: I’ll assume that XAMPP is installed in /opt/lampp/. If it’s different on your setup, please read carefully and adjust accordingly.

Enable virtual hosts in apache configuration file

Note: This should be done only once per XAMPP installation. If you want to add another virtual host later you can skip to the next step.

sudo nano /opt/lampp/etc/httpd.conf
  • Find the line that looks like this:
# Virtual hosts
# Include etc/extra/httpd-vhosts.conf
  • Uncomment the one that starts with "Include":
# Virtual hosts
Include etc/extra/httpd-vhosts.conf

Create project files

sudo mkdir /opt/lampp/htdocs/examplevhost
sudo touch /opt/lampp/htdocs/examplevhost/index.html

Add host to system hosts file

sudo nano /etc/hosts
  • Add this line to the bottom of the file:	examplevhost.local

Note: You should add this line localhost once in the /etc/hosts file (if it is not already exists)

Add host to XAMPP virtual hosts file

sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf
  • Since we enabled this file in the first step we can start editing it. Add this:
<VirtualHost *:80>
  <Directory "/opt/lampp/htdocs/examplevhost">
    AllowOverride All

  ServerName examplevhost.local
  ServerAlias www.examplevhost.local
  DocumentRoot "/opt/lampp/htdocs/examplevhost"

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Note: You can re-use this snipped for any number of virtual hosts. The directives that need changing are DocumentRoot, ServerAlias, and ServerName (ServerName must exist as an entry in /etc/hosts).

Note: It's safe to remove the example virtual hosts that come by default.


  • Restart XAMPP sudo /opt/lampp/lampp restart
  • Visit http://examplevhost.local and you should see the content of /opt/lampp/htdocs/examplevhost/index.html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment