Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sibysathyanesan/1f8773a44da9ffbc6767657f72b6e959 to your computer and use it in GitHub Desktop.
Save sibysathyanesan/1f8773a44da9ffbc6767657f72b6e959 to your computer and use it in GitHub Desktop.
Create virtual host in XAMPP, Ubuntu 16.04

I’ll go step-by-step on how to create a virtual host in the XAMPP environment. 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 16.04, but they should also work on most other Linux distribution

Note: I’ll assume that XAMPP is installed in /opt/lampp. If it’s different on your setup, please read carefully 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 gedit /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” so it looks like this:
# Virtual hosts
Include etc/extra/httpd-vhosts.conf

Create the files

$ mkdir /opt/lampp/htdocs/examplevhost
$ gedit /opt/lampp/htdocs/examplevhost/index.html

Add the host to /etc/hosts

$ sudo gedit /etc/hosts
  • Add this line to the bottom of the file
127.0.1.1	examplevhost.local

Add the host to /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>
    ServerAdmin ibrahimtuzlak.0295@gmail.com
    DocumentRoot "/opt/lampp/htdocs/examplevhost"
    ServerName examplevhost.local # entry in /etc/hosts
    ErrorLog "logs/examplevhost.local-error_log"
    CustomLog "logs/examplevhost.local-access_log" common
</VirtualHost>

Note: You can re-use this snipped for any number of virtual hosts. The directives that need changing are DocumentRoot and ServerName

Note: It's safe to remove the example virtual hosts

Test!

$ sudo /opt/lampp/lampp restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment