After installing XAMPP for Linux I wanted to use my old trick of configuring virtual hosts for Apache.
There is a one-time configuration, and two steps for each virtual host.
One-time configuration is needed to actually use virtual hosts, and to restore access to original XAMPP documents. So here it goes:
1. Open terminal and edithttpd.conf
file:
$ sudo nano /opt/lampp/etc/httpd.conf2. Now find the following line and uncomment it by removing the hash symbol (#) at the beginning:
Include etc/extra/httpd-vhosts.conf3. Edithttpd-vhosts.conf
file:
$ sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf4. Replace definitions fordummy-host.example.com
anddummy-host2.example.com
with following:
# Use name-based virtual hosting. NameVirtualHost *:80 <VirtualHost *:80> ## Restore access to localhost resources DocumentRoot "/opt/lampp/htdocs/" ServerName localhost </VirtualHost> <VirtualHost *:80> ## Restore access to 127.0.0.1 resources DocumentRoot "/opt/lampp/htdocs/" ServerName 127.0.0.1 </VirtualHost> 5. Restart Apache or reload its configuration. Then check if you can still access XAMPP Dashboard at: http://localhost and http://127.0.0.16. Prepare directory for future virtual hosts, and give your user's group write access to it:
$ sudo mkdir /opt/lampp/vhosts $ sudo chgrp $(id -n -g) /opt/lampp/vhosts $ sudo chmod g+rwx /opt/lampp/vhosts
For each virtual host, name resolver needs to be informed about new local domain.
Then virtual host definition has to be added, and directory for host's files created.
Finally after Apache restart all should work.
7. Edit local name resolverhosts
file:
$ sudo nano /etc/hosts8. Add local/development domain, for example "helloapp":
127.0.0.1 helloapp9. Edithttpd-vhosts.conf
file:
$ sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf10. Add virtual host, setting correctly paths and names:
<VirtualHost *:80> DocumentRoot "/opt/lampp/vhosts/helloapp" ServerName helloapp ErrorLog "logs/helloapp-error.log" CustomLog "logs/helloapp-access.log" combined # The same settings as for <Directory "/opt/lampp/htdocs"> in conf/httpd.conf <Directory "/opt/lampp/vhosts/helloapp"> # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews Options Indexes FollowSymLinks ExecCGI Includes # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit AllowOverride All # Controls who can get stuff from this server. Require all granted </Directory> </VirtualHost>11. Prepare directory for virtual host, remember about correct path:
(this works only if step 6. has been done, otherwise permission errors can occur)
$ mkdir /opt/lampp/vhosts/helloapp12. Restart Apache or reload its configuration. Then check if you can access new virtual host at:
http://helloapp
See also: