How to install Magento on CentOS 8

Share on Social Media

Magento is an open source eCommerce platform. This guide will show you how to install Magento on CentOS 8. #centlinux #linux #magento

What is Magento ? :

Magento is an open source eCommerce platform written in PHP by using multiple frameworks such as Laminas and Symfony. Provides complete features of content management and shopping cart application.

More than 100,000 online stores have been created on this eCommerce platform. The platform code has been downloaded more than 2.5 million times, and $155 billion worth of goods have been sold through Magento-based systems in 2019. Two years ago, Magento accounted for about 30% of the total market share.

Magento software is available in Enterprise and Community editions.

  • Enterprise edition is named as Magento Commerce and has a license fee, but offer many Enterprise level features. Check out the complete Magento Pricing.
  • Whereas, Community edition is named as Magento Open Source, which is free and distributed under Open Software License (OSL) v3.0. It’s source code is available at Magento Github.

Magento was acquired by Adobe Inc. in May 2018.

Magento Features:

Some of the popular features in Magento eCommerce Platform are:

  • Page Builder
  • Product Recommendations
  • Customer Segmentation and Personalization
  • Asset and Content Management
  • Content Staging and Preview
  • Instant Purchase
  • Dynamic Rule-Based Product Relations
  • Visual Merchandising
  • Elasticsearch
  • Powerful Admin Experience

Complete details about each feature is available on Magento website .

You can also view the feature comparison of Magento Commerce and Open Source here.

Environment Specification:

We are using a minimal CentOS 8 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 8.2
  • Hostname –
  • IP Address – /24

Update Linux Server Packages :

Connect with as Linux root user by using a SSH client.

It is a best practice to update your Linux operating system before installing any new software. Therefore, execute the dnf command and update installed software packages on CentOS / RHEL 8.

You may need to enable free Redhat subscription for your RHEL operating system.

# dnf update -y
Last metadata expiration check: 0:00:40 ago on Thu 03 Dec 2020 08:47:52 PM PKT.
Dependencies resolved.
Nothing to do.

Our Linux operating system is already up-to-date, therefore, no package is updated this time. The output may vary on your CentOS 8 server.

Verify the Linux operating system and updated Kernel versions.

# uname -r

# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

Install Magento Prerequisites:

Magento requires following prerequisite software. Therefore, you must install them to install Magento on CentOS 8.

  • Nginx or Apache Web Server
  • PHP (7.3 or later)
  • MySQL Database Server
  • ElasticSearch

Apache, PHP and MySQL are available in standard yum repositories, therefore, you can install all of them with a single dnf command.

# dnf install -y httpd mariadb-server @php:7.3 mod_ssl wget unzip

Configure PHP settings as required by the eCommerce software .

# vi /etc/php.ini

Locate and adjust following parameter in this file.

memory_limit = 1024M

Enable and start Apache, MySQL and PHP services.

# systemctl enable --now mariadb.service httpd.service php-fpm.service

Configure MySQL database server security as follows.

# mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Configure Linux Firewall for Magento :

To allow incoming traffic to HTTP service port, you can add http service or port 80/tcp in your Linux firewall.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Create Linux User and Directory:

Create a Linux user to own Magento directory and files.

# adduser magento
# usermod -a -G apache magento

Create a directory for deploying Magento eCommerce software.

# mkdir /var/www/magento
# chown magento:apache /var/www/magento

Create MySQL Database for Magento :

Magento uses MySQL as its backend database. You have already installed MariaDB on your Linux server. Now, login to MySQL shell as root user.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Create a MySQL database for Magento eCommerce software.

MariaDB [(none)]> CREATE DATABASE magentodb;
Query OK, 1 row affected (0.001 sec)

Grant all privileges on magentodb database to magento user. This command also creates the magento user, if not already created.

MariaDB [(none)]> GRANT ALL ON magentodb.* TO magento@localhost IDENTIFIED BY 'Str0ngP@ssw0rd';
Query OK, 0 rows affected (0.001 sec)

Exit from MySQL shell.

MariaDB [(none)]> exit

Install ElasticSearch on Linux server :

Starting from Magento 2.4.0, ElasticSearch is now being used for search. Therefore, you are also required to install ElasticSearch on Linux server.

ElasticSearch needs Java Runtime, therefore, before installing ElasticSearch you have to install OpenJDK on CentOS 8 machine.

# dnf install -y java-11-openjdk

Verify the Java version of installed software.

# java -version
openjdk version "11.0.9" 2020-10-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing)

Import the ElasticSearch GPG key by using rpm command.

# rpm --import

Create a yum repository file by using vi text editor.

# vi /etc/yum.repos.d/elasticsearch.repo

Add following directives in this repo file.

name=Elasticsearch repository for 7.x packages

You can now easily install ElasticSearch on your Linux server by using dnf command.

# dnf install -y --enablerepo=elasticsearch elasticsearch
Install ElasticSearch on CentOS 8

Since, we are installing on a virtual machine with limited memory. Therefore, we are reducing the Java virtual machine (JVM) memory options as follows.

Open jvm.option file in vi text editor.

# vi /etc/elasticsearch/jvm.options

Find and adjust following parameters therein.


Enable and start ElasticSearch service.

# systemctl enable --now elasticsearch.service

Install Composer on CentOS 8:

Composer is a dependency manager for PHP.

Currently, the Composer v2.0 is available on the Internet. But Magento 2.4.1 does not supports it.

Therefore, you have to use Composer v1.0 for your eCommerce server.

Download the Composer by using wget command.

# wget
--2020-12-05 18:53:38--
Resolving (, 2607:5300:201:2100::4:d105
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1999995 (1.9M) [application/octet-stream]
Saving to: âcomposer-1.pharâ

composer-1.phar     100%[===================>]   1.91M  63.0KB/s    in 29s

2020-12-05 18:54:11 (67.6 KB/s) - âcomposer-1.pharâ saved [1999995/1999995]

Add execute permissions to composer file and copy it in /usr/local/bin directory, so users can run it from any location.

# chmod +x composer-1.phar
# mv composer-1.phar /usr/local/bin/composer

All prerequisites has been installed and configured. Now you are ready to install Magento on CentOS 8.

Install Magento on CentOS 8:

You can now use composer to install the Magento Open Source edition as follows.

Note: You may be asked to provide a Username/Password to install Magento on CentOS 8. The username is the Public Key and Password is the Private Key. These Public/Private keys can be generated at Magento Marketplace website. You are required to sign-up/sign-in to generate these keys.

# composer create-project --repository-url= magento/project-community-edition /var/www/magento

Adjust file permissions of Magento files as follows.

# cd /var/www/magento
# 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 magento:apache /var/www/magento/
# chmod u+x bin/magento

Adjust SELinux file contexts and booleans.

# restorecon -R /var/www/magento
# setsebool -P httpd_unified 1

Create Apache virtual host configurations for Magento.

# vi /etc/httpd/conf.d/magento.conf

And add following directives in this file.

<VirtualHost *:80>
    DocumentRoot /var/www/magento
    ErrorLog /var/log/httpd/magento_error.log
    CustomLog /var/log/httpd/magento_access.log combined

    <Directory /var/www/magento >
        Options FollowSymLinks
        AllowOverride All


Restart Apache service to load newly added configurations.

# systemctl restart httpd.service

Magento web setup is no longer available in Magento 2.4.0 (or later). You must use Magento Command Line to install it.

# php /var/www/magento/bin/magento setup:install 
> --base-url="" 
> --db-host="localhost" 
> --db-name="magentodb" 
> --db-user="magento" 
> --db-password="Str0ngP@ssw0rd" 
> --search-engine="elasticsearch7" 
> --admin-firstname="admin" 
> --admin-lastname="admin" 
> --admin-email="" 
> --admin-user="admin" 
> --admin-password="Ahmer@1234" 
> --language="en_US" 
> --currency="USD" 
> --timezone="America/Chicago" 
> --use-rewrites="1" 
> --backend-frontname="admin"
Install Magento on CentOS 8 1
Install Magento on CentOS 8 2

Adjust SELinux file contexts for following Magento directories.

# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/var(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/generated(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/vendor(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/pub/static(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/pub/media(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/app/etc(/.*)?'
# restorecon -R /var/www/magento

Magento eCommerce Platform has been installed.

Conclusion – Install Magento on CentOS 8:

In this guide, you have learned how to install Magento on CentOS 8. Now its time to read Magento 2 Developer’s Guide (PAID LINK) by Packt Publishing, if you want to start developing your eCommerce website.