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.
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
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
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.