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.
Requisites
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
When the download and installation is over, edit /etc/php/7.4/apache2/php.ini and change the following values:
cgi.fix_pathinfo=0 date.timezone = America/Argentina/Salta #set to your timezone
Composer
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 https://getcomposer.org/installer | 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
Laravel
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
Wait a while, until the following output
Publishing complete. > @php artisan key:generate --ansi Application key set successfully. root@debian11-uni:/var/www/html#
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 laravel.example.com #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 </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
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
Test
Open in your web browser the servername you just defined and see this beautiful error:
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:
*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:
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)