How to Install Laravel on Ubuntu 20.04

How to Install Laravel on Ubuntu 20.04

Today in this post we learn How to Install Laravel on Ubuntu 20.04 and Ubuntu 21.04, Laravel is a PHP web application framework that is intended for the development of web applications following the model–view–controller (MVC) architectural pattern. It has an expressive, elegant syntax and provides tools needed for large, robust applications. In this tutorial, we will show you how to install Laravel on Ubuntu 20.04 and Ubuntu 21.04.

1. Connect to your server

To connect to your server via SSH as user root, use the following command:


and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number. Once logged in, make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

How To Install NodeJS On Linux

2. Install the MySQL Database server

MySQL is an open-source database management system. To install MySQL, run the following command:

$ apt-get install mysql-server

This will install MySQL 5.7 on your server. In order to improve the security of your MySQL server, we recommend that you run the mysql_secure_installation script by typing the following command:


This script will help you to perform important security tasks like setting up a root password, disable remote root login, remove anonymous users, etc.

How to Install GNOME 40.1 Stable Update on Ubuntu

3. Create a database for Laravel

Now, we will create our MySQL database for our Laravel site. Login to your MySQL server with the following command and enter your MySQL root password:

mysql -u root -p

In this section, we will create a new MySQL database laravel and assign user access to it to a new user admin_user with password Strong_Password

GRANT ALL PRIVILEGES ON laravel.* TO 'admin_user'@'localhost' IDENTIFIED BY 'Strong_Password';

Don’t forget to replace ‘Strong_Password’ with an actual strong password.

How to Build Linux Kernel From Scratch

4. Install PHP and required PHP modules

To install the PHP and all necessary modules, run:

sudo apt-get install php-cli php-mcrypt php-mbstring php-zip php-opcache php-gd php-xml

5. Install Composer

A composer is a dependency manager for PHP and of course Laravel, which you can install packages with. The composer will pull all the required libraries you need for your project.

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

How to Install Mesa Drivers on Ubuntu 20.04 LTS

6. Install Laravel on Ubuntu 20.04

Install the latest version of Laravel, using the composer create-project command:

sudo composer create-project --prefer-dist laravel/laravel my_project

If the installation is successful, you will see the following lines:

Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.
> @php artisan key:generate
Application key [base64:NEu4D2s1Ai8HHZL3wPnrl+BVpSmcm7dMTStIBtMgSn0=] set successfully.

By default, Laravel is configured to use MySQL(MariaDB), but you need to give it the right information to connect to the database that you just set up. Next, go to the /var/www/Html/my_project/config directory, open the database.php file with your favorite text editor, for example:

nano database.php

And update the database settings, replacing them with your own details:

 'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', ''),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'yourDBName'),
            'username' => env('DB_USERNAME', 'yourUserName'),
            'password' => env('DB_PASSWORD', 'yourPassword'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,

7. Server your application with Artisan serve command

Once the installation is completed you can use the artisan serve command to serve your application:

php artisan serve

The output should be something like this:

Laravel development server started: <>

You can now open your browser and access your new Laravel installation at:

How to Install Mate Desktop on Ubuntu Linux

8. Install and configure Apache webserver

In this part of the tutorial, we will show you how to install and configure Apache to serve your Laravel application. Run the following command to install Apache webserver from the official Ubuntu repositories:

apt-get install apache2

Change the ownership of the Laravel directory to the webserver user:

chown -R www-data:www-data /path/to/laravel
chmod -R 755 my_project/storage/

Create a new Apache virtual host with the following content:

sudo nano /etc/apache2/sites-available/
<VirtualHost *:80>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/my_project/public

<Directory /var/www/html/my_project>
AllowOverride All

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

Activate the virtual host by creating a symbolic link :

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

Your Laravel installation is now complete.  You have successfully installed Laravel on your Ubuntu 20.04 VPS. Visit the domain name with a web browser, you will see the Laravel default page.   That’s it. If you followed all the instructions properly now you should be able to access your Laravel installation on your Ubuntu 20.04 server.

If you are one of our web hosting customers, and use our optimized Laravel Hosting, you don’t have to install Laravel on Ubuntu 20.04 and Ubuntu 21.04, our expert Linux admins will set up and optimize your Laravel VPS, for you. They are available 24×7 and will take care of your request immediately. As a Laravel developer, you should be focusing on Laravel development and improving your code and leave the server work to us. PS. If you liked this post, on how to install Laravel on Ubuntu 20.04 and 21.04, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

Be the first to comment

Leave a Reply

Your email address will not be published.