Copied!
Laravel
PHP
Xampp

how to create virtual host on XAMPP - in 3 simple steps

laravel-blog.jpg
Shahroz Javed
Aug 05, 2023 . 353 views

Introduction

Creating a virtual host in XAMPP involves configuring your local development environment to recognize a custom domain name and route requests to a specific directory on your computer. This is useful for developing and testing web applications locally with a specific domain name. Here's how you can create a virtual host in XAMPP:

Steps

01: Edit the Hosts File:

  • Open a text editor with administrative privileges (Run as Administrator).
  • Open the hosts file. On Windows, this file is located at C:\Windows\System32\drivers\etc\hosts.
  • Add an entry for your virtual host. For example:
127.0.0.1 myapp.local

02: Configure Apache Virtual Host:

  • Navigate to the httpd-vhosts.conf file. In XAMPP, this file is located at C:\xampp\apache\conf\extra\httpd-vhosts.conf.
  • Open the file in a text editor.
  • Add a virtual host configuration block. For example:
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/myapp"
    ServerName myapp.local
    <Directory "C:\xampp\htdocs\myapp">
    </Directory>
</VirtualHost>
        

Replace "C:/xampp/htdocs/myapp" with the actual path to your project's directory.

03: Restart Apache:

  • Open the XAMPP Control Panel.
  • Stop and then start the Apache server.

04: Access Your Virtual Host:

  • Open a web browser and navigate to `http://myapp.local`

Conclusion

Your virtual host should now be accessible using the specified domain name (`myapp.local`) in your web browser. This allows you to work on your web application using a custom domain name in your local development environment.

📑 On This Page