How to Install Magento 2 on Ubuntu 22.04 Server (Step by Step)

How to Install Magento 2 on Ubuntu 22.04 Server (Step by Step). In this post, we introduce Magento, its features, advantages then explain how to install Magento 2 on Ubuntu 22.04 server.

What is Magento?

First of all, Magento is a well known open source eCommerce platform that allows the highest level of customization. One of the most reliable, adaptable, and extensible platforms that provides a wide range of effective tools for setting up and running your online store.

Secondly, Magento streamlines eCommerce operations and gives vendors a multi channel experience by enabling access to ready to use tools for product management, marketing, and SEO. Here, we are discussing more prominent features and advantages of Magento to further comprehend this eCommerce platform.

Magento and its Unbeatable Features

Importantly, with Magento it offers efficient operation by Magento Cloud to execute challenging eCommerce strategies. Below are Magento other features:

1. Analytics & Reporting

Supports Google Analytics to assist you in completing a complete investigation. Also offers several reports, including the following;

  • Sales and Tax report.
  • Best viewed products report.
  • Low stock report
  • Search terms report
  • Product reviews report.
  • Coupon usage report.
  • Total sales invoiced report.

2. Ece-Tool Package

Interestingly, Magento has created an ece tools package for modular deployment tool customization to meet merchant’s or retailer’s requirements. This package contains scripts and instructions that enable retailers to launch eCommerce projects automatically, including project verification, cron management, and docker deploy environments.

3. ElasticSearch

ElasticSearch assists in managing search requests across huge catalogues in many languages and customising search results across a Magento store.

4. Customer accounts

Offers user accounts, incorporating various functions, and is simple to use with a comprehensive dashboard (account). With the order history & status, one or more delivery addresses, billing options, browsing history, shopping cart contents and more as features of the customer account.

5. Hosted on the clouds

The Magento edition’s cloud based framework enables quick scaling and consistent performance regardless of the sales season. Your eCommerce store will be running efficiently owing to Magento Commerce Cloud (which is operated by developers) and it handles any issues that may arise during traffic spikes.

6. Shipping and payments methods

The eCommerce platform of Magento enjoys following features:

  • One page checkout.
  • Shipping module integration.
  • Support many payment methods.

7. Site management

Website management is unbeatable with Magento when it comes to it’s CMS. A perfectly suited for building landing pages with some features below:

  • Tax calculations.
  • Support for multiple languages and currencies.
  • Exquisitely configurable designs.

What advantages does Magento offer?

Powerful Platform

Well, with Magento it operates both small and large stores to overcome difficulties with product placement and performance. The platform also offers services like product and inventory management for your website. Additionally, it also enables configuring filters and navigation in a way that increases conversion rates and improves the operation of your website.

Highly versatile Content Management

Retailers build and modify their offers to an easy to use, visually based page builder. Moreover, its content management interface provides the option where customers get a link to what they see. This interference is convenient for those who lack programming skills but still wish to alter how the shopping cart functions at its most basic level.

A versatile content management system is essential for eCommerce websites to publish new, high quality material every day, and draw in customers.

SEO Friendly

With Magento Enterprise Edition, optimising product descriptions is a simple process. It generates SEO friendly URLs so that you excel at your customer experience.


Magento offers a high level of customisation, which places it above other eCommerce platforms. Also design a distinctive storefront for your eCommerce shop that sets it apart from your rivals using Magento.

Provides top notch security

Easily manage internal access with top notch levels of security to secure your store. Employing Magento, you create a secondary password to prevent security breaches. In addition, Magento offers PCI Data Security and CAPTCHA for the highest level of security.

This is the main part of the article how to Install Magento 2 on Ubuntu 22.04 Server (Step by Step).

How to Install Magento 2 on Ubuntu 22.04 Server (Step by Step)

Follow this post for step by step guide in how to install Magento 2 with Apache on Ubuntu 22.04 server.


  • An Ubuntu 22.04 server installed on your server.
  • A root user or a user with sudo privileges.

Step 1 - Install ElasticSearch

Magento uses ElasticSearch to provide search functionality. So you need to install the ElasticSearch on your server. First, install the Java JDK using the following command.

					apt install openjdk-17-jdk -y

After the installation, download the Magento GPG key with the following command.

					curl -fsSL | gpg --dearmor -o /usr/share/keyrings/elastic.gpg

Next, add the Magento 2 repository to APT with the following command.

					echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list

Then, update the repository cache and install the ElasticSearch with the following command.

					apt update -y
apt install elasticsearch -y

Once the ElasticSearch is installed, start and enable its service with the following command.

					systemctl enable elasticsearch.service
systemctl start elasticsearch.service


Next, verify the ElasticSearch installation using the following command.

					curl -X GET 'http://localhost:9200'

You should see the following output.

  "name" : "magento",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "8KXM6WEoRDiIB7uk3yc2sQ",
  "version" : {
    "number" : "7.17.8",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "120eabe1c8a0cb2ae87cffc109a5b65d213e9df1",
    "build_date" : "2022-12-02T17:33:09.727072865Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  "tagline" : "You Know, for Search"


Step 2 - Install LAMP Server

You also need to install the Apache web server, MySQL database server, PHP and other PHP modules to your server. Install all of them with the following command.

					apt install apache2 mysql-server php libapache2-mod-php php-mysql php-mbstring php-bcmath php-intl php-soap php-zip php-gd php-curl php-cli php-xml php-xmlrpc php-gmp php-common -y


After installing all the packages, edit the PHP configuration file.

					nano /etc/php/8.1/apache2/php.ini

Change the default settings as shown below.

					file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 1024M
upload_max_filesize = 256M
max_execution_time = 36000


Save and close the file then restart the Apache service to apply the changes.

					systemctl restart apache2

Step 3 - Configure MySQL for Magento

In order to store data Magento uses MySQL. You need to create a database and user in MySQL. Firstly, log in to the MySQL using the following command.


Once you are logged in, change the MySQL root password with the following command.

					ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlpassword';


Next, create a database and user for Magento with the following command.

					CREATE DATABASE magento2;
CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'magentopassword';


Then, grant all the privileges to the Magento database with the following command.

					GRANT ALL PRIVILEGES ON *.* TO 'magento2'@'localhost' WITH GRANT OPTION;

Next, flush the privileges and exit from the MySQL with the following command.


Step 4 - Download Magento 2

Magento is installed by using the Composer. So you need to install the Composer in your server. Please install it with the following command.

					curl -sS -o composer-setup.php
php composer-setup.php --install-dir=/usr/bin --filename=composer

You should get the following output.

					All settings correct for using Composer

Composer (version 2.5.1) successfully installed to: /usr/bin/composer
Use it: php /usr/bin/composer


Next, navigate to the Apache web root directory and download the latest version of Magento using the Composer.

					cd /var/www/html
composer create-project --repository-url= magento/project-community-edition=2.4.5 magento2

Provide your Magento public key and private key to download Magento from its website.

					Authentication required (
Username: da86d0babbb486bc25703ad7a899116f
Do you want to store credentials for in /root/.config/composer/auth.json ? [Yn] Y

Once Magento 2 is download, navigate to the magento2 directory and set proper permission on it.

					cd magento2
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R www-data:www-data .
chmod u+x bin/magento


At this point, Magento 2 is downloaded on your server. Proceed to the next step.

Step 5 - Install Magento 2

Without a doubt Magento 2 provides an easier way to install it via command line interface. Run the following command to install Magento 2 on your server.

					php bin/magento setup:install --base-url= --db-host=localhost --db-name=magento2 --db-user=magento2 --db-password=magentopassword --admin-firstname=Admin --admin-lastname=Admin --admin-user=admin --admin-password=Your@Secure1_Admin3_Password --language=en_US --currency=USD --timezone=UTC --backend-frontname=admin --search-engine=elasticsearch7 --elasticsearch-host=localhost --elasticsearch-port=9200

Once the Magento 2 is installed successfully, you should get the following output.

					Cache cleared successfully
[Progress: 1320 / 1323]
Disabling Maintenance Mode:
[Progress: 1321 / 1323]
Post installation file permissions check...
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 1322 / 1323]
Write installation date...
[Progress: 1323 / 1323]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin
Nothing to import.


Step 6 - Configure Apache for Magento 2

At this point, Magento 2 is installed on your server. Now, you need to create an Apache virtual host configuration file for Magento. Create it with the following command.

					nano /etc/apache2/sites-available/magento2.conf

Add the following configurations.

					<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2/pub
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
AllowOverride all


Save and close the file when you are done. Then, activate the Magento virtual host and Apache rewrite module with the following command.

					a2ensite magento2.conf
a2enmod rewrite

Finally, restart the Apache service to apply the changes.

					systemctl restart apache2

Next, you need to run these command to upgrade the database and deploy static view files.

					php bin/magento indexer:reindex && php bin/magento se:up && php bin/magento se:s:d -f && php bin/magento c:f && php bin/magento module:disable Magento_TwoFactorAuth

Step 7 - Access Magento 2 Web UI

Now, open your web browser and access the Magento 2 web interface using the URL You will be redirected to the Magento 2 login page.

Provide your Magento 2 admin username, password and click on the Sign in button. See the Magento 2 dashboard on the following screen.

Thank you for reading How to Install Magento 2 on Ubuntu 22.04 Server (Step by Step). We shall conclude the article.

How to Install Magento 2 on Ubuntu 22.04 Server (Step by Step) Conclusion

In this guide, we showed you how to install Magento 2 with Apache on Ubuntu 22.04 server. Now you can start your own eCommerce store using the Magento. The advantages of Magento eCommerce development are uncountable, varying from hassle free product management to simple third party integration. These all greatly contribute to the expansion of your business. Therefore, choose Magento for its advanced features and benefits to stand out in the fierce competition with your rivals.

Also feel free to read more interesting Magento content in our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x