How to install Magento-2.2.3 on RHEL / CentOS 7.6

how to install magento

Magento is one of the robust and powerful platform for eCommerce website. It built with a PHP Framework. It comes with two editions-: Magento-2 Commerce (EE) "formerly known as Enterprises Edition" and Magento-2 Open Source "formerly known as Community Edition". Magento-2 is a fully customizable and user-friendly interface, which can set up and control a fully operational e-commerce store in a few minutes.

In short, we can use Magento-2 EE/Commerce, it is a paid version where you can get all the advanced functionalities with a yearly subscription. The slab you can choose based on your business-level/stage and Magento-2 CE/Opensource is offered a free version where anyone can download and use to build their own business, preferably (small business) where they can do the test on how to build an eCommerce Site. The CE can modify based on your requirement also it has the advantage of using the Magento extension to strengthen the functionality.

This step by step guide will help you to install/ configure the most recent stable Magento2 Community Edition (2.3) on CENTOS/RHEL 7.6. The same steps can be used for all the versions of CENTOS/RHEL/Fedora with a few minimal changes in commands.

Prerequisites :

Magento runs on Web Server as Apache or Nginx with a backend database (either MySQL or MariaDB)

Apache              :  Apache 2.4 or later
PHP                    :  7.2 or later
MYSQL              :  5.6 or later OR
MariaDB           :  MariaDB 10.1 or later
Server Ram      :  Minimum 2GB (according to the official Magento2)

My Lab Setup :

Server                   :  CentOS-7.6
Apache                 :   Apache/2.4.6
MariaDB              :  MariaDB 10.1 or later
PHP                       :  7.2.25
IP address            :  192.168.3.103
Domain name     :  magento-linuxteck.com

To start the installation setup of Magento-2, we need to set up the LAMP (Linux, Apache MariaDB, and PHP) stack in our Centos 7.6 server.

Step 1: Install the LAMP stack

For the complete steps to install LAMP stack in CentOS:- please click here:

First, let's update the latest current version of the package.

# yum update -y

Install the EPEL repository using the following command:

# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-release

Install Apache Server using the following command:

# yum install httpd -y

Use the following command to Start httpd service and enable it to start automatically after every reboot

# systemctl enable httpd

 

# systemctl start httpd

 

# systemctl status httpd

Now, we need to add some additional configuration in Apache Server in-order to install the Magento application.

(a)  Make sure the Apache version :

# httpd -v

Server version: Apache/2.4.6 (CentOS)
Server built: Aug 8 2019 11:41:18

(b) Magento will be host under the DocumentRoot of /var/www/html in Apache Server. ( You can provide your path)

# mkdir -p /var/www/html/magento2

(c) If you have any normal user who needs to access/modify the files of Magento other than the root user, then you need to change the ownership of Magento directory (/var/www/html/magento). In my case normal user named "magento"

# chown -R magento:magento /var/www/html/magento2

Using the following command you can cross-check the ownership of the directory

# ls -ld /var/www/html/magento2/

drwxr-xr-x 2 magento magento 6 Dec 23 17:51 /var/www/html/magento2/

(d) We need to set the permissions of the above directory to ensure that all of the files and folders are accessible by Magento application

# chmod -R 755 /var/www/html/

# ls -ld /var/www/html/

drwxr-xr-x 3 root root 22 Dec 31 14:48 /var/www/html/

(e) Now create a new Virtual Host in Apache Server: This is mainly used for adding multiple domain requests in a single apache server.  To initialize this set-up, we need a directory to store our virtual host (this is nothing but to store individual websites in different directories), as well as we need to tell the path of virtual hosts to the Apache configuration file to serve the sites for the visitors.

(i) Here we will create two directories under Apache Server "/etc/httpd". One directory will save all the configuration files for the virtual host and the other directory would be served as a symbolic link of the newly created virtual host.

This directory is to store all the configuration files for  the virtual host

# mkdir /etc/httpd/available-virtualhosts

# mkdir /etc/httpd/enable-virtualhosts                                ## This will be served for the symbolic links

(ii) Create your First Virtual host file

# vi /etc/httpd/available-virtualhosts/magento.conf                  ## The virtual host file should be ended with ".conf"

<VirtualHost *:80>
ServerName magento-linuxteck.com
ServerAlias magento-linuxteck.com
DocumentRoot /var/www/html/magento2
ErrorLog /var/log/magento/error.log
CustomLog /var/log/magento/access.log combined
</VirtualHost>

Save and exit.

(iii) Logs, you can create a folder "magento" under /var/log, so that it will not mix up with other logs

# mkdir /var/log/magento

(iv) Activate the symbolic link for the newly created virtual host configuration file

# ln -s /etc/httpd/available-virtualhosts/magento.conf /etc/httpd/enable-virtualhosts/magento.conf

(v) Add the following entry (including an optional directory)to the end of the Apache's configuration file. This is one of the easiest methods to activate and de-activate the virtual hosts in Apache. This concept was developed by Debain's well-wishers.

# vi /etc/httpd/conf/httpd.conf

IncludeOptional enable-virtualhosts/*.conf

Save and exit.

(vi) Create a dummy Page to the newly added virtual host

# vi /var/www/html/magento2/index.html

This is a testing page for magento-linuxteck.com

Save and exit.

(vii) Use the following command to open Firewall ports  HTTP (80) and HTTPS (443) services OR simply disable the Firewall.

# firewall-cmd --permanent --add-port=80/tcp

 

# firewall-cmd --permanent --add-port=443/tcp

 

# firewall-cmd --reload

OR

# systemctl disable firewalld.service

# systemctl stop firewalld.service

(ix) Disable the SELinux or click here to configure SELinux for apache.

(x) Now, it's time to restart the Apache Server.

# systemctl restart httpd.service

Note: Open your Web browser  and hit "http://magento-linuxteck.com/" to see the newly created dummy page

install magento 2 centos 7 apache

Install and Configure PHP 7.2

In Centos-7, the default repository built with PHP 5.4 version which is not compatible with magento2 the latest version. It requires PHP 7.2 or higher versions. See the following steps to install and configure PHP 7.2.

(a) Activate EPEL and Remi "yum" repositories

This section discusses how to install and configure MySQL 5.6. CentOS 6.x repositories have MySQL 5.1; to install a different version of MySQL, see the MySQL documentation. # yum install epel-release

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

(b) Use the following command to install PHP 7.2 and it's a dependency on your CentOS-7 Server

# yum --enablerepo=remi-php72 install php php-bcmath php-dom php-gd php-intl php-mbstring php-pdo_mysql php-soap php-zip

# yum install -y php72-php-xmlrpc.x86_64

(c) PHP 7.2 is installed, check the following command to find the version of PHP

# php -v

PHP 7.2.26 (cli) (built: Dec 17 2019 14:06:22) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

(d) Tweaking PHP's default configuration file which is "php.ini". Based on our requirement we need to change the settings of PHP. These changes are related to upload maximum size, display log errors, resource limits, sets the time zone, set the maximum php execution time, etc.

Modify the following changes in your php.ini file. For date, you can change it based on your zone

#  vi /etc/php.ini

max_input_time = 30
memory_limit= 2G
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log
date.timezone = Asia/Calcutta
cgi.fix_pathinfo=1

Save and exit.

Note: After every change in the php.ini file, do not forget to restart your web server.

(e)  In CentOS-7 the mod_rewrite will be enabled by default,  in case if it is not enabled, then follow the steps to enable "mod_rewrite" manually

Open this file and add the following entry at the end of the file

# vi /etc/httpd/conf.modules.d/00-base.conf

LoadModule rewrite_module modules/mod_rewrite.so

Save and exit.

Note: Restart your Apache Server!

(f) THIS IS AN OPTIONAL, IF THE. HTACESS NOT WORKING, THEN WE NEED TO TWEAK THIS ENTRY INTO HTTP.CONF FILE.

Find the section <directory /var/www> and change AllowOverride None to AllowOverride All

<Directory /var/www>
AllowOverride All
</Directory>

Save and exit.

Note: Finally, Restart your Apache Server!

(g) Create an info.php file under /var/www/html/magento2 to check all the current PHP configurations from your Web Browser

# echo "<?php phpinfo(); ?>" > /var/www/html/magento2/info.php

Note: Open your Web browser hit: http://magento-linuxteck.com/info.php.  Once you're confirmed, then delete info.php file

magento 2 php 7.2

Install and Configure MariaDB (Replacement of MySQL)

This section will show you how to install and configure the Database Management System (DBMS) for Magento2. As all we know, the launch of RHEL/CENTOS-7 RedHat has switched their default database management system from MySQL to MariaDB and the default MariaDB version is 5.5 which is not compatible with Magento2. As mentioned above the compatible version is 10.1 or later. It can be upgraded through the MariaDB yum repository. Follow the steps to install and configure MariaDB 10.1 from yum repository:

(a) Create a repository configuration file for MariaDB 10.1

# cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/10.1/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=1
EOF

(b) Import GPG public key

# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

(c) Enable yum cache for the recently added repo

# yum makecache fast

(d) Install MariaDB 10.1 version

# yum install -y mariadb-server

(e) Use the following command to start MariaDB service and enable it to start automatically after every reboot

# systemctl enable mariadb.service

 

# systemctl start mariadb.service

(f) Configure MariaDB

# mysql_secure_installation

magento with mariadb

(g) Connect MariaDB database instance using root credentials.

# mysql -u root -pXXXXXX (XXXXX is your root DB password )

Welcome to the MariaDB monitor.

Your MariaDB Server version: 10.1.43-MariaDB MariaDB Server

MariaDB [(none)]>

(h) Create a new mysql user and database for Magento Application.

MariaDB [(none)]> create database magento2;
Query OK, 1 row affected (0.00 sec)

 

MariaDB [(none)]> create user [email protected] identified by '[email protected]';
Query OK, 0 rows affected (0.01 sec)

 

MariaDB [(none)]> grant all privileges on magento2.* to [email protected] identified by '[email protected]';
Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> quit

Bye

Step 2: Install Composer

(a) Use the following yum command to install PHP Composer

# yum --enablerepo=remi-php72 install php composer

(b) After installation check the version of the composer

# composer -V

Composer version 1.9.1 2019-11-01 17:20:17

Step 3: Install  Magento CE

(a) Download magento2-2.3 Community Edition from Magento Offical Website. Click here to download:  http://www.magentocommerce.com/download

(b) After download ,extract the tar file of Magento2 into your Document Root (/var/www/html/magento2)

# tar -xvf magento2-2.3.2.tar.gz -C /var/www/html/magento2/

Note: Make sure after extraction all the Magento2 cores files should be placed under /var/www/html/magento2 and remove any previously created dummy "index.html and info.php" from the same folder.

# pwd

 

/var/www/html/magento2

# ls

Output:

app                                composer.json            generated                                   pub        vendor
auth.json.sample    composer.lock           grunt-config.json.sample     lib          nginx.conf.sample      README.md
bin                                 COPYING.txt            Gruntfile.js.sample                 LICENSE_AFL.txt package.json.sample     setup
CHANGELOG.md  dev                                 index.php                                    LICENSE.txt             phpserver var

(c) To install the Magento2 application via browser we need to change the ownership of /var/www/html/magento2 to apache user and group. Follow the below command to do the same.

# chown -R apache:apache /var/www/html/magento2/

# ls -ld /var/www/html/magento2/

Output:

drwxr-xr-x 13 apache apache 4096 Jan 2 13:55 /var/www/html/magento2/

(d) Now use the following command to download all the packages and its dependencies of Maento2 using composer from Terminal.

# composer install

install magento 2 using composer

Note: It will download all the Magento components and their dependencies. Once it is successfully installed magento2 using composer you will see a line ended with "Generating autoload files".

Access Magento Web Installation Wizard

(a) Now open your browser and hit "http://magento-linuxteck.com" you will get the WEB wizard setup. Follow the screenshots for further steps:

The first page will redirect to the License Agreement Page of Magento2.

(i) Click on Agree and Setup Magento

install magento 2 enterprise composer

(ii) Click on Start Readiness Check

magento installation guide

(iii) If there are any fails found during the Readiness Check, then you need to rectify before click Next. In our case there are no failures,  so click Next

magento installation steps

(iv) Now fill the Database details which have created above and click on Next

magento database configuration

(v) Make the changes of Web Configuration based on your needs and click on Next

magento 2 server configuration

(vi) Customize Your Store and click on Next

magento 2.3 installation in centos 7

(vii) Create Admin Account and click on Next

magento commerce installation

(viii) Click on Install Now

magento 2 server setup

(ix) Magento2 installation on CentOS 7 server in progress

download and install magento

(x) Magento2 installation has been completed.

install magento 2.3

(b) Due to the security measures of Magento2 application, we need to revoke the permission of the following directories:
'/var/www/html/magento2/app/etc'. The following command will remove the write permission

# chmod -w /var/www/html/magento2/app/etc

Output:

chmod: /var/www/html/magento2/app/etc: new permissions are r-xrwxr-x, not r-xr-xr-x

(c) Now Click on Launch Magento Admin

Launch Magento Admin

(d) Once you log in as Admin User (linuxteck) , you’ll see the Magento2 dashboard, which will appear something like this:

install magento dashboard

Conclusion

Congratulations, you have successfully installed Magento2 Community Edition on RHEL/CentOS 7.6. During the installation of your Magento setup if you face any difficulties, just let us know through the comment box.

I hope this article will help you to set up a 'magento2 application on RHEL/CentOS-7. Drop me your feedback/comments.

Thank you!

Please share it, if you like this article and help us to grow! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *