Install Laravel on Ubuntu



PHP is known as an older language that serves almost 60% of websites around the world. Due to its simplicity and stability, some popular web technologies are based on PHP, one of them being Laravel.

Laravel is a well-known backend framework that provides developers with all the tools needed to build robust and secure web applications. Laravel is on the list of top web technologies and frameworks used to build web apps.

Because it's a PHP based framework, it's easy to use and learn, which makes it a great choice for beginner level developers starting their journey into web development, especially for backend development.

In this tutorial, we will learn how to install and use Laravel on Ubuntu, step by step.

Install Required PHP Packages

Before you start installing Laravel, you first need to have some PHP plugins installed alongside the PHP version itself. For Laravel, we need to have a PHP version higher than 8. These are dependencies for Laravel and are required to be installed on the system to work with Laravel on an Ubuntu machine.

First, update your system to make sure it is up to date:

sudo apt update && sudo apt upgrade -y

This command upgrades the packages. We use the apt package manager, so we need to get the most updated versions of the packages.

Then, use this command to install the desired plugins and dependencies ?

sudo apt install php php-cli php-mbstring php-xml php-bcmath php-json php-zip php-curl unzip -y

This command will install PHP, PHP CLI, along with some other plugins.

Note: If you are using an older version of Ubuntu or an Ubuntu-based distribution, make sure to check the available PHP version before proceeding with the installation.

To check the PHP version that will be installed with the previous command, use the following ?

apt show php

This command will let you know which version of PHP will be installed using APT. If it's an older version, make sure to get an updated version of PHP first. Using the updated version is always recommended to ensure security and access to the latest features of the language.

Install Apache Server

For Laravel to work, a server is needed behind the scenes. There are other options to use as a server, but the most popular and easy to use server is Apache.

Apache Server is an open-source project used to serve web applications to the internet. Because it's fast and powerful, it is one of the most popular web servers out there.

If you are on an Ubuntu machine and need to check whether Apache exists, you can use the command ?

sudo systemctl status apache2

It requires root access, so you will need to enter the password. This will show the status of the Apache server; if it's not installed, you will see this output ?

Unit apache2.service could not be found.

After we check that we don't have the server, we need to install it on Ubuntu using the command ?

sudo apt install apache2

After the installation is completed, Ubuntu by default starts the server. If we check the status again using the command ?

sudo systemctl status apache2

We will get an output like this ?

This means we have Apache installed and running (active).

To be sure, let's open a browser and navigate to 127.0.0.1. If you are on a server, replace it with the server IP. You should get a page like this:

This means your Apache server is installed and running successfully.

Install Composer

Composer is a package or dependency manager for PHP. It's used to download PHP libraries and dependencies that we need.

In our case, we will use Composer to download Laravel.

First, install Composer using the following command ?

curl -sS https://getcomposer.org/installer -o composer-setup.php

Install Composer globally on your system ?

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

This will run the installer and make Composer global.

Install Laravel

Now we have all dependencies needed to get started using Laravel. First, create a project folder of your choice, navigate to this folder, and run the following command to kickstart a Laravel project ?

composer create-project laravel/laravel your_project_name

Replace your_project_name with the name of your project. Once this is done, you're good to go and can start using Laravel and practicing with the project.

To serve the project and see the result in the browser, use the command ?

php artisan serve

This will set the server up and running, and if you navigate to the URL 127.0.0.1:8000, you should see the Laravel start screen.

Conclusion

PHP is one of the most widely used languages and will be for a long time. It serves millions of websites around the world, and one of the best frameworks PHP has is Laravel. As a PHP developer, it is necessary to learn how to use Laravel.

In this tutorial, we show how to install Laravel on Ubuntu, step by step.

Updated on: 2024-11-21T12:05:33+05:30

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements