Author Photo

Being a Linux Enthusiast and a Fan of Open Source Software, I created Ahmer’s SysAdmin Recipes blog to share my experiences with other System Administrators. The curiosity doesn’t let me stop; therefore, I am constantly trying to learn new software tools and techniques. Whereas I also have the passion and the patience to teach the others.

I am always ready to accept new challenges and wish to explore the areas, that I haven’t worked on. Please give me your feedback and help me improve this blog.

Friday, 21 June 2019

Install Magento 2 Open Source on CentOS 7

Install Magento Open Source on CentOS 7Magento is an open-source eCommerce platform, initially developed by Varien, Inc and currently maintained by Magento, Inc developers. Magento was first released on March 31, 2008. Magento is written in PHP and it requires a LAMP server for its deployment. In May 2018, Magento was acquired by Adobe.

Magento is a flexible and open-source platform empowers merchants to create innovative shopping experiences to attract new customers. Magento has a rich, out of the box feature set, combined with thousands of off-the-shelf extensions.

In this article, we are installing Magento Open Source on CentOS 7. First, we will install all prerequisites to configure a working LAMP server, then we will deploy Magento Open Source 2.3 on it.

 

Magento System Requirements:

Visit Magento documentation for complete system requirements. Most common system requirements are copied below.

  • Memory - 2 GB
  • Web Server - Apache 2.2 or 2.4 or nginx 1.x
  • Database - MySQL 5.6 or 5.7 or MariaDB 10.x
  • PHP - 7.1.3 or 7.2.0

 

Environment Specification:

We have provision a CentOS 7 virtual machine with following specification.

  • Hostname – magento-01.example.com
  • IP Address – 192.168.116.178 /24
  • Operating System – CentOS 7.6

 

Installing Magento Prerequisite - Apache 2.4:

Connect with magento-server-01.example.com using ssh as root user.

Install Apache web server using yum command.

[root@magento-server-01 ~]# yum install -y httpd ... Installed: httpd.x86_64 0:2.4.6-89.el7.centos Dependency Installed: apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-89.el7.centos mailcap.noarch 0:2.1.41-2.el7 Complete!

Allow Apache web service in Linux Firewall.

[root@magento-server-01 ~]# firewall-cmd --permanent --add-service=http success [root@magento-server-01 ~]# firewall-cmd --reload success

Enable and start Apache web service.

[root@magento-server-01 ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@magento-server-01 ~]# systemctl start httpd

Find and set directives for /var/www/html directory in /etc/httpd/conf/httpd.conf as follows.

<Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory>

 

Install Magento Prerequisite - MariaDB:

Magento requires MariaDB 10.x, which is not available in default yum repositories.

Therefore, we are required to add MariaDB yum repository as follows.

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

Import GPG public key in CentOS 7.

[root@magento-server-01 ~]# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

Build yum cache for newly added repositories.

[root@magento-server-01 ~]# yum makecache fast Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.ges.net.pk * extras: mirrors.ges.net.pk * updates: mirrors.ges.net.pk base | 3.6 kB 00:00 extras | 3.4 kB 00:00 mariadb | 2.9 kB 00:00 updates | 3.4 kB 00:00 mariadb/primary_db | 53 kB 00:00 Metadata Cache Created

Install MariaDB 10.3.16 using yum command.

[root@magento-server-01 ~]# yum install -y mariadb-server ... Installed: MariaDB-compat.x86_64 0:10.3.16-1.el7.centos MariaDB-server.x86_64 0:10.3.16-1.el7.centos Dependency Installed: MariaDB-client.x86_64 0:10.3.16-1.el7.centos MariaDB-common.x86_64 0:10.3.16-1.el7.centos boost-program-options.x86_64 0:1.53.0-27.el7 galera.x86_64 0:25.3.26-1.rhel7.el7.centos lsof.x86_64 0:4.87-6.el7 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 rsync.x86_64 0:3.1.2-6.el7_6.1 Replaced: mariadb-libs.x86_64 1:5.5.60-1.el7_5 Complete!

Enable and start MariaDB service.

[root@magento-server-01 ~]# systemctl enable mariadb.service [root@magento-server-01 ~]# systemctl start mariadb.service

Configure MariaDB database instance as follows.

[root@magento-server-01 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 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!

Connect with MariaDB database instance.

[root@magento-server-01 ~]# mysql -u root -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.3.16-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 user and database for Magento Software.

MariaDB [(none)]> create database magento; Query OK, 1 row affected (0.026 sec) MariaDB [(none)]> create user magento@localhost identified by '123'; Query OK, 0 rows affected (0.120 sec) MariaDB [(none)]> grant all privileges on magento.* to magento@localhost identified by '123'; Query OK, 0 rows affected (0.035 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.064 sec) MariaDB [(none)]> exit Bye

 

Installing Magento Prerequisite - PHP:

Magento requires PHP 7.3.1 or 7.2.0, which are not available in default yum repositories.

Therefore, we are installing Webtatic, a third party yum repository, to install PHP 7.2.

At first, we have to add EPEL (Extra Packages for Enterprise Linux) as a prerequisite of Webtatic yum repository.

[root@magento-server-01 ~]# yum install -y epel-release ... Installed: epel-release.noarch 0:7-11 Complete!

Install Webtatic yum repository as follows.

[root@magento-server-01 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm warning: /var/tmp/rpm-tmp.fN84oh: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:webtatic-release-7-3 ################################# [100%]

Build yum cache for webtatic repository.

[root@magento-server-01 ~]# yum makecache fast Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 7.6 kB 00:00 * base: mirrors.ges.net.pk * epel: kartolo.sby.datautama.net.id * extras: mirrors.ges.net.pk * updates: mirrors.ges.net.pk * webtatic: uk.repo.webtatic.com base | 3.6 kB 00:00 epel | 5.3 kB 00:00 extras | 3.4 kB 00:00 mariadb | 2.9 kB 00:00 updates | 3.4 kB 00:00 webtatic | 3.6 kB 00:00 (1/5): webtatic/x86_64/group_gz | 448 B 00:01 (2/5): webtatic/x86_64/primary_db | 160 kB 00:03 (3/5): epel/x86_64/updateinfo | 978 kB 00:03 (4/5): epel/x86_64/group_gz | 88 kB 00:03 (5/5): epel/x86_64/primary_db | 6.7 MB 01:06 Metadata Cache Created

Install PHP 7.2 and required PHP extensions using yum command.

[root@magento-server-01 ~]# yum install php72w php72w-bcmath php72w-ctype php72w-curl php72w-dom php72w-gd php72w-hash php72w-iconv php72w-intl php72w-mbstring php72w-openssl php72w-pdo_mysql php72w-simplexml php72w-soap php72w-spl php72w-xsl php72w-zip php72w-pecl libxml2 ... Installed: mod_php72w.x86_64 0:7.2.17-1.w7 php72w-bcmath.x86_64 0:7.2.17-1.w7 php72w-common.x86_64 0:7.2.17-1.w7 php72w-gd.x86_64 0:7.2.17-1.w7 php72w-intl.x86_64 0:7.2.17-1.w7 php72w-mbstring.x86_64 0:7.2.17-1.w7 php72w-mysql.x86_64 0:7.2.17-1.w7 php72w-soap.x86_64 0:7.2.17-1.w7 php72w-xml.x86_64 0:7.2.17-1.w7 Dependency Installed: libX11.x86_64 0:1.6.5-2.el7 libX11-common.noarch 0:1.6.5-2.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.12-1.el7 libargon2.x86_64 0:20161029-3.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7 libxcb.x86_64 0:1.13-1.el7 php72w-pdo.x86_64 0:7.2.17-1.w7 Complete!

Configure PHP settings as required by Magento.

[root@magento-server-01 ~]# vi /etc/php.ini

Find and update following parameters.

date.timezone = Asia/Karachi memory_limit= 756M max_input_time = 30

Restart Apache web service.

[root@magento-server-01 ~]# systemctl restart httpd

 

Installing Magento Open Source on CentOS 7:

Currently, Magento Open Source 2.3 is available on Magento download page.

You are required to create a User Account on Magento Site to download Magento software.

Once Magento Open Source 2.3 is downloaded, transfer it to our Magento Server and copy it into /tmp directory.

Extract the contents of Magento-CE-2.3.1_sample_data-2019-03-18-07-26-52.tar.bz2 file in /var/www/html/magento directory.

[root@magento-server-01 ~]# cd /tmp [root@magento-server-01 tmp]# mkdir /var/www/html/magento [root@magento-server-01 tmp]# tar xvf Magento-CE-2.3.1_sample_data-2019-03-18-07-26-52.tar -C /var/www/html/magento/ ... vendor/zendframework/zend-view/src/Strategy/JsonStrategy.php vendor/zendframework/zend-view/src/Strategy/PhpRendererStrategy.php vendor/zendframework/zend-view/src/Stream.php vendor/zendframework/zend-view/src/Variables.php vendor/zendframework/zend-view/src/View.php vendor/zendframework/zend-view/src/ViewEvent.php

Grant file permissions of magento directory, as mentioned in Magento 2.3 documentation.

[root@magento-server-01 tmp]# cd /var/www/html/magento [root@magento-server-01 magento]# chown -R apache:apache . [root@magento-server-01 magento]# find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} + [root@magento-server-01 magento]# find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} + [root@magento-server-01 magento]# chmod u+x bin/magento

Adjust SELinux file contexts.

[root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/var(/.*)?' [root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/generated(/.*)?' [root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/vendor(/.*)?' [root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/pub/static(/.*)?' [root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/pub/media(/.*)?' [root@magento-server-01 magento]# semanage fcontext -a -t httpd_sys_rw_content_t '/app/etc(/.*)?' [root@magento-server-01 magento]# restorecon -R .

If you do not have semanage command, then you have to install policycoreutils-python package.

Browse URL http://magento-01.example.com/ using a client's browser.

01-magento-setup-license-agreement

We were redirected to the Magento License Agreement Page.

Click on Agree and Setup Magento.

02-magento-setup-readiness-check

Click on Start Readiness Check.

03-magento-setup-readiness-check-completed

If any check fails then you have to rectify it before continuing.

For us, there are no failures. Therefore, click on Next.

04-magento-setup-add-database

You are at the Add Database step. Add the database and user that we have created above and click on Next.

05-magento-setup-web-configuration

Adjust the settings as per the above screen-shot and click on Next.

06-magento-setup-customize-your-store

Set Timezone and Language here and click on Next.

07-magento-setup-create-admin-account

Create a new Admin account and click on Next.

08-magento-setup-ready-to-install

Click on Install Now.

09-magento-setup-installation-progress

Installer takes a while to setup Magento on CentOS 7 server.

10-magento-setup-installation-success

Magento installation has been completed.

Revoke write permissions from app/etc directory for security purpose.

[root@magento-server-01 ~]# chmod -w /var/www/html/magento/app/etc [root@magento-server-01 ~]# semanage fcontext -d -t httpd_sys_rw_content_t '/app/etc(/.*)?' [root@magento-server-01 ~]# restorecon -R /var/www/html/magento/app/etc

Click on Launch Magento Admin.

11-magento-admin-login

Login as ahmer user.

12-magento-admin-dashboard

We have reached at the dashboard of ahmer user.

We have successfully installed Magento Open Source on CentOS 7. To start using Magento in true capacity, we suggest you to read Magento Beginner’s Guide Second Edition by Packt Publishing.

Install Magento 2 Open Source on CentOS 7


YOU MIGHT ALSO LIKE:

2 comments:

  1. Hi! Good job! but can you explain how to install magento locally, please? Because i try to adapt your explanations but it seems to be more difficult. thx

    ReplyDelete
    Replies
    1. Hi, Thanks for appreciation.

      The above article is also good for local installation of Magento. However, if you are facing difficulties. You can share the problems with me on Linkedin.

      Delete