Install Laravel and Basic Configurations

Install Laravel and Basic Configurations

Install Laravel and Basic Configurations

In this tutorial, we are going to install Laravel and do the basic configuration which needs in any Laravel project.

– Last tested on Laravel 11.x.

1 - Install Laravel

The Laravel framework has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:

  • PHP >= 8.2
  • Ctype PHP Extension
  • cURL PHP Extension
  • DOM PHP Extension
  • Fileinfo PHP Extension
  • Filter PHP Extension
  • Hash PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PCRE PHP Extension
  • PDO PHP Extension
  • Session PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Method 1: 

– You can also install Laravel using composer:

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

Method 2:

– You can install Laravel using Laravel installer:

# install installer
composer global require laravel/installer

# create project
laravel new my_porject

2 - 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:

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

3 - Handle specified key was too long error

To handle this error [[Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes]], go to this file app/Providers/AppServiceProvider.php and inside the boot method set a default string length:

use Illuminate\Support\Facades\Schema;

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

4 - 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

– Then run this command (to migrate database):

php artisan migrate

5 - Sample Blade File

After generating UI, we need to include CSS & JS in layouts/app.blade.php file. 

– Here’s an example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello from xdevspace.com!</title>

    {{-- vite --}}
    @vite(['resources/sass/app.scss', 'resources/js/app.js'])
</head>
<body>
<div class="container">
    <div class="text-center" style="margin: 50px 0 10px 0;">
        Hello from Shouts.dev!
    </div>
</div>
</body>
</html>

6 - Run the Server

– You can launch the local web server using this command:

php artisan serve

– Now, if you visit http://localhost:8000 Or http://127.0.0.1:8000, you'll see the output like:

Install Laravel and Basic Configurations

– Now you can start building something cool stuff!

All Comments