Laravel - Installation

Laravel - Installation

Laravel is a powerful PHP framework that makes building complex web applications a breeze. In this guide, you’ll learn how to install and configure Laravel and get your first Laravel project running on your computer.
 

Prerequisites

Before we start, make sure you have:

  • Basic knowledge of PHP
  • PHP installed on your system
  • Basic familiarity with the Terminal or Command Prompt

 

You will have to follow the steps given below for installing Laravel onto your system −

Steps to Install Laravel

Step 1 — Install Composer

Laravel uses a dependency manager called Composer to install all the required libraries.

Visit the following URL and download Composer:
👉 https://getcomposer.org/download/

Follow the installation instructions provided on the website. It’s well-documented and straightforward.

Step 2 — Confirm Composer Installation

After installing Composer, verify the installation by running the following command in your terminal or command prompt:

composer

If you see an output similar to this (a list of Composer commands and options), Composer has been installed successfully:


   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.7.2 2024-03-11 17:12:18

Usage:
  command [options] [arguments]

– Now we’re ready to move on to installing Laravel!

 

Step 3 — Install Laravel

Now that Composer is ready, let’s install Laravel globally so you can use the laravel command from anywhere on your system.

Run the following command in your terminal:

composer global require laravel/installer

– This will install the Laravel installer globally.

Once the Laravel installer is ready, you can create a new Laravel project with this command:

laravel new project-name

Replace project-name with the name you want for your project.

For example:

laravel new myapp

This command will create a new Laravel application in a folder called myapp.

 

Step 4 — Create a New Laravel Project

There are multiple ways to create a new Laravel project using Composer. Here are the two most common methods:

Method 1 — Install Laravel into the Current Directory

If you’ve already created and navigated into your desired project directory, you can run:

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

– This will install Laravel into the current directory.

Method 2 — Install Laravel and Automatically Create a New Directory

You can skip manually creating a folder and let Composer create the project directory for you. Simply run:

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

This will:

  • Create a new folder named myapp
  • Install the latest stable Laravel version into it

Tip: Replace myapp with your preferred project name.

 

Step 5 — Start the Laravel Development Server

Navigate to your project directory:

cd myapp

Then, start the built-in Laravel development server:

php artisan serve

You should see something like:

Starting Laravel development server: http://127.0.0.1:8000

Now open http://127.0.0.1:8000 in your browser, and you’ll see the Laravel welcome page! 🎉

Congratulations!

You’ve successfully installed and configured Laravel, and your first Laravel project is running.