Configure Virtual Host for Laravel in XAMPP

In my previous post we have successfully installed laravel on xampp and tested via php artisan serve command. Artisan is the command line interface included in laravel. We will discuss more about artisan in my upcoming posts. SO if you want read by yourself then visit Artisan Console on official laravel documentation.

But this means every time I want to run laravel, I have to use artisan serve command?

No no, You can also access laravel by hitting localhost/laravel_folder_name/public. In our installation tutorial I renamed laravel folder to my_site. Below is the screenshot in which laravel site is showing using localhost/my_site_public

laravel public url

By default laravel uses public/index.php to jump into its eco system. But using localhost/laravel_folder_name/public may create some internal linking problem in development.

To overcome this issue most of the PHP developers (including me) create virtual host for localhost . According to wikipedia:

Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers). This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.

Configure Virtual Host for Laravel in XAMPP:

Now you know what is Virtual Host. Now lets configure virtual host for laravel in xampp. I will create virtual host as mysite.laravel. There are 2 steps involve which are.

  1. Add/point Virtual host entry in httpd-vhosts.conf file. This file normally falls in xampp\apache\conf\extra folder.
  2. Point Virtual host entry to hosts file. Hosts file path is C:\Windows\System32\drivers\etc\ on windows.

Add Laravel Folder Path to http-vhosts.conf:

goto xampp apache conf extra

I have installed xampp in D:\ drive so my http-vhosts.conf file path is D:\xampp\apache\conf\extra\httpd-vhosts.conf. Open http-vosts.conf file and paste below code at the bottom.

Add Laravel Folder Path to hosts file:

Normally hosts file path is C:\Windows\System32\drivers\etc\hosts. Open hosts file as an Administrator.
goto windows system 32 drivers etc hosts

Once both entries are done restart your xampp apache service and goto browser and type mysite.laravel. You will see laravel default page.

mysite laravel


Leave a Reply

Your email address will not be published. Required fields are marked *