Skip to content

Instantly share code, notes, and snippets.

@noeGnh
Last active August 23, 2023 16:49
Show Gist options
  • Save noeGnh/3a16658f12eedd4c3040782e81d47e17 to your computer and use it in GitHub Desktop.
Save noeGnh/3a16658f12eedd4c3040782e81d47e17 to your computer and use it in GitHub Desktop.
Setup virtualhosts with XAMPP on linux

Create an virtualhost with XAMPP on linux

Here's a summary of the steps involved in setting up virtual hosts with XAMPP on Linux. Let's assume we want to create a virtualhost at test.local for the example.

Step 1: Include the httpd-vhosts file in the httpd.conf configuration file

Open the configuration file with path /opt/lampp/etc/httpd.conf:

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

Look for the term 'Virtual hosts' and uncomment the line below:

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

Save the httpd.conf file

Step 2: Edit httpd-vhosts.conf file

Open with this command:

$ sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf 

At the top of the file add this configuration for XAMPP home folder

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs"
    ServerName localhost
</VirtualHost>

Then add the configuration for the virtualhost you wish to create

<VirtualHost test.local:80>
    DocumentRoot "/home/user/test"
    ServerName test.local
    ErrorLog "logs/test.local-error.log"
    <Directory "/home/user/test">
    	Allow from all
        AllowOverride all
    	Require all granted
    </Directory>
</VirtualHost>

Save the httpd-vhosts.conf file

Step 3: Edit your hosts file

Open with this command:

$ sudo gedit etc/hosts

Add this line:

127.0.0.1   lab.local

Save the hosts file and restart XAMPP:

$ sudo /opt/lampp/lampp restart

If you get a 403 error on launch, make sure that the folder to which your virtualhost is directed has the necessary permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment