How to Install Laravel on Windows
Laravel is one of the most popular PHP framework. If you are just starting to learn Laravel development, then I assume that you know PHP. Even you know how local development environment works.
At Melo Pixels office, we had few intern on PHP and Laravel Framework. Including our interns, most of the PHP developer ask how to install LAravel on Windows PC. Today I am going to share the right way to install Laravel on Windows pc and also right way to set a local development environment for laravel development.
There are so many ways to make local server on Windows. I am sure that you know how WAMP or XAMPP works and how to install it. As you are familiar with those software, I am not going in details guide. For this post, I am going to use XAMPP as it is easier than WAMP.
Install XAMPP for Laravel
- XAMPP is the most popular PHP development environment. and completely free to use.
- First of all download XAMPP software from here: https://www.apachefriends.org/download.html
- You can chose PHP 7.1 and 32 bit supported software as it will support 64 bit system as well.
- Once download completed, click to install XAMPP for Apache, MySQL and phpMyAdmin
- I will recommend you to install XAMPP in local disc C to avoid a lot ot configuration time and obstacles.
- If everything you did carefully, then I am sure you will see finish button. Click on it to complete the installation process.
Setting path for PHP development on Windows
Most of the time you don’t need to set path for PHP, because XAMPP will do it for you. But I will recommend you to check it.
- First Open Advanced System Settings (System Properties -> Advanced)
- Click to Open on Environment Variables option
- On the top window select Path and click on Edit
- In the new window click on New
- We need to enter the path to XAMPP PHP: C:\xampp\php
- You will also need to add MySQL Path, click on New again and enter: C:\xampp\mysql\bin
Install Composer on Windows for XAMPP
Composer is the application level package manager for PHP. Almost all the PHP expert like to use composer as dependency manager.
- First Download Composer’s installer file: https://getcomposer.org/download/
- While you will install composer, make sure the path is: C:\xampp\php
Now as you Apache, PHP, MySQL and Composer installed, you are ready to install Laravel. By the way, you set a Virtual Host with a custom domain for local development. XAMPP’s Apache uses the htdocs folder for serving HTTP requests, you will see your custom Laravel Virtual Host under C:\xampp\htdocs\example\ which will be opened locally from example.com
Install Laravel on Windows with Composer
First open Windows CMD or powershell and write: cd C:\xampp\htdocs
Now its time to Install Laravel using Composer. To install laravel using bellow command:
composer create-project --prefer-dist laravel/laravel example
Create MySQL Database for Laravel
You can crate database manually by visiting localhost/phpmyadmin very easily. But I am going to show you how you can do it using windows cmd or powershell.
Again Open the CMD or PowerShell and Access the MySQL CLI using bellow command:
mysql -u root -p
Now create Database for your Laravel project using this command:
CREATE DATABASE laravel DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Configuring Laravel’s .env file
Now navigate to C:\xampp\htdocs\example folder. Here example is where we installed our laravel.
From example folder root, Open the .env file and edit the MySQL Connection settings
DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=
Create Virtual Host with XAMPP
You can easily create virtual host in XAMPP. Follow below steps to create virtual host in xampp:
- Go to C:\xampp\apache\conf\extra
- Open httpd-vhosts.conf and append:
NameVirtualHost *:80 <VirtualHost example.com:80> DocumentRoot "C:\xampp\htdocs\example\public" ServerName example.com ServerAlias www.example.com <Directory "c:/xampp/htdocs/example/public"> Require all granted </Directory> </VirtualHost>
How to enable mod_rewrite for Laravel
Its important to enable mod_rewrite mode for laravel and to do this follow below steps:
- Open the httpd.conf file in C:\xampp\apache\conf\extra
- Look for LoadModule rewrite_module modules/mod_rewrite.so and remove the ; at the start
How to Set local domain with hosts file
Personally I like to use custom domain name instead localhost or local IP. Most of the time I use projects name as domain name. Here how you can use custom domain for local development:
- Navigate to c:\Windows\System32\Drivers\etc
- Open the hosts file with Administrator Privileges
- Append the line at the bottom
127.0.0.1 www.example.com example.com
Now if you start Apache and MySQL and brows example.com, you will see that laravel has been installed successfully. And if you can do it, then Yes, welcome to the board.
I hope now you don’t need to ask how to install Laravel on your windows computer. If you face any issue, dont forget to ask me using comment box. Thanks for stopping by and wishing best of luck.