Install Laravel and Basic Configurations

Last modified on September 9, 2020 1 min read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

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

Table of Contents

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

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.3
  • 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
 * Run one command only
 */
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

/**
 * Generate login / registration scaffolding
 * Run one command if needed auth or skip this
 */
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

Then run this command:

npm install && npm run dev

Sample Blade File

After generating UI, we need to inlcude CSS & JS in our blade file. Here’s an example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello from MyNotePaper!</title>
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="text-center" style="margin: 50px 0 10px 0;">
            Hello from MyNotePaper!
        </div>
    </div>

    <script src="{{ asset('js/app.js') }}"></script>
</body>
</html>

We are done. Now continue with any Laravel project.

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

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