Select Page

Laravel is a free and open-source PHP framework that implements the MVC (Model-View-Controller) design pattern. Taylor Otwell created it in 2011 as an attempt to provide an advanced alternative to the CodeIgniter (CI) framework.

In 2011, Laravel released version 1 and version 2. The latest version 8.x comes with more and improved features like versioning scheme, support policy, Blade Component Tags & Improvements, Fluent String Operations, Route Model Binding Improvements, etc.

This tutorial will show you how to install the latest Laravel version 8.x with the Apache webserver on Ubuntu 20.04 Server. We will show you two different ways of installing the Laravel web framework on the Linux Ubuntu system.


  • Ubuntu 20.04 System
  • 2 GB or more RAM
  • Root privileges
  • Understanding the Basic Usage of Debian/Ubuntu System

What will we do?

  • Install Apache Web Server
  • Install and Configure PHP 7.4
  • Install Composer PHP Packages Management
  • Install Laravel Web Framework
  • Set Up Apache Virtual Host for Laravel Project
  • Testing

Step 1 – Setup Ubuntu for production

First, we need to setup and configure ubuntu for our production. change the file for your need and paste to your terminal.

sudo su

apt update && apt upgrade -y



rm /etc/localtime; ln -s /usr/share/zoneinfo/$TIME_ZONE /etc/localtime 
ls -la /etc/localtime

# Kernel hostname 
# Kernel domain name
kernel.domainname=`echo $DOMAINNAME`” >> /etc/sysctl.conf

echo -e “\t`echo $HOSTNAME`.`echo $DOMAINNAME` `echo $HOSTNAME`” >> /etc/hosts
echo -e “::1\t`echo $HOSTNAME`.`echo $DOMAINNAME` `echo $HOSTNAME`” >> /etc/hosts

sudo hostnamectl set-hostname $HOSTNAME
sysctl -p /etc/sysctl.conf
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
# Set SSHD value for user
mkdir ~/.ssh

# Backup sshd settings
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults

sed -i ‘s/GSSAPIAuthentication yes/GSSAPIAuthentication no/’ /etc/ssh/ssh_config
echo ‘UseDNS yes’ >> /etc/ssh/sshd_config

# allow ssh root login
sudo sed -i ‘s/#PermitRootLogin prohibit-password/PermitRootLogin yes/’ /etc/ssh/sshd_config
# Enable root file edit for WinSCP
sudo echo 
#### added
sysadmin ALL=NOPASSWD: /usr/lib/openssh/sftp-server’ >> /etc/sudoers

service sshd restart

Step 2 – Install apache web server

we will install the Apache webserver on the Ubuntu 20.04 system and setup the UFW firewall that only allows incoming connections for some services, including the SSH, HTTP, and HTTPS.

sudo apt update
sudo apt install apache2
systemctl start apache2
systemctl enable apache2

Step 3 – Install and Configure PHP 7.4

In this step, we will install and configure PHP 7.4 for our Laravel installation. To install the Laravel 8.x, at least you must have the PHP >= 7.2.5 on your system. And by default, the official Ubuntu 20.04 repository provides PHP 7.4 packages.

Install PHP 7.4 packages using the apt command below.

sudo apt install libapache2-mod-php php php-common php-xml php-gd php-opcache php-mbstring php-tokenizer php-json php-bcmath php-zip unzip

Once all installation is completed, go to the ‘/etc/php/7.4/’ directory and edit the ‘php.ini’ configuration for the Apache2 web server.

cd /etc/php/7.4/
vim apache2/php.ini Uncomment the 'cgi.fix_pathinfo' option and change the value to '0'.

Save and close.

Next, restart the Apache service to apply the new ‘php.ini’ configuration.

systemctl restart apache2

Step 4 – Install Composer PHP Packages Management

Composer is a dependency manager for PHP. It’s an application-level package manager for PHP that allows you to download additional PHP dependencies and libraries to your PHP project.

In this tutorial, we will be using the Composer for installing Laravel, and we will install the Composer by downloading the composer binary file from the official composer website.

Download the binary file of the Composer and move the file to the ‘/usr/local/bin’ directory.

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

After that, check the composer version using the following command.

composer --version

Step 5 – Install Laravel 8.x on Ubuntu 20.04

#install laravel.
cd /var/www/html/
composer create-project –prefer-dist laravel/laravel crm


sudo chgrp -R www-data /var/www/crm
sudo chgrp -R www-data /var/www/html/crm
sudo chmod -R 775 /var/www/html/crm/storage/


cd /etc/apache2/sites-available/
sudo nano laravel_project.conf
#past the below code
<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot /var/www/html/crm/public


   <Directory /var/www/html/crm>
       AllowOverride All
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
#save the file
#After that, disable the default configuration file of the virtual hosts in Apache with this command:


sudo a2dissite 000-default.conf


#Afterwards, enable the new virtual host:
sudo a2ensite laravel_project


#Enable the Apache rewrite module, and finally, restart the Apache service:
sudo a2enmod rewrite
sudo systemctl restart apache2


#setup login and register page for laravel 
apt install npm 


cd /var/www/html/crm 
composer require laravel/ui
php artisan ui vue –auth


npm install && npm run dev
#if you wanna access your phpmyadmin then 
sudo nano laravel_project.conf
<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot /var/www/html/crm/public
   DocumentRoot /var/www/html/


   <Directory /var/www/html/crm>
       AllowOverride All
   <Directory /var/www/html>
        AllowOverride All
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined


#rename .env to env and edit for database
cd /var/www/html/crm/
nano .env
#edit database information 
cd /var/www/html/crm/config/
nano database.php
#edit mysql database username,password.


#create a login database to migaration 
#php artisan make:model login -m
php artisan make:migration create_users_table
nano /database/migrations/create_users_table.php 
#add to the table


#migrate now
php artisan migrate            
#php artisan migrate:rollback
#if you wanna clean the database 
php artison db:wipeup