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.
Version | PHP (*) | Release | Bug Fixes Until | Security Fixes Until |
---|---|---|---|---|
8 | 7.3 - 8.1 | September 8th, 2020 | July 26th, 2022 | January 24th, 2023 |
9 | 8.0 - 8.2 | February 8th, 2022 | August 8th, 2023 | February 6th, 2024 |
10 | 8.1 - 8.2 | February 14th, 2023 | August 6th, 2024 | February 4th, 2025 |
11 | 8.2 | Q1 2024 | August 5th, 2025 | February 3rd, 2026 |
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
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.
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
.
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.
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.
Once you're done, type the following to see if you can log into the MySQL console:
sudo mysql
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
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