Install Laravel and Basic Configurations

Last modified on July 24, 2020 1 min read

In this tutorial, I’m going to install Laravel and do the basic configuration which needs in any Laravel project.

Table of Contents

  1. Install Laravel
  2. Database Configuration
  3. Handle specified key was too long error
  4. Install Laravel UI

Install Laravel

Let’s install a fresh Laravel project. Before installation you will need to make sure your server meets the following requirements:

  • PHP >= 7.2.5
  • BCMath PHP Extension
  • Ctype PHP Extension
  • Fileinfo PHP extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Method 1: You can install Laravel using Laravel installer:

 # install installer
composer global require laravel/installer
# create project
laravel new my_porject

Method 2: You can also install Laravel using composer:

composer create-project --prefer-dist laravel/laravel my_porject

Database Configuration

In the Laravel project, there is a file called .env. It’s for project configuration. To connect with the database we need to set database credentials.

.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

Handle specified key was too long error

To handle this error, go to this file app/Providers/AppServiceProvider.php and inside the boot method set a default string length:

AppServiceProvider.php
use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

Install Laravel UI

Laravel UI is an official package that contains the extracted UI parts from a Laravel project. To generate UI scaffolding, we first need to install the laravel/ui.

composer require laravel/ui

Once the laravel/ui package has been installed, you may install the frontend scaffolding using the ui Artisan command:

// Generate basic scaffolding...
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

// Generate login / registration scaffolding...
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

Then run this command:

npm install && npm run dev

We are done. Now continue with any Laravel project.

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.
Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development. If you enjoy my content, please consider supporting what I do!

Follow Buy me a coffeeBuy me a coffee

Leave a Reply

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