Laravel is a widely-used PHP framework that has gained popularity among developers for building modern web applications. It is an open-source framework that follows the model-view-controller (MVC) architectural pattern.
Created by Taylor Otwell and built on top of Symfony, Laravel was designed as an alternative to the CodeIgniter framework.
In this guide, we will walk you through the process of installing Laravel on Ubuntu 22.04 / Ubuntu 20.04.
How-to install PHP 8 on Ubuntu 22.04
Laravel necessitates PHP version 8 or a more recent release. Ubuntu 22.04 includes PHP 8.1 by default, eliminating the need to obtain PHP packages from external repositories. However, in the case of Ubuntu 20.04, you will have to configure the Ondřej Surý repository in order to install PHP 8.1.
Install PHP and other important extensions with the below command:
sudo apt update
sudo apt install -y php php-common php-cli php-gd php-mysqlnd php-curl php-intl php-mbstring php-bcmath php-xml php-zip
Then, check the PHP version post the installation of packages:
PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS)
right (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologie
Installing PHP Composer on Ubuntu 22.04
Installing Composer, a PHP dependency manager that facilitates the downloading and installation of Laravel along with its essential components for application development.
sudo apt install -y curl
curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/bin –filename=composer
Then, verify the composer version.
Composer version 2.3.5 2022-04-13 16:43:00
Guideline for Installing Laravel on Ubuntu 22.04
Once you have successfully installed PHP Composer on your system, you can utilize it to create a new Laravel project.
composer create-project laravel/laravel my_example_app
Now, go to the project directory.
Then, start Laravel’s local development server using the
artisan serve command.
php artisan serve
You will get the message something like this.
Starting Laravel development server: http://127.0.0.1:8000
[Wed Apr 27 23:28:24 2022] PHP 8.1.5 Development Server (http://127.0.0.1:8000) started
By default, Laravel listens on the localhost with port 8000. However, you can use the –host and –port options to change the listening IP address and port of Laravel, respectively.
php artisan serve –host 192.168.0.10 –port 8000
To access the Laravel development server, open your web browser and enter the IP address and port number provided in the previous command output.
Upon accessing the server, you will be greeted with the following web page.