DebianLinuxTutorials

How To Install Laravel on Debian 10 Buster

Install Laravel on Debian 10 Buster

In this tutorial, we will show you how to install Laravel on Debian 10 Buster. For those of you who didn’t know, Laravel is a free, open-source PHP web application framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern. It is a pretty new framework, but with a big potential to become one of the most popular PHP frameworks.

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 the step-by-step installation of Laravel on a Debian 10 (Buster) server.

Prerequisites

  • A server running one of the following operating systems: Debian 10 (Buster).
  • 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 10 Buster

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

apt update
apt upgrade

Step 2. Installing Apache on Debian 9 Stretch.

We will be installing Apache with apt-get, which is the default package manager for Debian:

apt install apache2

After installing apache services on your system, start all required services:

systemctl enable apache2
systemctl start apache2
systemctl status apache2

Allow Apache HTTP server via the firewall:

ufw status
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
ufw enable

Step 3. Install MySQL.

Now that we have our web server up and running, it is time to install MySQL. MySQL is a database management system. Basically, it will organize and provide access to databases where our site can store information:

sudo apt install mysql-server php-mysql

Step 4. Installing PHP.

To install the latest stable version of PHP version 7 and all necessary modules, run:

sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip

Step 5. Installing Composer.

The composer is required for installing Laravel dependencies. So use the below commands to download and use as a command in our system:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Verify the installation by printing the composer version:

composer --version

Step 6. Installing Laravel on Debian.

At the time of writing this article, the latest stable version of Laravel is version 5.7:

cd /var/www
git clone https://github.com/laravel/laravel.git

Navigate to the Laravel code directory and use composer to install all dependencies required for the Laravel framework:

cd /var/www/laravel
sudo composer install

After successfully installing all dependencies, set the proper permissions on all files:

chown -R www-data.www-data /var/www/laravel
chmod -R 755 /var/www/laravel
chmod -R 777 /var/www/laravel/storage

Step 7. Set Encryption Key.

First, rename the .env.example file to .env in the project’s main directory. This will use to set up the application environment for the project:

mv .env.example .env

Then, generate a base64 random number encryption key:

php artisan key:generate

Edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated in the above command:

nano .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Wer9JfZHN4qYQBMWe46n1hLt8LWPeT3urzdI0hVqfzJM=
APP_DEBUG=true
APP_URL=http://localhost

Step 8. Setup MySQL Database

You may also require creating a database for your Laravel application. Login to your MySQL server and create MySQL database and user:

mysql> CREATE DATABASE laravel;
mysql> GRANT ALL ON laravel.* to 'laravel'@'localhost' IDENTIFIED BY 'your_secret_password';
mysql> FLUSH PRIVILEGES;
mysql> quit

Edit the .env file and update database settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=your_secret_password

Step 9. Apache Configuration

You can create a new Apache configuration file or edit Apache default virtual host configuration file 000-default.conf and update DocumentRoot to Laravel public directory as below:

nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/laravel/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>

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

</VirtualHost>

Reload Apache configuration changes by restarting the service:

sudo service apache2 restart

Step 7. Accessing Laravel.

Open your browser, type your domain, and assuming the installation is successful, a screen similar to the following will appear:

Install Laravel on Debian 10 Buster

Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing Install Laravel on Debian 10 Buster system. For additional help or useful information, we recommend you to 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button