Laravel is a web application framework based on PHP for building enterprise web applications. It’s a free and open web framework that follows model-view-controller (MVC) architecture and is based on Symfony. it provides elegant syntax that allows you to create applications with clean code and is easy to read and understand.

Laravel is an enterprise-grade web framework for building enterprise and robust full-stack web applications. Laravel applications can be delivered fastly without headaches, from the development process to the production.

Pairing the Laravel web framework with another framework such as React or Vue allows you to create a beautiful and interactive frontend. Also, its supports multiple databases including MySQL, PostgreSQL, SQLite, and SQL Server. Laravel also provides scaffolding for secure authentication.

In this guide, we’ll show you how to install Laravel step-by-step on Debian 12, so you can get started with the Laravel project. We’ll show you how to install Laravel with Apache2 web server, MariaDB, and PHP 8.2.

Prerequisites

Below is the requirement that you need to follow this guide:

  • A Debian 12 server.
  • A non-root user with administrator privileges.

Installing LAMP Stack

The first step you need to do is install the LAMP Stack (Apache2, MariaDB, and PHP) to your Debian server. Then, you will also verify both Apache2 and mariaDB services to ensure that the service is running.

Before installing packages, run the apt update command to update and refresh Debian repositories.

sudo apt update

Once the repository is updated, install the LAMP Stack (Apache2, PHP, and MariaDB) packages by executing the apt install command below. The following command also installs some of the PHP extensions that are needed by Laravel.

sudo apt install apache2 php php-curl php-bcmath php-json php-mysql php-mbstring php-xml php-tokenizer php-zip mariadb-server

Enter y to confirm and proceed with the installation.

<img alt="installing lamp packages" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/1-install-lamp-stack.png64cab3c3ec3a4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="424" loading="lazy" src="data:image/svg xml,” width=”750″>

With the LAMP Stack installed, run the below systemctl command to verify the apache2 and mariadb services. If the service running, you should get the output active (running).

sudo systemctl status apache2

sudo systemctl status mariadb

For apache2 service, you should get about put like this:

<img alt="checking apache2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/2-check-apache2.png64cab3c42346f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="252" loading="lazy" src="data:image/svg xml,” width=”750″>

And below is the mariadb service status.

<img alt="checking mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/3-check-mariadb.png64cab3c45b046.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="282" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the php command below to verify the PHP version and enabled modules on PHP. You should see PHP 8.2 installed with some modules enabled, such as curl, date, dom, and exif.

php -v

php -m

<img alt="check php version and module" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/4-check-php-version-extensions.png64cab3c487a13.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="382" loading="lazy" src="data:image/svg xml,” width=”605″>

Lastly, launch your web browser and visit your Debian server IP address (i.e: http://192.168.10.15/). If the installation is successful, you should get the index.html page of the Apache web server.

<img alt="default index" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/5-default-apache2-index.png64cab3c4e052e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="591" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring PHP

To install Laravel, there are some PHP extensions you must enable, such as fileinfo, mbstring, and openssl. You can enable those extensions via the php.ini file.

Use the following nano editor to open the PHP configuration file /etc/php/8.2/apache2/php.ini.

sudo nano /etc/php/8.2/apache2/php.ini

Uncomment the following lines to enable the extension fileinfo, mbstring, and openssl.

extension=fileinfo

extension=mbstring

extension=openssl

When finished, save the file and exit the editor.

Next, run the following systemctl command to restart the apache2 service and apply the changes.

sudo systemctl restart apache2

Then, ensure the PHP extensions fileinfo, mbstring, and openssl are enabled by running the php command below. 

sudo php -m

Now create a new phpinfo file /var/www/html/info.php using the below command. If your installation of PHP and Apache2 web server success, this will show you detailed information about your PHP installation.

echo "" > /var/www/html/info.php

Open up your preferable web browser and visit the server IP address followed by the path file info.php (i.e: http://192.168.10.15/info.php). If successful, you should see an output like this:

<img alt="phpinfo" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/6-phpinfo.png64cab3c536e19.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="631" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring MariaDB Server

After configuring PHP, you will be configuring your MariaDB server, which includes securing the MariaDB server via the mariadb-secure-installation utility, then creating a new database and user for your Laravel project.

First, run the mariadb-secure-installation command below to secure your MariaDB server installation. During the process, you will be asked for some of MariaDB configurations, input Y to confirm the configuration or n for No.

sudo mariadb-secure-installation

Below are some of the MariaDB settings that you will be asked about during the process:

  • Press ENTER when asked for the MariaDB root password.
  • Input n when asked about the unix_socket authentication method.
  • Input Y to set up a new password for the MariaDB root user. Then, input the new password and repeat.
  • Input Y to remove the default anonymous user from MariaDB.
  • Then, input Y again to disable remote login for the MariaDB root user.
  • Input Y to remove the default database test from MariaDB.
  • Lastly, input Y again to reload table privileges and apply the changes.

After configuring the MariaDB server, you need to create a new database and user for your Laravel project.

Log in to the MariaDB server via the mariadb command below. Input your MariaDB password when prompted.

sudo mariadb -u root -p

Now run the following queries to create a new database testapp, the user testapp, and the password password. Be sure to change the password in the following query.

CREATE DATABASE testapp;

CREATE USER [email protected] IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON testapp.* TO [email protected];

FLUSH PRIVILEGES;

<img alt="create database and user" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/7-create-database-user.png64cab3c5638ba.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="239" loading="lazy" src="data:image/svg xml,” width=”688″>

Next, run the query below to ensure the user testapp can access the database testapp.

SHOW GRANTS FOR [email protected];

The output below confirms that the user testapp can access the database testapp.

<img alt="check user privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/8-check-user-privileges.png64cab3c596e95.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="257" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, type quit to exit from the MariaDB server and complete this step.

Installing Composer

Laravel can be installed in many ways, and the easiest is to install it via Composer, the PHP package manager. Now, you will install the Composer to your Debian server.

To install the Composer PHP package manager, run the apt install command below. Type y when prompted to proceed with the installation.

sudo apt install composer

<img alt="installing composer" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/9-install-composer.png64cab3c5da698.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="493" loading="lazy" src="data:image/svg xml,” width=”729″>

After installation is finished, run the following command to locate the binary file of the composer and verify the composer version.

which composer

sudo -u www-data composer --version

The composer binary file is located at /usr/bin/composer and the composer 2.5.5 is installed.

<img alt="verify composer" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/10-install-verify-composer.png64cab3c607e3d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="171" loading="lazy" src="data:image/svg xml,” width=”525″>

Creating First Laravel Project

With everything in place, you’re ready to install and create the first Laravel project. You will create the first Laravel project with MariaDB as the database.

First, create a new document root directory /var/www/testapp for your project and change the ownership to www-data user via the command below. You’ll also create directories /var/www/.cache and /var/www/.config that will be used by Composer.

sudo mkdir -p /var/www/{.cache,.config,testapp}

sudo chown -R www-data:www-data /var/www/{.cache,.config,testapp}

Now move to the /var/www/testapp/ directory and run the composer command below to create the first Laravel project. Your first Laravel project is stored at /var/www/testapp/ directory.

cd /var/www/testapp/

sudo -u www-data composer create-project laravel/laravel .

During the installation, you should get a similar output like this:

<img alt="installing laravel" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/11-creating-laravel-project.png64cab3c63e2e6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="289" loading="lazy" src="data:image/svg xml,” width=”750″>

With the Laravel project created, next you will set up the database for your project via the .env configuration file. The .env file is used as the base configuration for your Laravel project.

Use the following nano editor command to open the .env file.

nano .env

Change the APP_URL parameter with the local domain name of your Laravel project. This way, you can access your project via a local domain name. In this case, the domain name is testapp.local.

APP_URL=http://testapp.local

Now change the database configuration DB_CONNECTION to mysql and change the details of DB_DATABASE, DB_USERNAME, and DB_PASSWORD with your details MariaDB database and user.

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=testapp

DB_USERNAME=testapp

DB_PASSWORD=password

When finished, save the file and exit the editor.

Now run the following command to migrate the database. This will create tables for the Laravel project.

sudo -u www-data php artisan migrate

<img alt="migrate database" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/12-migrate-the-database.png64cab3c6850a9.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="209" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring Apache Virtual Host

In the following step, you will create a new Apache2 virtual host configuration for your Laravel project. After that, you must activate the virtual host and verify Apache2 configurations, then restart the Apache2 web server to take effect.

Before creating Apache2 virtual host configuration for Laravel, you must enable the rewrite module on Apache2 via the command below.

sudo a2enmod rewrite

Use the following nano editor command to create the Apache2 virtual host configuration /etc/apache2/sites-available/laravel.conf.

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

Insert the following configuration and change the parameter ServerName with your domain name.

    ServerAdmin [email protected]

    ServerName testapp.local

    DocumentRoot /var/www/testapp/public

   

            Options FollowSymLinks

            AllowOverride None

   

   

            AllowOverride All

   

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

When finished, save the file and exit the editor.

Next, run the following command to activate the virtual host configuration laravel.conf and verify Apache2 configurations. If you’ve proper configurations, you should get the message such as Syntax OK.

sudo a2ensite laravel.conf

sudo apachectl configtest

Lastly, restart the apache2 service by executing the command below and applying the changes that you’ve made.

sudo systemctl restart apache2

<img alt="setup virtual host" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/13-setup-virtual-host-laravel.png64cab3c6bc09f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="411" loading="lazy" src="data:image/svg xml,” width=”696″>

Accessing Laravel

If you’re on a Linux client, modify the /etc/hosts file via the nano editor command below.

sudo nano /etc/hosts

If you’re on a Windows machine, modify the file C:WindowsSystem32driversetchosts.

Insert the domain name of your Laravel project and your Debian server IP address like this:

192.168.10.15   testapp.local

Save the file and exit the editor.

Lastly, launch your web browser and visit the local domain name of your Laravel project (i.e: http://testapp.local). If successful, you should get a similar page of Laravel like this:

<img alt="installing laravel" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/08/echo/14-laravel-installed.png64cab3c73ce44.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="480" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

In conclusion, you have installed Laravel with LAMP Stack (Apache2, MariaDB, and PHP) on the Debian 12 server. You’ve also installed Composer, the PHP package manager, and used it as the media installation for Laravel. With this in mind, you can now develop your application using the Laravel web framework and MariaDB as the database for your applications.