Virtual Hosts XAMPP [Linux Ubuntu] not working
Step 1: Edit apache configuration
sudo nano /opt/lampp/etc/httpd.conf
and find below the line and uncomment (remove #) and save
Include etc/extra/httpd-vhosts.conf
Step 2: Edit vhost configuration to Add Virtual Host
sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf
and add below code with your DocumentRoot (/opt/lampp/htdocs/example) and ServerName (URL)(example.local)
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/example"
ServerName "example.local"
ErrorLog "logs/example.local-error_log"
CustomLog "logs/example.local-access_log" common
</VirtualHost>
Step 3: Edit host file to add your URL (example.local)
sudo nano /etc/hosts
and add this line to the bottom with your URL (example.local) and save
127.0.1.1 example.local
Step 4: Restart server
sudo /opt/lampp/lampp restart
The virtual hosts conf by defualt is disabled in httpd.conf, in order to allow virtual hosts
in XAMPP under Ubuntu you have to uncomment line 480
in httpd.conf
:
MAINSTEP: Uncomment line 480
as below:
479. # Virtual hosts
480. Include etc/extra/httpd-vhosts.conf
The httpd.conf
file is located under /opt/lampp/etc
, to modify it just follow these steps:
1. run sudo gedit /opt/lampp/etc/httpd.conf
2. apply MAINSTEP