Rate this post

Last Updated on January 26, 2021 by Vikash Ekka

Install and setup Laravel 7 on Ubuntu 18.04 and 20.04 LTS
Install and setup Laravel 7 on Ubuntu 18.04 and 20.04 LTS

Hey guys, In this blog, I’m writing how to install and configure Laravel 7 on Ubuntu 18.04 LTS and Ubuntu 20.04 LTS from scratch with step by step example. The same instructions would be applied for Ubuntu 20.04 LTS.
Before we start installing Laravel 7, make sure that you have already installed LAMP (Linux, Apache, MySQL, and PHP). If not then you can follow the link to install and configure the LAMP stack on your system Link

Also Read:- How To Install Linux, Apache, MySQL, PHP (LAMP) on Ubuntu 16.04

Laravel is an open-source PHP framework that is designed for the faster development of MVC web applications in PHP.

Before move on you will need to make sure your server meets the following requirements. To do so install all php extension.

 Note:- PHP >= 7.2.5

  1. Install Composer
  2. Install Laravel 7
  3. Create and setup Database Connection for Laravel
  4. Apache Configuration
  5. Enable Laravel virtual host file and Apache2 Rewrite Module
  6. Restart Apache2 server 
  7. Access Laravel Application

Install Composer

In this blog, we will install Laravel 7 via composer. If the composer is not installed in your Ubuntu system. Enter the following command.

sudo apt install composer

The above command will install the composer in your Ubuntu system.

Install Laravel 7

For this blog, I’m installing laravel 7 in /var/www/html/  directory. To install Laravel 7 enter the following command.

cd /var/www/html/
composer create-project laravel/laravel vetechno –prefer-dist “7.*”

In the above command, my project name is “vetechno” you can replace it according to your project name. It will create a separate directory in the html folder. Before moving forward let’s set-up the correct  file permission for Laravel 7 else you will end up with 500 error

sudo chown -R www-data:www-data /var/www/html/vetechno/
sudo chmod -R 755 /var/www/html/vetechno/

Create and setup Database Connection for Laravel

Next, we have to set-up the MySQL database for Laravel 7. Login to your MySQL server and create a MySQL database and user.

mysql -u root -p

mysql> GRANT ALL ON vetechno.* to ‘laravel’@’localhost’ IDENTIFIED  BY ‘pass##123’;
mysql> quit

Next, Go to /var/www/html/vetechno and rename the .env.example file to .env .Enter the following command

cp .env.example .env      OR     mv .env.example .env

Then enter the following command to generate the Laravel 7 Key

php artisan key:generate

Now edit the .env configuration file settings and update the database connection with the following code. Also, make sure APP_KEY is properly set as generated in the above command. 


Apache Configuration

Next, we will setup the virtual host configuration file to run the Laravel 7 project. To do so enter the following command to create an apache2  configuration file call the laravel-vetechno.conf file

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

Now copy and paste the below code and save it.

<VirtualHost *:80>   
ServerAdmin [email protected]
DocumentRoot /var/www/html/vetechno/public
ServerName laravelblog.local

<Directory /var/www/html/vetechno/public>
Options +FollowSymlinks
AllowOverride All
Require all granted

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

Enable Laravel virtual host configuration file  and Apache2 Rewrite Module

Once the configuration is done. Then need to enable the newly created site. To do so enter the following command

sudo a2ensite laravel-vetechno.conf
sudo a2enmod rewrite

Access Laravel Application 

This command will start a development server at http://localhost:8000 

php artisan serve


Congratulations you have successfully installed and configured the Laravel 7 PHP framework on your Ubuntu system. Access Laravel application in your favorite web browser. If this blog really helpful then please do comment on the comment box. Please feel free to ask questions.

Also Read:- How to uninstall PHP, Apache and MySQL on Ubuntu 16.04

By Vikash Ekka

Hi All, My name is Vikash Ekka from India. I’m the founder and tech editor of https://www.vetechno.in. I have completed my Graduation in BCA. I love to write technical articles like Windows, Linux & MAC Tutorials, Tips, Tricks, How To fix, Tutorials About Ethical Hacking & Cyber Security Guide, and Software Review. Currently, I have been working as an IT professional since 2018.

Leave a Reply

Your email address will not be published. Required fields are marked *