Categories: Ubuntu

How to Install Laravel Framework on Ubuntu

Laravel is an open-source and cross-platform PHP framework that is hailed by web developers everywhere. Laravel is built by Symfony framework and works on model-view-controller pattern. It is highly regarded because it cuts down the grunt work and lets the developers do the real work.

In this article, You will learn how you can install and set up the Laravel framework on your Ubuntu System.

Prerequisites

  • Ubuntu Linux-based system
  • Terminal access
  • A user account with sudo privileges.

Note: The commands in this tutorial are executed on the Ubuntu 20.04 system. All the methods in the tutorial are valid for any Linux-based system.

Update & Upgrade the System

It is always the best practice to start any installation with the upgraded and updated system but it is necessary as Laravel does not work with PHP with a version lower than 7.2.

To update and upgrade your system, run the following command.

sudo apt update && apt upgrade -y

Install PHP

To install PHP on your system, run the following apt command.

sudo apt install php

Once you are done with the installation, check the installation version with the following command.

php -v

Now install the PHP extension with the same version with the following command.

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

Install curl

Run the following command to install curl if you do not have it installed.

sudo apt install curl

Install Composer

You need the Composer to manage dependencies in Laravel.

To install composer, run the following command.

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

Run the following command with your composer file path to run composer without sudo permission.

sudo chown -R $USER /usr/local/bin/composer/

Install Symfony

Laravel often uses the Symfony framework so it is best to install it along with Laravel.

To install Symfony run the following command.

composer create-project symfony/skeleton testproj

Change into the testproj directory and run the following command

run php -S 127.0.0.1:8000 -t public

Open the following link in the browser to verify the installation.

http://localhost:8000/

Install Laravel

Now that everything is set and running, install Laravel using the following composer command.

composer global require laravel/installer

Add Laravel to Path in Bashrc File

Once the Laravel installation is done, open the .bashrc file.

nano .bashrc

Then add the following line of code at the end of the file.

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Press Ctrl+O and Ctrl+X to save and exit.

Next source the bashrc file.

source ~/.bashrc

Create New Laravel App

Simply run the following command to create an application in Laravel.

laravel new [name of app]

Navigate to the application directory and run the following composer command.

cd [name of app]
composer install

Now run the following commands to get the encryption key and access to localhost.

php artisan key:generate --ansi
php artisan serve

Note the development server link and open it in the browser.

http://localhost:8001

You can see Laravel is up and running.

Conclusion

This article discusses the installation process of Laravel and all the necessary components to establish a bare-minimum configuration. You can keep using the installation as it is to learn the Laravel basics or add more components like databases or homestead to build elaborate web applications.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago