How to setup Laravel 10 on Ubuntu 22.04 LTS via Composer

How to setup Laravel 10 on Ubuntu 22.04 LTS via Composer
How to setup Laravel 10 on Ubuntu 22.04 LTS via Composer

In this tutorial, I am going to show you how to set up Laravel 10 on Ubuntu 22.04 LTS.

VersionPHP (*)ReleaseBug Fixes UntilSecurity Fixes Until
87.3 - 8.1September 8th, 2020July 26th, 2022January 24th, 2023
98.0 - 8.2February 8th, 2022August 8th, 2023February 6th, 2024
108.1 - 8.2February 14th, 2023August 6th, 2024February 4th, 2025
118.2Q1 2024August 5th, 2025February 3rd, 2026
Reference: Laravel Release Notes

What exactly is Laravel?

Laravel is a PHP web framework that is open source and used to create web applications. Its source code is available on GitHub and is licensed under the MIT License. As a result, it is both safe and free to use.

Laravel is compatible with any server platform, including cloud services. As a result, Laravel can be used in a variety of situations. Even better, because the platform has been around for a while, there are frequently simple solutions to complex problems. This means that our team can work more effectively for you.

Laravel’s goal is to provide out-of-the-box usability. Even better, because Laravel uses a Model-View-Controller architecture, it is extremely simple to use for developers.

Laravel’s first stable version was released in 2011. That is, the program has been running for more than ten years. When using the system, provides a plethora of resources from which to solve unique problems.

How Does Laravel Function?

It makes use of the MVC design pattern. The “Model” component of this framework represents the shape of the data on which the application operates. Its application is extremely versatile.

The “Controller” is the model’s interface. Assume a user wishes to make a new post. The controller will then update the model in order to retrieve the required information. The controller contains the majority of the application’s logic.

The “View” represents all of the HTML components of the application. The model and the controller interact with the view, which is a template. It is what the user is shown.

Why Should You Use Laravel?

Laravel is used by our team because of its functionality and efficiency. It aids in the acceleration of development, which can increase overall productivity. Something that our clients have grown to appreciate.

It also has significant security advantages. This, among other things, helps with data migration. We can also use the system to assist in the development of mobile applications for both iOS and Android.

In Laravel, tasks can also be scheduled. Periodically executed tasks can be implemented with various additions. The built-in ORM implementation is regarded as one of the best Object-Relational Mappers when compared to other frameworks. Database objects can be interacted with using expressive syntax.

Laravel Official Documentation – https://laravel.com/

Step 1: Install Apache Web Server To verify that an Apache system service exists

sudo systemctl status apache2

Install Apache2 on Ubuntu or you can follow alone the complete tutorial of installing LAMP stack on Ubuntu 22.04 LTS, so you can skip up to 03rd Step of this tutorial.

sudo apt install apache2

To check the Apache service status again:

sudo systemctl status apache2
Apache service
Check the Apache service status

Step 2: Install PHP

sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-curl

When the installation is finished, check the PHP version.

php --version

To create a test.php file on Apache’s root directory

sudo nano /var/www/html/test.php

Then add following lines to the test.php file.

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

Then press ctrl and x keys together for saving the test.php file

Now visit the following URL localhost/test.php. Then you can see the version of your PHP which you have installed now.

test.php
localhost/test.php

Step 3: Download and Install a Database Manager.

Following that, we’ll create a database for the Laravel application.

But first, we must set up a database server. Laravel supports the following database systems: MariaDB, MySQL, SQLite, Postgres, and SQL Server.

We’ll use the MariaDB database engine. To install MariaDB

sudo apt install mysql-server

To run MySQL secure installation

sudo mysql_secure_installation 

It will ask that whether you want to configure the VALIDATE PASSWORD PLUGIN on MySQL server.

Enter y for yes, or any other key to continue without enabling VALIDATE PASSWORD PLUGIN.

MySQL secure installation on Ubuntu

If your answer is yes, then you need to select the level of the password validation. If you enter 2 here, your password level will be the strongest level. Then the password that you enter in here needs to contain numbers, upper and lowercase letters, and special characters otherwise you may receive some errors.

Setting a new password for MySQL root user
Using existing password for root

press Y and press the ENTER key at each of the prompt. It will remove test database and some anonymous users, disable remote logins for the root user, and MySQL load these new rules, immediately to the respond the changes that you have made in each prompt.

MySQL minimal security script

Once you're done, type the following to see if you can log into the MySQL console:

sudo mysql
Checking MySQL is installed or not in the system

Type exit and hit enter key for quitting from the MySQL.

exit

Step 4: Install Composer

Composer is a PHP dependency package manager. It provides a framework for managing libraries, dependencies, and prerequisites. Install composer first before you can use Laravel. To Download the Composer

curl -sS https://getcomposer.org/installer | php
Install Composer
Install Composer on Ubuntu 22.04

To make sure that composer can be used globally and make it executable

sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer create-project --prefer-dist laravel/laravel [project_name]

When it is completed, navigate to the installation directory and verify the Laravel version.

cd [project_name]
php artisan serve
first Laravel 9 project
Laravel 10 Landing Page

Read more