Create Virtual Hosts in XAMPP
Follow steps below to create virtual hosts.
Locate the file httpd-vhosts.conf in the directory: xampp\apache\conf\extra\. Add the following sections to the file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "\xampp\htdocs"
<Directory "\xampp\htdocs">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName becc.local
DocumentRoot "\xampp\htdocs\becc"
<Directory "\xampp\htdocs\becc">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.local
DocumentRoot "\xampp\htdocs\example"
<Directory "\xampp\htdocs\example">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The above creates these web sites:
- http://localhost
- http://becc.local
- http://example.local
Modify the hosts file on PC
In order to access these websites from the PC using domain names, the PC hosts file has to resolve the domain names to IP addresses. Add these lines to the C:\Windows\System32\drivers\etc\hosts file.
127.0.0.1 localhost 127.0.0.1 becc.local 127.0.0.1 example.local
max_allowed_packet Setting
When importing a database, there may an error due to the max_allowed_packet setting. To adjust this setting, edit the file xampp/mysql/bin/my.ini as follows:
[mysqld]
max_allowed_packet = 512M
[mysqldump]
max_allowed_packet = 512M
Then restart mySQL.
