Regardless of whether it’s B2B or B2C, an eCommerce platform is the backbone of an online enterprise. The best eCommerce platform also promotes the mechanism of the market interaction processes with clients, workers, and customers. Therefore, you can’t survive online if you don’t have a strong e-commerce site. Thus, in widening and growing the market, the right eCommerce platform plays a very important role, like Magento. In this blog, we’ll learn Magento 2.4 Installation On Ubuntu 20.04. You can also follow my blogs for Magento2.4 Installation on Windows and macOS.
You might ask why, although we have other hosting providers. I choose Magento as a platform for eCommerce. And AWS as a hosting provider. So, let’s just start to answer this simple question.
What’s The Magento, Exactly?
Magento is an open-source eCommerce platform. That provides online shoppers with a versatile shopping cart interface. And also provides control over their online store’s look, content, and usability of their online store. Therefore, it facilitates effective marketing, optimization of search engines, and tools for catalog management.
Why We’re Using AWS?
Generally, Cloud Computing allows an eCommerce platform to cater to the changing market demand and scenarios. It also offers scalable technology tailored to business needs. And allows upscale or downscale facilities depending on demand and traffic.
Additionally, Amazon Web Services (AWS) is the most advance and widely acceptable cloud platform in the world. That provides more than 175 fully integrated data center facilities worldwide. Furthermore, A million users use AWS to cut costs, to make themselves more agile, and to innovate faster.
Installation Requirements For Magento 2.4:
Operating systems (Linux x86-64)
- Distributions of Linux, including RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian, etc.
Memory requirement
- Magento2 requires 2GB or higher RAM.
Composer
- Composer 2.x cannot be supported by Magento.
Web servers
- Apache 2.4
- Nginx 1.x
Database
- MySQL 8.0
- MariaDB 10.4
PHP
Magento supports PHP 7.4.0
Elasticsearch
- As of 2.4.0 Magento, MySQL is no longer available for search purposes. You’re supposed to use Elasticsearch.
- Elasticsearch 2.x, 5.x, and 6.x are no longer supported by Magento.
To get detailed information about system requirements, just visit the mentioned link: https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html
What We’re Going To Use:
- OS: Ubuntu 20.04
- SERVER: Apache 2
- RAM: 1 GB (We’re using 1GB of RAM, so a swap memory is required)
- PHP: 7.4
- MY SQL: 8.0
- Composer: 1.10
- Elasticsearch: 7.10
Magento 2.4 Installation On AWS
So let’s move to the installation part.
STEP 1: Creation of AWS Account
(i) To start with, create a new AWS account by using Sign-up.

(ii) And then log in to your AWS account by Sign-in.

(iii) Also, select the webserver location ie AWS region from the list available. where you want to launch the EC2 instance. The option is at the top of the bar on the right-hand side.

STEP 2: Creation of EC2 Instance.
(i) After your account has been successfully created. Select the EC2 among the available AWS services. or you can search for an EC2 service in the search box.

(ii) And then Select the Launch Instance button from the dropdown menu.

(iii) Select the server ie, Ubuntu Server 20.04 LTS by scroll down or you can directly search in the search box.

(iv) Now choose the Instance type and click on the tab, Next: Configure Instance Details.

(v) After the above steps, select the number of EC2 Instances, you want to run and then choose the tab, Next: Add Storage.

(vi) Now add up the storage as per your requirement and select the tab, Next: Add Tags.

(vii) Add tags and choose the tab, Next: configure security group.

(viii) Now, Click Add rule in configure security group, and ADD the following :
SSH, HTTP, and HTTPS – select anywhere in the source column for all rules. Thus, after adding up the rules, select the review, and launch tab.

(ix) Under this step, review the instance launch to recheck your Instance settings one more time and if everything goes right, then select the launch button.

(x) This step is concerned with creating a key pair (It’s better to use the domain name for the key pair name) and after the creation, download the key pair.

(xi) Once the pem file is downloaded, adhere to the terms and conditions of the AWS, and click the Launch button. You’ll see the image as below.

(xii) Scroll down and press the “View launch log” button and then click the Instance Id to view your instance after the successful launch of the instance as seen in the images below.


(xiii) Now, the newly generated instance can be seen. Click on the instance, and you will get your instance’s summary. To connect the instance, click the “connect” button.


(xiv) Choose the ‘SSH client’ option from the three options below. To connect to your Ubuntu server, you can copy and paste the command directly into your terminal. Mention in point 3 and, in the example, as in the image below.
Note: **To log in to your Ubuntu Server, please follow either STEP (xiv) or STEP 3. The command is the same in each of these steps.

STEP 3: Log in to your Ubuntu Server by executing the command mentioned below:
1 2 3 4 5 6 |
chmod 400 /path to .pem file ssh -i ".pem file" ubuntu@ec2-ip_address.compute-1.amazonaws.com |
After logging in, install the necessary application software.
(i) Creation of SWAP Memory (You can leave this step, if you’re using 2GB or higher RAM. Since it is only necessary for the 1GB RAM.)
We create a shell file with the Nano Editor to configure the SWAP memory on the server.
1 2 3 4 5 6 7 |
sudo nano swap.sh #!/bin/bash |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
sudo fallocate -l 4G /swap.img ls -lh /swap.img sudo chmod 600 /swap.img ls -lh /swap.img sudo mkswap /swap.img sudo swapon /swap.img echo '/swap.img none swap sw 0 0' | sudo tee -a /etc/fstab cat /etc/fstab cat /proc/sys/vm/swappiness sudo sysctl vm.swappiness=10 sudo echo "vm.swappiness=10" >> /etc/sysctl.conf |
After that, click Ctrl+x to save the file and validate the changes by pressing Y and then click Enter.
Now, apart from the aforementioned, execute the below two commands:
1 2 3 4 5 6 |
sudo chmod +x swap.sh sudo sh swap.sh |
Well, by using below command, you can check the SWAP memory.
1 2 3 4 5 |
free -h |

(ii) Install Apache2, MY SQL, PHP 7.4, and its modules
Apache, Php, and Mysql database are needed for the magneto backend. All three applications can be configured with these commands.
1 2 3 4 5 6 7 8 9 10 11 12 |
sudo apt update sudo apt install apache2 sudo systemctl start apache2.service sudo systemctl enable apache2.service sudo apt-get install -y software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-gmp php7.4-curl php7.4-soap php7.4-bcmath php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-xml php7.4-cli php7.4-zip |
Check the version of PHP, if it is php7.4., then allow the PHP-module apache and the rewrite-apache module.
1 2 3 4 5 6 7 8 |
php -v sudo a2enmod php7.4 sudo a2enmod rewrite sudo service apache2 restart |
(iii) Install the Composer
1 2 3 4 5 |
sudo apt install composer |
STEP 4: SSH User creation
Presently, we were in our server’s root user, but due to security issues, we do not keep our application code in the directories of the root user. So, we have to create another SSH user for this.
Create an SSH user who will be the owner of the application code. I create an SSH user with the name “magento.” You can pick any name you want.
1 2 3 4 5 |
sudo adduser magento |
Eventually, this prompts a password window where you can set the password. Also, the remaining fields can be left empty by simply pressing the enter key. Additionally, after creating a user, we will switch to a new user.
STEP 5: Download Magento 2 by using the composer:
To install magento2 with composer, first, create the Access keys of Magento marketplace. If you have an account on Magento Marketplace, simply sign in and generate the access keys. If you don’t have an account, create an account by registering yourself on marketplace.magento.com
For generating Access keys, login into Magento marketplace, and from the top right corner of the page where your user name is displayed, navigate to My profile > Marketplace > My products > Access Keys
After all, create a new pair of Access keys. You need to provide the public Key as a username and the Private Key as a password when prompt.
1 2 3 4 5 6 |
cd /home/magento sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2 |
STEP 6: Apache configuration
However, to support the web pages we will configure apache. So, we need to switch again to the root user for configuring apache.
1 2 3 4 5 |
sudo nano /etc/apache2/sites-enabled/000-default.conf |
You will find the following lines as shown below, after executing the above command.

Besides that, change this to :

Save it, and exit after this.
Furthermore, configure the envvars file by executing the below command:
1 2 3 4 5 |
sudo nano /etc/apache2/envvars |
And find these lines :

Modify the apache SSH username by this way :

And configure file apache2.conf by the following command:
1 2 3 4 5 |
sudo nano /etc/apache2/apache2.conf |
Although, you will find the block code as shown below:

Modify it to the following code:
<Directory /home/magento/magento2/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save the file and exit it.
Meanwhile, make some changes to php.ini file
1 2 3 4 5 |
sudo nano /etc/php/7.4/apache2/php.ini |
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago
Save and exit, php.ini file and then run the command below:
1 2 3 4 5 |
sudo service apache2 restart |
STEP 7: Install MYSQL Server for database creation by executing the following commands and when a password is asked after the below two commands, simply press ENTER
1 2 3 4 5 6 7 8 9 10 11 |
sudo apt-get install mysql-server sudo mysql -u root -p create database magento2; CREATE USER 'magento2user'@'localhost' IDENTIFIED BY 'magento'; GRANT ALL ON magento2.* TO 'magento2user'@'localhost' WITH GRANT OPTION; flush privileges; exit; |
STEP 8: Similarly, Install the Elastic Search to move further
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
sudo su apt-get install apt-transport-https wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list apt update && apt-get install elasticsearch service elasticsearch start sysctl -w vm.max_map_count=262144 echo "vm.max_map_count=262144" | tee /etc/sysctl.d/elasticsearch.conf service elasticsearch restart exit; |
STEP 9: Likewise, execute the commands below to install Magento 2 by using the required variables such as host, database name, username, and password, etc.
1 2 3 4 5 6 7 |
cd /home/magento/magento2 sudo bin/magento setup:install --base-url=http:// Public IP Address or Domain Name --db-host=localhost --db-name=magento2 --db-user=magento2user --db-password=magento --admin-firstname=Admin --admin-lastname=User [email protected] --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 sudo service apache2 restart |
when this command is successfully executed, the output will be identical as seen in the image below:

STEP 10: In addition, Enable and restart Apache2, the Magento2, and rewrite the module
1 2 3 4 5 6 7 8 |
sudo a2enmod rewrite sudo chmod -R 755 /home/magento/magento2 sudo chown -R magento:magento /home/magento/magento2 sudo systemctl restart apache2.service |
while the installation of Magento2 has been successfully completed, go to your browser and enter the IP address of your EC2 instance or domain name. As a result, the homepage of your default eCommerce website will be like this:

STEP 11: Magento configuration
After all the above steps, you can now access your admin panel by using your credentials. Therefore, the admin login will open as in the image below.

You can’t log in to Magento Admin Panel after installation since two-factor authentication has been implemented in Magento2.4 and won’t be allowed you to log in. Hence, a page similar to the one below will open.

Moreover, to log in, you need a working email id. And then Magento sends an email to conduct the authentication on the given email id. In that case, the 2-factor authentication module must need to be disabled and later set up by the admin panel. Thus, we can disable 2FA by using the below command in the Magento web root directory:
php bin/magento module:disable Magento_TwoFactorAuth
**We highly recommend you to continue with 2-factor authentication**
At last, the admin panel is accessible. In addition, this is what the default admin dashboard looks like.

In short, your eCommerce platform is ready to use.
Thanks For Reading!
At last, we hope it works for you! And during this blog, you have found something valuable.
Keep in touch!!
In case of any help or query, please contact us or raise a ticket.