Laravel is a widely-used open source web framework designed for PHP developers. It serves as an MVC framework, enabling the creation of both basic and intricate web applications using the PHP programming language. It strictly adheres to the MVC (model-view-controller) architectural pattern.
In this tutorial, we will guide you through the process of installing Laravel 9 (LTS) on Debian 11.
System Requirements
Before proceeding, please ensure that your system meets the following requirements:
- Apache Web server
- MySQL/MariaDB
- PHP >= 8.0.2 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
- Composer – an application-level package manager for the PHP
Update your operating system
To ensure that all existing packages are up to date, please update your Debian 11 operating system by following these steps:
$ sudo apt update && sudo apt upgrade -y
To install the Apache web server, please follow the steps below
To install the Apache web server, execute the following command:
$ sudo apt install apache2
Once the installation is complete, Apache should be running. However, if it is not running for any reason, you can start it by following these steps:
$ sudo systemctl start apache2
Next, enable Apache to start automatically during system boot:
$ sudo systemctl enable apache2
To install PHP and the necessary PHP extensions for your Laravel application, follow these steps:
First and foremost, Laravel 9 requires the latest version of PHP 8. However, PHP 8.1 is not included in the default repository of Debian 11. Therefore, you need to add the DEB.SURY.ORG repository to APT. To accomplish this, execute the following command to install the necessary packages:
$ sudo apt-get install ca-certificates apt-transport-https software-properties-common -y
After successfully installing all the packages, you can add the Sury repository to APT by running the following command:
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
Next, you need to download and add the GPG key by executing the following command:
$ wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -
Once you have completed the previous step, update the repository by running the following command:
$ apt-get update -y
Now, you can install PHP 8.1 by executing 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 correctly:
php -v
Output: 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
To install MariaDB and create a database, follow the steps below
You can install MariaDB by using the following command:
$ sudo apt install mariadb-server mariadb-client
Start the database server daemon and enable it to automatically start at the next boot by executing the following commands:
$ systemctl start mariadb $ systemctl enable mariadb
After successfully installing the database server, you can log into the MariaDB prompt by following these steps:
$ sudo mysql -u root -p
To create a database, a database user, and grant all privileges to the database user, execute 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)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT
Now we will Install Composer
To download Composer, use the following command:
$ curl -sS https://getcomposer.org/installer | php
In the next step 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
To verify the installed version of Composer, use the following command:
$ composer --version Output: Composer version 2.2.6 2022-02-04 17:00:38
To install Laravel 9 on Debian 11, follow the steps below
Navigate to the webroot directory and enter the following command:
$ cd /var/www/html
Now, proceed with the installation of Laravel by executing the composer command as follows:
$ sudo composer create-project laravel/laravel laravelapp
The command will generate a new directory named “laravelapp” and install all the necessary files and directories for Laravel.
Change the ownership of the Laravel directory to the web server user and adjust the permissions accordingly:
sudo chown -R www-data:www-data /var/www/html/laravelapp sudo chmod -R 775 /var/www/html/laravelapp/storage
Once the installation is complete, go to the installation directory and verify the Laravel version by executing the following command:
$ cd laravelapp
$ php artisan

To configure the Apache web server for Laravel, follow the steps below
Navigate to the “/etc/apache2/sites-available” directory and create a configuration file for your Laravel installation by executing the following command:
$ sudo nano /etc/apache2/sites-available/laravel.conf
Add the following content:
<VirtualHost *:80> ServerName your-domain.com ServerAdmin [email protected] DocumentRoot /var/www/html/laravelapp/public <Directory /var/www/html/laravelapp/> Options +FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined </VirtualHost>
Save the file and Exit.
Now enable the laravel virtual host:
$ sudo a2ensite laravel.conf
Now restart the Apache web server wit the following command:
$ sudo a2ensite laravel.conf
To access your Laravel application, follow these steps:
Open your browser and type your domain for eexample http://your-domain.com
That’s it! You have successfully installed Laravel 9 on Debian 11. If you have any questions, please feel free to leave a comment below.