How to install Laravel on Debian 11

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"

Laravel is a web application framework with expressive, elegant syntax. In this article I will show you how to easily install Laravel on Debian 11.

Also (spoiler alert), I will show you how easily is to commit a mistake, but to correct it later 😉

If you are working with CentOS and Nginx (I’ll be using apache), here on unixcop we have an article about Laravel with Nginx on CentOS.


Apache and PHP

To install Laravel you need a web server (I’m using apache in this tutorial) and PHP. You can skip this section if you already have it. In case you don’t have it yet, run the following command as root (with sudo or su)

apt-get update; apt-get install apache2 libapache2-mod-php php php-common php-xml php-gd php-opcache php-mbstring php-tokenizer php-json php-bcmath php-zip unzip curl
installing Laravel prerequisites

When the download and installation is over, edit /etc/php/7.4/apache2/php.ini and change the following values:

date.timezone = America/Argentina/Salta #set to your timezone


From the composer website: «Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.»

To install it run:

curl -sS | php
cp composer.phar /usr/local/bin/composer
composer --version

The first command downloads and install composer in your current path.

The second one copy the executable binary to make it available system wide. You actually need to be root only to copy to /usr/local/bin.

The third one is just a test. Also is not mandatory but not recommended to run composer as root. Pay attention to the warning

how to install php composer on debian 11
composer installed


Install Laravel on Debian 11

Now it’s time to actually install Laravel. Just go to the apache document root (i.e. /var/www/html) and run

cd /var/www/html
composer create-project --prefer-dist laravel/laravel laravel
actually install laravel on debian 11
installing Laravel

Wait a while, until the following output

Publishing complete.
> @php artisan key:generate --ansi
Application key set successfully.

Apache configuration

We will put laravel in a new virtual host. Create /etc/apache2/sites-available/laravel.conf with the following content:

<VirtualHost *:80>
        ServerName #remember to set the dns!    

        ServerAdmin gonz@localhost
        DocumentRoot /var/www/html/laravel/public

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

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
laravel virtualhost file
apache configuration

Run the following three commands to made sure mod_rewrite is enabled, to enable this new virtual host and to restart apache to apply changes:

a2enmod rewrite
a2ensite laravel.conf
systemctl restart apache2


Open in your web browser the servername you just defined and see this beautiful error:

how to install laravel on debian 11. Fail!

This was on purpose(?), remember when I composer create-project –prefer-dist/laravel etcétera? If you where paying attention (I wasn’t) to the screenshot, there was a warning about not running composer as root. Now I have a file permissions issue, let’s check:

all your files are belong to root* and apache runs with www-data user

*pun intended

We can fix this by setting proper permissions:

chown -R www-data:www-data laravel
chmod -R 755 laravel

Let’s try again:

how to install laravel on debian 11. Success

It’s that easy to install Laravel on Debian 11. Now I only need to figure what this Laravel thing is or how to use it.

On a second thought, that’s developer problem, I’m just the SysAdmin (and I’m pretty sure he already knows laravel)

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"
Gonzalo Rivero
Gonzalo Rivero
I am Gonzalo, I live in Salta, a city located in the NW of Argentina. I play the guitar and a little harmonica. I also like to bike.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook