how to create virtual host on XAMPP
To create a virtual host on XAMPP, follow these steps:
- Open the XAMPP control panel and start the Apache server.
- Open the Apache configuration file. This is typically located at
C:\xampp\apache\conf\httpd.conf
. - Scroll down to the section labeled
# Virtual Hosts
. - Uncomment the following line by removing the
#
at the beginning of the line:#Include conf/extra/httpd-vhosts.conf
- Save the changes to the
httpd.conf
file and close it. - Open the virtual host configuration file. This is typically located at
C:\xampp\apache\conf\extra\httpd-vhosts.conf
. - Add a new virtual host entry at the bottom of the file. It should look something like this:
- Save the changes to the
httpd-vhosts.conf
file and close it. - Open the hosts file. This is typically located at
C:\Windows\System32\drivers\etc\hosts
. - Add a new entry to the bottom of the file that maps the domain name of your virtual host to your local IP address. It should look something like this:
127.0.0.1 example.local
- Save the changes to the hosts file and close it.
- Restart the Apache server in the XAMPP control panel.
- You should now be able to access your virtual host by visiting the domain name in a web browser.
<VirtualHost *:80>
ServerName example.local
DocumentRoot "C:\xampp\htdocs\example"
<Directory "C:\xampp\htdocs\example">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Replace example.local
with the desired domain name for your virtual host, and C:\xampp\htdocs\example
with the path to the root directory of your website.
Note: You may need to adjust the file paths and/or use administrator privileges to edit the configuration files.