How to Install Magento 2 on Ubuntu 20.04 LTS — Step by Step Instruction

Magento 2 is a leading eCommerce platform that is used mostly by corporations due to the complexity of development and the ability to customize it to the specific needs of merchants. This open-source platform combines powerful features with a flexible and convenient interface. Below is the instruction on how to install Magento 2 on Ubuntu 20.04 LTS.


In this manual, we will show how to install Magento 2.4.2 on a computer with only Ubuntu 20.04 LTS. We will use L.A.M.P (Linux Apache MySql Php) as a web server.

First, we need to update the list of repository packages and update our packages:

sudo apt update && sudo apt upgrade

Beginning. Installation of the required packages for Magento 2.

Unzip — packages to work with archives.

#Installing unzip
sudo apt install unzip

Curl — it is short for “Client URL.” The tool is available on the majority of Linux systems and it is designed to check the connection to the URL addresses. Moreover, the command Curl – is a great tool to transfer data. 

#Installing CURL
sudo apt install curl

NodeJS – is an environment for the code execution on JavaScript that is based on the 

JavaScript Chrome V8 engine which allows to broadcast JavaScript into the machine code. Node.js is designed to create server applications in JavaScript.

#Installing NodeJS 10 version
curl -sL | sudo -E bash –
sudo apt-get install -y nodejs

Grunt — task manager for the automatic execution of the routine operations. It is written in JavaScript. We will use it for the transformations of styles from less to css.

#Installing grunt globally
sudo npm i grunt-cli -g

Installing php and apache2

#Installing php
sudo apt install php php-bcmath php-curl php-gd php-intl php-mbstring php-mysql
#Check version php
php -v

Important!!! It is vital to check the php version because if you install 8th versions, Magento 2 could be working with errors. 

#Install apache2

sudo apt install apache2


#Enable modules

sudo a2enmod rewrite

#restart apatche to enable the settings
systemctl restart apache2

Installation and creation of MySQL database

MySQL – is a popular database management system (DBMS) with a “client-server” model. That’s why you can frequently hear from other developers the phrase “MySQL-server”.

#Install mysql engine/client
sudo apt install mysql-server
#Check version MySQL.
mysql -V

Enter MySQL using the following command:

sudo mysql

1.Create database


2. Create user base

CREATE USER ‘YouUser’@’localhost’ IDENTIFIED BY ‘YouPassword’;
GRANT ALL ON *.* TO ‘YouUser’@’localhost’;
#See all bases:
show databases;

3. Exiting mysql>


If everything is done right, the result should be following:

Installing phpMyAdmin

PhpMyAdmit — allows administering the MySQL server from the browser, launching SQL commands and viewing the content of the database tables.

#Installation of phpmyadmin
sudo apt install phpmyadmin

In the window of the terminal select apache [with space], and move with TAB.

Address: http://localhost/phpmyadmin/
Login and password that were used during the creation of MySQL user. 

Preparation for the installation of Magento 2

You need to create a config file in the folder /etc/apache2/sites-available/.

I am launching the application Double Commander from the root and create the needed file. If you do not have one, you can install it.

#Install Double Commander
sudo apt install doublecmd-qt
#double commander open as root
sudo doublecmd
#Create new project virtual host file
<VirtualHost *:80>
ServerAdmin admin@magento2.loc
ServerName magento2.loc
ServerAlias magento2.loc
DocumentRoot /var/www/magento2.loc/pub
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/magento2.loc/pub>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

Let’s add our local site to hosts. magento2.loc
#Standard editor
sudo nano /etc/hosts
# I use third-party editor bluefish
sudo apt install bluefish
sudo bluefish /etc/hosts

Installation of Composer

#Installing Composer
sudo apt install composer
#composer version:
composer –version
#Preferably, it is important install the needed version:
composer self-update 1.10.6

Installation of elasticsearch engine

Elasticsearch engine —  is an open-source product that allows taking data from any source and any format, and also, searching and visualizing it in real time. In Magento 2, it is used for fast and advanced searches in the catalog of products.

#Download and install elasticsearch engine
shasum -a 512 -c elasticsearch-7.9.2-amd64.deb.sha512
sudo dpkg -i elasticsearch-7.9.2-amd64.deb

Create the file for the configuration in the folder: /etc/apache2/sites-available/elastic.conf

For this:

#Open double commander from root
sudo doublecmd
#Turn on proxy mod
sudo a2enmod proxy_http
#Apply new configuration:
sudo a2ensite elastic.conf
#And reload apache2
systemctl reload apache2

The content of the file elastic.conf:

Listen 8080
<VirtualHost *:8080>
ProxyPass “/” “http://localhost:9200/”
ProxyPassReverse “/” “http://localhost:9200/”

Creating folder for your Magento 2 store

Let’s create the folder for the Magento 2 store and grant the needed rights.

1. It is important to grant rights to the folder /var/www.

sudo chmod 777 /var/www/

2. If the rights were granted properly, we can use Double commander (not from root) to create and edit folders.

Create folder magento2.loc. In the end, should be the following: /var/www/magento2.loc

3. Assign the rights to all files and folders which Magento 2 will be creating during the installation.

sudo find /var/www/magento2.loc/ -type d -exec chmod 775 {} \;
sudo find /var/www/magento2.loc/ -type f -exec chmod 664 {} \;

Restart everything that is needed.

sudo service mysql restart
sudo service apache2 restart
sudo service elasticsearch restart
sudo systemctl enable elasticsearch

Check the work of Elastic

curl -i http://localhost:8080/_cluster/health

Magento 2 installation

1. Download Magento 2 from the official repository:

composer create-project –repository-url= magento/project-community-edition

Important!!! The command should be done in terminal in: /var/www/magento2.loc

#go the folder /var/www/magento2.loc
cd /var/www/magento2.loc

Before downloading, you need to write a login and password. It is Public Key & Private Key from the site If you do not have them, you need to get them. Sign up and create the access. 

Login: Public Key

Password: Private Key

Important!!! Magento 2 starts slowly downloading its own files on your device, until one moment, a terminal freezes for a long time. It is not an error. Everything is working fine. You can just come back in 10-15 minutes after the installation has been finished. 

If the error is related to Compose, it will appear immediately. In this case, you need to downgrade it to 1.10.6.

composer self-update 1.10.6
# Version composer
composer -v

2. Final command which will install and set up your store:

php bin/magento setup:install –base-url=http://magento2.loc/ –db-host=localhost –db-name=magento2 –db-user=eugene –db-password=password –admin-firstname=Eugene –admin-lastname=Eugene – –admin-user=eugene –admin-password=qwerty1991 –language=en_US –currency=USD –timezone=America/Chicago –use-rewrites=1 –backend-frontname=admin –search-engine=elasticsearch7 –elasticsearch-host=magento2.loc –elasticsearch-port=9200

The main data to create an admin and launch store.

base-url=http://magento2.loc/ – store’s address;

db-name=magento2 – database name;

db-user=eugene – database user login;

db-password=password – database user password;

admin-user=eugene – admin’s login;

admin-password=qwerty1991 – admin’s password;

backend-frontname=admin – address of admin panel.

The installation is complete at this point, and logically, your shop should be working by now. However, after opening an address, you might encounter 500 Internal Server Error. It will be only once, and it can be solved in one minute. 

Solution to 500 Internal Server Error

It is an issue with rights and you need to fix it.

eugene = Your username

sudo usermod -a -G eugene www-data
sudo usermod -a -G www-data eugene

After the restart of a system, everything should be working fine. 

If you do not know your username, you can use the following command:

#Who am I?

Installing test products

#Install test products:
php bin/magento sampledata:deploy
#And update settings
php bin/magento setup:upgrade
#Clear cache
php bin/magento cache:flush
#Enable all modules
php bin/magento module:enable –all
#Disable two-factor authentication
php bin/magento module:disable Magento_TwoFactorAuth
#And update settings
php bin/magento setup:upgrade
#Clear cache
php bin/magento cache:flush

If you have encountered an error:

Updating modules:

Could not validate a connection to Elasticsearch. No alive nodes found in your cluster


#Launch Elasticsearch
sudo service elasticsearch start
#And update settings
php bin/magento setup:upgrade
#Clear Cache
php bin/magento cache:flush


Having installed Magento 2, you can start working on the development of the store. In addition, if you need other tips on eCommerce development and learn about the industry itself, you can check our other articles from the blog. Join our Overdose Tech Club to share the development experience with other eCommerce enthusiasts and learn from industry professionals.

Related Articles

Notify of
Inline Feedbacks
View all comments