DebianLinuxTutorials

How To Install Laravel on Debian 11

Install Laravel on Debian 11

In this tutorial, we will show you how to install Laravel on Debian 11. For those of you who didn’t know, Laravel is an open-source PHP web framework, designed for the faster development of web applications. It is based on the Symfony framework. Laravel makes it easier to perform some common tasks such as authentication, routing, sessions, and caching. It has several useful features including, Artisan, Object-relational mapping, Template Engine, and many more.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Laravel web framework on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Laravel on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

Step 2. Installing the Apache Web Server.

You need to have installed Apache Web Server on your system. Run the following command to install it:

sudo apt install apache2

Step 3. Installing PHP.

Now we add the SURY repository to your system:

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Then, install PHP 8.0 using the following command below:

sudo apt update
sudo apt install php8.0

Additionally, the necessary packages will be installed, some of which are standard PHP 8.x extensions:

sudo apt install php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-xsl php8.0-apcu php8.0-curl php8.0-gmp php8.0-opcache php8.0-mbstring php8.0-pgsql php8.0-imagick php8.0-memcached php8.0-bz2 php8.0-ds php8.0-imap php8.0-cgi php8.0-mysql php8.0-cli php8.0-fpm php8.0-xml

After the installation has been completed, you can confirm the installation using the following command:

php -v

Step 4. Installing Composer.

Composer is a dependency package manager for PHP. To use Laravel, first install Composer:

curl -sS https://getcomposer.org/installer | php

Next, move the Composer binary to the system path using the following command:

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

Assign execute permission:

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

Verify the Composer version installed:

composer --version

Step 5. Installing Laravel on Debian 11.

Now we download the latest version of Laravel using the Composer:

cd /var/www/html
composer create-project --prefer-dist laravel/laravel laravel

Next, set proper permissions and ownership to the Laravel directory:

chown -R www-data:www-data /var/www/html/laravel
chmod -R 775 /var/www/html/laravel

Step 6. Configure Apache for Laravel.

Now create an Apache virtual host configuration file for Laravel:

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

Add the following lines:

<VirtualHost *:80>
    ServerName laravel.your-domain.com

    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www/html/laravel/public

    <Directory /var/www/html/laravel>
    Options Indexes MultiViews
    AllowOverride None
    Require all granted
    </Directory>

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

Save and close the file then enable the Apache virtual host and rewrite module with the following command:

sudo a2enmod rewrite
sudo a2ensite laravel.conf
sudo systemctl restart apache2

Step 7. Accessing Laravel Framework Web Interface

Once successfully installed, you can access your website on http://laravel.your-domain.com. A congratulations page as follow should greet you:

Install Laravel on Debian 11 Bullseye

Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing the latest version of the Laravel framework on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Laravel website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button