Site icon LinuxTuto

How to Install Laravel 9 on Debian 11

How to Install Laravel 9 on Debian 11

Laravel is a popular open source web framework built for PHP developer. It’s an MVC framework for building simple to complex web applications using the PHP programming language, and it strictly follows the MVC (model–view–controller) architectural pattern.

In this tutorial we will show you how to install Laravel 9 (LTS) on Debian 11.

System prerequisites

Your system will need to satisfy the requirements below before proceeding.

Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade -y

Install Apache web server

To install Apache web server, run the following command:

$ sudo apt install apache2

Once installed, Apache should be running. If it’s not, for whatever reason, start it:

$ sudo systemctl start apache2

Then enable it to start on boot time.

$ sudo systemctl enable apache2

Install PHP and PHP extensions for Laravel Application

First and most importantly, Laravel 9 requires the latest PHP 8.

By default, PHP 8.1 is not included in the Debian 11 default repository. So you will need to add the DEB.SURY.ORG repository to APT.

First, install the required packages using the following command:

$ sudo apt-get install ca-certificates apt-transport-https software-properties-common -y

Once all the packages are installed, add a Sury repository to APT using the following command:

$ echo "deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list

Next, download and add the GPG key with the following command:

$ wget -qO - | apt-key add -

Once you are done, update the repository with the following command:

$ apt-get update -y

Now, you can install the PHP 8.1 using the following command:

$ sudo apt-get install php8.1 libapache2-mod-php php8.1-dev php8.1-zip php8.1-curl php8.1-mbstring php8.1-mysql php8.1-gd php8.1-xml

Verify if PHP is installed.

php -v
PHP 8.1.2 (cli) (built: Jan 27 2022 12:22:31) (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

Install MariaDB and create a database

You can install MariaDB with the following command:

$ sudo apt install mariadb-server mariadb-client

Note: If you want newer version of MariaDB you can follow our tutorial here.

Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

$ systemctl start mariadb
$ systemctl enable mariadb

Once the database server is installed, log into the MariaDB prompt:

$ sudo  mysql -u root -p

To create a database, database user, and grant all privileges to the database user run the following commands:

MariaDB [(none)]> CREATE DATABASE laravel_db;
MariaDB [(none)]> CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'Password';
MariaDB [(none)]> GRANT ALL ON laravel_db.* TO 'laravel_user'@'localhost';
MariaDB [(none)]> EXIT

Install Composer

To download Composer, run the following command:

$ curl -sS | php

Next, move the composer file to the /usr/local/bin path.

$ sudo mv composer.phar  /usr/local/bin/composer

Assign execute permission:

$ sudo chmod +x   /usr/local/bin/composer

Verify the Composer version installed:

$ composer --version

Composer version 2.2.6 2022-02-04 17:00:38

Install Laravel 9 on Debian 11

Navigate to the webroot directory, type:

$ cd /var/www/html

Now, install Laravel using the composer command, type:

$ sudo composer create-project laravel/laravel laravelapp

The command creates a new directory called laravelapp and installs all the files and directories for Laravel.

Change the ownership of the Laravel directory to the webserver user and also the permissions:

sudo chown -R www-data:www-data /var/www/html/laravelapp
sudo chmod -R 775 /var/www/html/laravelapp/storage

Once the installation is done navigate to the installation directory and check the Laravel version:

$ cd laravelapp
$ php artisan
Framework 9.0.2

Configure Apache Web Server for Laravel

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your Laravel installation:

$ sudo nano /etc/apache2/sites-available/laravel.conf

Add the following content:

<VirtualHost *:80>


DocumentRoot /var/www/html/laravelapp/public

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

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined


Save the file and Exit.

Enable the laravel virtual host.

$ sudo a2ensite laravel.conf

Restart the Apache web server.

$ sudo systemctl restart apache2

Access your Laravel Application

Open your browser and type your domain e.g

Comments and Conclusion

That’s it. You have successfully installed Laravel 9 on Debian 11.

If you have any questions please leave a comment below.

Exit mobile version