How To Install Laravel on Ubuntu 20.04 LTS

Install Laravel on Ubuntu 20.04

In this tutorial, we will show you how to install Laravel on Ubuntu 20.04 LTS. For those of you who didn’t know, 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 through the step by step installation Laravel on Ubuntu 20.04 Focal Fossa. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian based distribution like Linux Mint.

Install Laravel on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running these following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Install LAMP server.

A Ubuntu 20.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here.

Step 3. Installing Composer.

Composer a dependency manager tool for PHP programming language. To install Composer, type 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

Verify the installation of the composer run the below command:

composer -V

Step 4. Installing Laravel on Ubuntu 20.04.

The latest Laravel version is available under the Github repository. Now we download the latest version, and install it with the following command:

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

Next, switch to the Laravel directory and use the 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 we create the Laravel environment configuration file. You can do it by renaming the .evn.example file to .env. :

mv .env.example .env

Next, generate base64 random number encryption key, which used by the Illuminate encrypter service:

$ php artisan key:generate

Application key set successfully.

Then, edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated:

nano .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:HFdS7c9rhDp+AeHu7kcmeilanaq2BQ/1gfFWEpoAk=
APP_DEBUG=true
APP_URL=http://localhost
...

Step 6. Configure MySQL / MariaDB Database Laravel.

Create a MySQL database for your Laravel application:

CREATE DATABASE laravel;
CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL ON laravel.* to 'laravel'@'localhost';
FLUSH PRIVILEGES;
quit

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

Step 7. Configuring Apache web server for Laravel.

Now we edit the Apache default virtual host configuration file (ie: 000-default.conf) and update Document Root to the Laravel public directory:

nano /etc/apache2/sites-enabled/000-default.conf

Add the following lines:

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

Now, we can restart the Apache webserver so that the changes take place:

sudo systemctl restart apache2

Step 8. Accessing Laravel Web Interface.

Laravel will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com or http://server-ip-address and complete the required steps to finish the installation. If you are using a firewall, please open port 80 to enable access to the control panel.

Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing Laravel in Ubuntu 20.04 LTS (Focal Fossa) systems. 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!