how to create virtual host on XAMPP

To create a virtual host on XAMPP, follow these steps:

Watch a course Learn object oriented PHP

  1. Open the XAMPP control panel and start the Apache server.
  2. Open the Apache configuration file. This is typically located at C:\xampp\apache\conf\httpd.conf.
  3. Scroll down to the section labeled # Virtual Hosts.
  4. Uncomment the following line by removing the # at the beginning of the line: #Include conf/extra/httpd-vhosts.conf
  5. Save the changes to the httpd.conf file and close it.
  6. Open the virtual host configuration file. This is typically located at C:\xampp\apache\conf\extra\httpd-vhosts.conf.
  7. Add a new virtual host entry at the bottom of the file. It should look something like this:
  8. <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.

  9. Save the changes to the httpd-vhosts.conf file and close it.
  10. Open the hosts file. This is typically located at C:\Windows\System32\drivers\etc\hosts.
  11. 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
  12. Save the changes to the hosts file and close it.
  13. Restart the Apache server in the XAMPP control panel.
  14. You should now be able to access your virtual host by visiting the domain name in a web browser.

Note: You may need to adjust the file paths and/or use administrator privileges to edit the configuration files.