How to Install Laravel on Ubuntu 20.04

Install Laravel on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Laravel on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Laravel is a very popular open-source PHP framework with the expressive and elegant syntax used to design modern and beautiful web applications. Laravel aims to take the pain out of web development and make it an enjoyable and creative experience, turning web devs into web artisans.

Install Laravel on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install LAMP Stack.

You need to setup the LAMP stack on your Ubuntu system. If you haven’t done so already, use our traditional LAMP guide to set up Ubuntu to serve PHP before you continue.

Step 3. Install Composer.

Composer a dependency manager tool for PHP programming language. We will use it to download and install the Laravel Core and all the required Laravel components:

curl -sS | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Finally, verify that the composer installed correctly by running:

composer -V

Step 4. Install Laravel on the Ubuntu system.

First, clone the master branch of the Laravel from GitHub repository:

cd /var/www
git clone

Next, change 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 the directory permissions accordingly:

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:

mv .env.example .env

Then, generate base64 random number encryption key:

$ php artisan key:generate

Application key set successfully.

AFter generate random encryption, now we 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

Step 6. Creating a MariaDB database for Laravel.

Laravel uses the MariaDB database to store all its data like posts, pages, users, plugins and themes settings. Log in to your MariaDB server with the following command and enter your MariaDB root password:

mysql -u root -p

Once you’re in the MariaDB console, create a new database:

CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'secret-passwd';
GRANT ALL ON laravel.* to 'laravel'@'localhost';

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


Step 7. Configuring Apache for Laravel.

Create a new virtual host configuration file for your Laravel website, named

nano /etc/apache2/sites-available/

And add the following content to the file:

<VirtualHost *:80>    
      ServerAdmin [email protected]
      DocumentRoot "/var/www/laravel/public"

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

      <Directory /var/www/laravel/>
         Options FollowSymlinks
         AllowOverride All
         Require all granted

To enable the virtual host we have just created, run the following command:

ln -s /etc/apache2/sites-available/ /etc/apache2/sites-enabled/

For the new configuration to take effect, restart the Apache service by typing:

sudo a2ensite 
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 8. Setup Laravel.

Now you can access the Laravel web install wizard using an HTTP connection:

That’s all you need to do to install Laravel on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.