How To Set up Laravel on Debian 11

In this guide, you will learn How To Set up Laravel PHP Framework on Debian 11. Laravel is a powerful and easy-to-use PHP framework. In simple words, Laravel reuses the available parts of different frameworks that help to create a web application. Laravel has many amazing features that will increase web development speed.

This guide will show you the complete installation steps of Laravel on Debian 11.

How To Set up Laravel on Debian 11?

Before you start to set up Laravel, you must log in to your server as a root or non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Debian 11.

Also, you need a domain name that pointed to your server’s IP address.

Now follow the steps below to complete this guide.

Step 1 – Install Apache and PHP on Debian 11

To install Laravel, you need to have Apache and PHP installed on your server.

First, update your local package index with the following command:

apt update

Then, install Apache with the command below:

apt install apache2 -y

At this point, you need to install PHP and its extensions for Laravel on Debian 11.

First, install the required packages with the command below:

apt install apt-transport-https gnupg2 ca-certificates -y

Then, add the GPG key and PHP repository to your server with the following commands:

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

Note: This will help you to install the latest PHP on your server.

Run the system update again:

apt update

Now you can install PHP and its extensions with the following command:

apt install libapache2-mod-php php php-common php-xml php-gd php8.2-opcache php-mbstring php-tokenizer php-json php-bcmath php-zip unzip curl -y

Verify your PHP installation on Debian 11 by checking its version:

php -v
Output
PHP 8.2.6 (cli) (built: May 12 2023 07:48:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

Step 2 – Configure PHP For Laravel

Here you need to make some configuration changes to the PHP config file. Open the file with your favorite text editor, here we use the vi editor:

vi /etc/php/8.2/apache2/php.ini

Find the lines below and uncomment them by removing the “;” from the beginning of the line and changing them to:

cgi.fix_pathinfo=0 
date.timezone = US/Eastern

Note: Remember to set the correct timezone.

When you are done save and close the file.

Setp 3 – Install Composer To Set up Laravel on Debian 11

In this guide, you will install Laravel by using Composer on Debian 11. So you need to install Composer with the following command:

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

When your installation is completed, you will get the following output:

Output
All settings correct for using Composer
Downloading...

Composer (version 2.5.7) successfully installed to: /root/composer.phar
Use it: php composer.phar

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

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

Verify your Composer installation on Debian 11 by checking its version:

composer --version
Output
Composer version 2.5.7 2023-05-24 15:00:39

Step 4 – Install Laravel on Debian 11

At this point, you can start your Laravel installation. First, switch to your Apache webroot directory:

cd /var/www/html

Then, download and install Laravel by using the composer:

composer create-project --prefer-dist laravel/laravel laravel --ignore-platform-req=ext-curl

When your installation is completed, you will get the following output:

Output
81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].

No security vulnerability advisories found
> @php artisan key:generate --ansi

   INFO  Application key set successfully.

Next, you need to set the correct permissions and ownership to the Laravel directory with the following commands:

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

Step 5 – Configure Apache for Laravel

At this point, you need to create an Apache virtual host configuration file for Laravel. Create and open the file with your favorite text editor, here we use vi:

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

Add the following content to the file with your own domain name:

<VirtualHost *:80>
    ServerName domain-name

    ServerAdmin admin@example.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>

When you are done, save and close the file.

Now enable the Apache virtual host and rewrite the module with the following commands:

# a2enmod rewrite
# a2ensite laravel.conf

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

Step 6 – How To Access Laravel Web Interface?

At this point, you can access the Laravel web interface by typing your domain name in your web browser:

http://domain-name

You should see the following screen:

Laravel default page Debian 11

For more information, you can visit the Laravel Documentation page.

Conclusion

At this point, you have learned to Set up Laravel PHP Framework on Debian 11. By following the installation steps you can easily install your Apache and PHP in the latest version and use Composer to install your Laravel app on Debian 11.

Hope you enjoy it. You may be like these articles too:

How To Install and Secure Laravel on AlmaLinux 8

Install and Configure Laravel on Ubuntu 22.04

Install and Configure Laravel on AlmaLinux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!