MWZ

MINDWAREZONE

Installation of Laravel: A Complete Beginner's Guide

Laravel is one of the most popular PHP frameworks used for building modern web applications. It provides an elegant syntax, powerful tools, and a structured development environment that helps developers create secure and scalable applications efficiently.

Before creating your first Laravel application, make sure that your local machine has PHPComposer, and the Laravel installer installed. In addition, you should install either Node and NPM or Bun so that you can compile your application's frontend assets.  

In this tutorial, you'll learn how to install Laravel on your local machine step by step.

Prerequisites

Before installing Laravel, ensure that the following software is installed on your system:

  • PHP 8.1 or higher
  • Composer (PHP Dependency Manager)
  • MySQL or another supported database
  • A web server such as Apache or Nginx
  • Node.js and npm (optional, for frontend asset management)

You can verify your PHP installation by running:

php -v
            

To check whether Composer is installed:

composer -v
            

Step 1: Install Composer

Laravel uses Composer to manage dependencies.

If Composer is not installed, download it from the official Composer website and follow the installation instructions for your operating system.

After installation, verify it using:

composer -v
            

A successful installation will display the Composer version.

Step 2: Create a New Laravel Project

Open your terminal or command prompt and run the following command:

composer create-project laravel/laravel my-project
            

Replace my-project with your desired project name.

Composer will download Laravel and install all required dependencies.

Step 3: Navigate to the Project Directory

Move into the newly created Laravel project folder:

cd my-project
            

Step 4: Start the Laravel Development Server

Laravel includes a built-in development server.

Run the following command:

php artisan serve
            

You should see output similar to:

INFO Server running on [http://127.0.0.1:8000]

Open your browser and visit:

http://127.0.0.1:8000

If everything is configured correctly, the Laravel welcome page will appear.

Step 5: Configure Environment Settings

Laravel stores application configuration in the .env file.

Open the .env file and update your database settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=
            

Replace these values with your actual database credentials.

Step 6: Generate Application Key

Laravel uses an application key for encryption and security purposes.

Generate a new key using:

php artisan key:generate
            

You should receive a success message confirming that the application key has been set.

Step 7: Run Database Migrations

Laravel provides migrations to create database tables automatically.

Execute:

php artisan migrate
            

This command creates the default Laravel tables in your database.

Common Installation Issues

Composer Not Found

If you receive:

composer: command not found

Ensure Composer is installed correctly and added to your system PATH.

PHP Version Error

Laravel requires a supported PHP version. Verify your version using:

php -v
            

Upgrade PHP if necessary.

Database Connection Error

Double-check your database credentials in the .env file and ensure your database server is running.

Conclusion

Installing Laravel is straightforward when the required dependencies are in place. By following the steps above, you can quickly set up a Laravel development environment and start building powerful web applications. Once Laravel is installed, you can explore routing, controllers, models, migrations, and Blade templates to create dynamic and feature-rich websites.

Happy Coding!