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
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.
- Add/point Virtual host entry in
httpd-vhosts.conf
file. This file normally falls inxampp\apache\conf\extra
folder. - Point Virtual host entry to
hosts
file. Hosts file path isC:\Windows\System32\drivers\etc\
on windows.
Add Laravel Folder Path to http-vhosts.conf:
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.
1 2 3 4 5 6 7 8 9 10 11 |
<VirtualHost mysite.laravel:80> DocumentRoot "D:\xampp\htdocs\my_site\public" ServerAdmin mysite.laravel <Directory "D:\xampp\htdocs\my_site"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> |
Add Laravel Folder Path to hosts file:
Normally hosts file path is C:\Windows\System32\drivers\etc\hosts
. Open hosts file as an Administrator.
1 2 3 |
127.0.0.1 mysite.laravel |
Once both entries are done restart your xampp apache service and goto browser and type mysite.laravel
. You will see laravel default page.