Home Linux ServerWeb Server How to install Laravel on Ubuntu 22.04

How to install Laravel on Ubuntu 22.04

by Thạch Phạm
Published: Last Updated on

Installing Laravel on Ubuntu 22.04 with 4 simple steps.


Laravel is a free, open-source PHP framework built to support software and application development, following the MVC (Model-View-Controller) architecture. Laravel is the most popular and extremely powerful PHP framework.

In this tutorial, AZDIGI will show you how to set up Laravel on Ubuntu 22.04 server with LAMP.

Implementation Guide

Step 1: Update the system

Before going into the installation, you should update the system according to the command:

AZDIGI Tutorial
sudo apt update -y && apt upgrade -y

Step 2: Install PHP & PHP extensions

In this section, we will install PHP and the necessary PHP extensions to run the Laravel Framework.

AZDIGI Tutorial
sudo apt-get install php libapache2-mod-php php-dev php-zip php-curl php-pear php-mbstring php-mysql php-gd php-xml curl -y

Then check if PHP has been installed successfully.

php -v
PHP 8.1.2 (cli) (built: Apr  7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Step 3: Install the Apache webserver

  • To install the Apache web server, run the command:
AZDIGI Tutorial
sudo apt install apache2
  • Enable and start with the system
AZDIGI Tutorial
sudo systemctl start apache2
sudo systemctl enable apache2

Step 4: Create the database for Laravel Application

Because in this tutorial we use LAMP, I recommend using MariaDB as the database system. However, you can choose other databases because Laravel supports many different database systems such as SQLite, MySQL, Postgres and SQL Server. Now we will go into the installation:

  • Install MariaDB
AZDIGI Tutorial
sudo apt install mariadb-server -y
sudo mysql_secure_installation

To know how to set up MariaDB, you can see more instructions here. (Mariadb installation section)

  • Login to the MariaDB server
AZDIGI Tutorial
sudo mysql -u root -p
  • Create the database for the Laravel application.
AZDIGI Tutorial
MariaDB [(none)]> create database laravel;
MariaDB [(none)]> grant all privileges on laravel.* to 'laravel'@'localhost' identified by 'mypassword';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
How to install Laravel on Ubuntu 22.04

Step 5: Install Composer

Composer is a PHP package manager that provides a standard format for managing PHP software dependencies and required libraries.

  • Install Composer
AZDIGI Tutorial
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
How to install Laravel on Ubuntu 22.04

Then check if Composer has been installed successfully.

composer --version
Composer version 2.3.5 2022-04-13 16:43:00

Step 6: Install Laravel Framework

  • First, you need to create a folder to save the project:
AZDIGI Tutorial
sudo mkdir /var/www/laravel
  • Move to the newly created folder.
AZDIGI Tutorial
cd /var/www/laravel
  • With Composer installed, we can now install Laravel as follows:
AZDIGI Tutorial
composer create-project laravel/laravel myapp --prefer-dist

Note: Replace myapp with your project name.

How to install Laravel on Ubuntu 22.04
  • Check the Laravel version, go to your project.
AZDIGI Tutorial
cd myapp
php artisan
How to install Laravel on Ubuntu 22.04
  • Assign project directory permissions to www-data (Apache user).
AZDIGI Tutorial
sudo chown -R www-data:www-data /var/www/laravel
sudo find /var/www/laravel/ -type d -exec chmod 755 {} \;
sudo find /var/www/laravel/ -type f -exec chmod 644 {} \;


Step 7: Create Virtual Host for Laravel Application

  • Create a virtual host with the command:
AZDIGI Tutorial
nano /etc/apache2/sites-available/laravel.conf

Add the following content to the file you just created:

<VirtualHost *:80>
     ServerAdmin admin@azdigi.space
     DocumentRoot /var/www/laravel/myapp/public
     ServerName laravel.azdigi.space

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     <Directory /var/www/laravel/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted


Note: Replace azdigi.space with your domain name.

  • Activate the newly created virtual host
AZDIGI Tutorial
sudo a2ensite laravel.conf
systemctl reload apache2
  • Enable mod_rewrite Apache
AZDIGI Tutorial
sudo a2enmod rewrite
systemctl reload apache2
  • Restart Apache
AZDIGI Tutorial
sudo systemctl restart apache2

Step 8: Access the Laravel application

After completing the Laravel application installation, you will access your application with the name set up in step 7. Before that, I named the application laravel.azdigi.space, and below is my result:

How to install Laravel on Ubuntu 22.04

So AZDIGI has completed the installation and configuration steps of Laravel on Ubuntu 22.04. Hopefully, this article will be helpful to you. Wishing you success!

You can refer to other instructions at the link below:

If you need support, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign