How To Install Laravel on Linux Mint 20

Install Laravel on Linux Mint 20

In this tutorial, we will show you how to install Laravel on Linux Mint 20. For those of you who didn’t know, Laravel is a very popular open-source PHP framework aimed at the easy development of applications. It is based on the Symfony framework and follows the model–view–controller (MVC) architectural pattern.

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 a Laravel on a Linux Mint 20 (Ulyana).

Install Laravel on Linux Mint 20 Ulyana

Step 1. Before running the tutorial below, 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 install software-properties-common

Step 2. Installing the LAMP stack.

A Linux Mint 20 LAMP server is required. If you do not have LAMP installed, you can follow our guide here.

Step 3. Installing Composer.

We are downloading and installing the Composer with the following commands:

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

Step 4. Installing Laravel on Linux Mint 20.

By default, Laravel is not available on the Linux Mint base repository. Now we clone the master branch Laravel from the Github repository:

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

Next, 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

Then, set proper permissions on files:

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

Step 5. Create Environment Settings.

Now create the Laravel environment configuration file:

mv .env.example .env

Next, create the key file with the PHP artisan command:

[email protected]:# php artisan key:generateApplication key [base64:EFk4kXxbmwe46+q/oF7hPnHm6mtechnsmfOMWd/qg=] set successfully.

After that, 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

Edit the following file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:EFk4kXxbmwe46+q/oF7hPnHm6mtechnsmfOMWd/qg=
APP_DEBUG=true
APP_URL=http://localhost
...

Step 6. Configuring MariaDB.

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

Next, we will need to log in to the MariaDB console and create a database for Laravel. Run the following command:

mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Laravel installation:

CREATE DATABASE laraveldb;
CREATE USER 'laraveluser'@'localhost' IDENTIFIED BY 'Your-Strong-Passwd';
GRANT ALL PRIVILEGES ON `laraveldb`.* TO 'laraveluser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Next, edit the .env file and update database settings:

nano .env

Add the following file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laraveldb
DB_USERNAME=laraveluser
DB_PASSWORD=Your-Strong-Passwd

Step 6. Configure Apache.

Now create an Apache virtual host configuration file for Laravel:

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

Add the following lines:

<VirtualHost *:80>

        ServerAdmin [email protected]
        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>

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 8. 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 Laravel PHP framework on the Linux Mint system. 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!