How to install Laravel in Ubuntu?

Laravel is a free and open-source PHP web framework that is based on Symphony and works on Model View Controller (MVC) architectural pattern.

It aims at simplifying both the development and testing of applications by providing the required tools and components that are used in web development. So the developer need not start from scratch.

In this article, I will discuss how to install and set up Laravel on a Ubuntu system.

Prerequisites

To follow this guide you should have the following –

  • A system running Ubuntu Linux
  • Access to a user account with sudo privileges

Installing PHP

Before you install any package make sure to update the apt package index and upgrade package on your system –

sudo apt update &&  apt upgrade -y

Use the following command to install the default version of PHP from the Ubuntu package repository –

sudo apt install php

Press y then enter if it asks for confirmation.

At the time of writing this article php 7.4 is the latest default version available on Ubuntu.

Next, install the required PHP modules by using the given command –

sudo apt install php7.4-mbstring php7.4-xml php7.4-zip

You can verify PHP installation by using –

php -v

check php version

Installing Composer

Composer is a dependency manager for PHP. We will use it to download the Laravel core and install all necessary Laravel components.

We need curl utility so use the following command to install it on your system –

sudo apt install curl

To install the Composer, run the given command in your terminal –

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

You can verify the installation of the composer by checking its version –

composer --version

composer version

Installing Laravel

Run the composer command to install the Laravel in the my_app directory on your system –

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

This will fetch and install the required PHP package on your system.

Here Laravel will automatically create a file named .envwhich includes custom configuration variables including the database credentials.

Move to the created Laravel project directory –

cd my_app

Now start the development server by using the given command –

php artisan serve

Laravel can use SQLite, PostgreSQL, MongoDB, MySQL, or MariaDB databases to store all its data.

Verify the installation

Open your browser and enter the given URL –

http://127.0.0.1:8000

This will display the given Laravel page.

laravel page

Conclusion

Ok, so you have successfully installed and set up Laravel on the Ubuntu system. Now if you have a query then write us in the comments below.

Leave a Comment