In this tutorial you will learn about the Laravel 5.8 Installation and its application with practical example.
Laravel 5.8 Installation
Download and install Laravel 5.8 using the below command. Make sure you have composer installed.
1 |
composer create-project --prefer-dist laravel/laravel larablog |
Now, lets switch to the project directory and start the development server using following artisan command –
1 |
php artisan serve |
Now, open the following URL in browser to see the output –
http://localhost:8000/
Output:-
In case if you get RuntimeException No application encryption key has been specified error, please follow instruction given below to generate application key –
Generate Application Key
Open terminal and switch to the project directory and run the following command to generate application key and configure cache.
1 |
php artisan key:generate |
1 |
php artisan config:cache |
Connecting Laravel with MySQL Database
In order to connect your laravel application to a MySQL database. Lets create a MySQL database set database credential in application’s .env file.
.env
1 2 3 4 5 6 |
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=lara58blog DB_USERNAME=root DB_PASSWORD= |
Migrations
Before we run “php artisan migrate” command, location the file “app/Providers/AppServiceProvider” file, and add following line of code in the top of the file
1 |
use Illuminate\Support\Facades\Schema; |
and inside the boot method set a default string length as given below –
1 |
Schema::defaultStringLength(191); |
So this is how your “app/Providers/AppServiceProvider” file looks like –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { public function boot() { // Schema::defaultStringLength(191); } public function register() { // } } |
After installing laravel, some default migration files are created inside “database/migrations” directory. Now, lets run the “php artisan migrate” command for creating default create users table and password reset table.
1 |
php artisan migrate |
Restart Development Server
Restart the development server using following artisan command –
1 |
php artisan serve |
Now, visit the following URL in browser to see the output –
http://localhost:8000/
Output:-