Learn how to configure easily a virtual host for your Laravel project (with local domain) in Xampp for Windows.

Sometimes you will need to create virtual hosts in xampp to handle multiple projects because that's easier than accesing the direct path with the localhost URL. Creating a virtual host in xampp is pretty easy, however you may need orientation to configure it correctly for a Laravel project and today we are going to share with you how to do it easily.

1. Create local domain for your app

In this article we want to access our laravel project from the browser accesing the URL http://laravel-sandbox/, so you need to modify the hosts file of Windows located in C:\Windows\System32\drivers\etc\hosts. Remember to edit the hosts file using an editor with administrator rights, otherwise you won't be able to save the changes. Then add the host using a custom host on your system, in this case we will add the host that will be accesible as well with an alias of laravel-sandbox:

# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
#     rhino.acme.com          # source server
#     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#       localhost
#	::1             localhost	laravel-sandbox

Remember that you can increase the final number of the host to have multiple of them e.g, etc.

2. Configure Virtual Host

The entry point of a laravel application is the index.php inside the public folder, so the desired directory for our application will be the absolute path to your project in the public folder as shown in the following example. The virtual host needs to point out the same host declared in the hosts file of windows (in this case at the port 80. You can create this virtual host appending the following snippet at the end of the content of the httpd.conf file located in the xampp folder \xampp\apache\conf\extra:

    DocumentRoot "C:/xampp/htdocs/projects/laravel-sandbox/public"
    DirectoryIndex index.php      
    <Directory "C:/xampp/htdocs/projects/laravel-sandbox/public">
        Options All
        AllowOverride All
        Order Allow,Deny
        Allow from all

3. Visit your project from the browser

Finally as expected, by visiting either laravel-sandbox or in your browser will show the entry point of your Laravel application:

Laravel Windows Configure Xampp

Now you can start to work on your project without worrying about the local server configuration.

Happy coding !

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.