Pada panduan kali ini saya akan berbagi bagaiamana tahapan instalasi Magento pada CentOS 7.

Apa itu Magento?

Magento adalah platform e-commerce open-source yang ditulis menggunakan PHP. Magento salah satu sistem e-commerce terbuka yang paling populer. Magento dibuat menggunakan Zend Framework.

Kode sumber Magento didistribusikan di bawah Open Source Initiative (OSI) yang disetujui oleh Open Software License (OSL) v3.0, yang mirip dengan AGPL tetapi tidak sesuai dengan GPL. Selengkapnya dapat merujuk pada link berikut: Wikipedia Magento.

Berikut ini merupakan topologi sederhana yang akan saya gunakan

Pada topologi diatas saya membutuhkan 2 Instance diantaranya:

  1. Digunakan untuk server web server magento
  2. Digunakan untuk server database magento

Dimana nantinya server database magento akan terhubung dengan server web magento menggunakan private IP. Panduan kali ini saya menggunakan NEO Cloud sebagai penyedia layanan Cloud Computing yang mudah digunakan dan tentunya berkualitas dalam segi performance dan yang lainnya.

Tahapan Instalasi Magento 2.2

Akses Instance Web Server Magento

Silakan akses server Web Magento Anda, dan terlebih dahulu update sistem operasi CentOS 7 Anda menggunakan perintah berikut

[[email protected] ~]# yum update -y

Silakan tunggu sampai proses update selesai, jika sudah langkah selanjutnya menambahkan installasi epel gunakan perintah berikut

[[email protected] ~]#
[[email protected] ~]# yum install epel-release -y

Langkah selanjutnya yaitu instalasi web server, disini saya menggunakan Nginx. Untuk instalasi Nginx Anda hanya perlu menjalankan satu baris perintah berikut

[[email protected] ~]#
[[email protected] ~]# yum install nginx -y

Jika sudah silakan start, enable Nginx dan pastikan service nya running seperti berikut

[[email protected] ~]#
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[[email protected] ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-11-24 10:49:48 UTC; 9s ago
 Main PID: 15067 (nginx)
   CGroup: /system.slice/nginx.service
           ├─15067 nginx: master process /usr/sbin/nginx
           ├─15068 nginx: worker process
           └─15069 nginx: worker process

Nov 24 10:49:48 srv-web.hamim.web.id systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 24 10:49:48 srv-web.hamim.web.id nginx[15062]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
Nov 24 10:49:48 srv-web.hamim.web.id nginx[15062]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 24 10:49:48 srv-web.hamim.web.id systemd[1]: Started The nginx HTTP and reverse proxy server.
[[email protected] ~]# 

Selanjutnya instalasi PHP. Disini saya akan menggunakan php 7.2 webtatic, terlebih dahulu silakan enable repository webtatic sebagai berikut

[[email protected] ~]#
[[email protected] ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-12                ################################# [ 50%]
Cleaning up / removing...
   2:epel-release-7-11                ################################# [100%]
[[email protected] ~]# 
[[email protected] ~]# 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.6VcXw1: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]
[[email protected] ~]#

Selanjutnya instalasi ekstensi PHP72 yang dibutuhkan Magento 2 sebagai berikut,

[[email protected] ~]# 
[[email protected] ~]# yum install php72w-{fpm,cli,bcmath,devel,gd,iconv,intl,json,mbstring,mysqlnd,opcache,pdo,soap,xml} -y

Untuk melihat versi php gunakan perintah berikut:

[[email protected] ~]# 
[[email protected] ~]# php -v
PHP 7.2.24 (cli) (built: Oct 26 2019 12:28:19) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
[[email protected] ~]# 

Selanjutnya konfigurasi php.ini, di CentOS 7 php.ini berada di direktori /etc/php.ini silakan gunakan teks editor untuk membukanya, disini saya menggunakan vim.

[[email protected] ~]#
[[email protected] ~]# vim /etc/php.ini

Ubah beberapa parameter berikut:

memory_limit = 128M           >> memory_limit = 2G
max_execution_time = 30       >> max_execution_time = 1800
zlib.output_compression = Off >> zlib.output_compression = On
session.save_path = "N;/path" >> session.save_path = "/var/lib/php/session"

Jika sudah silakan simpan konfigurasi php.ini

Langkah selanjutnya melakukan konfigurasi php-fpm yang berada di direktori /etc/php-fpm.d/www.conf silakan buka menggunakan teks editor

[[email protected] ~]# 
[[email protected] ~]# vim /etc/php-fpm.d/www.conf

Ubah beberapa parameter berikut: 

user = apache           >> user = nginx
group = apache          >> group = nginx
listen = 127.0.0.1:9000 >> listen = /run/php-fpm/php-fpm.sock

Uncoment dan ubah beberapa parameter berikut:

;listen.owner = nobody >> listen.owner = nginx
;listen.group = nobody >> listen.group = nginx
;listen.mode = 0660    >> listen.mode = 0660

Uncoment beberapa parameter berikut:

;env[HOSTNAME] = $HOSTNAME                  >>  env[HOSTNAME] = $HOSTNAME 
;env[PATH] = /usr/local/bin:/usr/bin:/bin   >>  env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp                            >>  env[TMP] = /tmp
;env[TMPDIR] = /tmp                         >>  env[TMPDIR] = /tmp
;env[TEMP] = /tmp                           >>  env[TEMP] = /tmp

Jika sudah silakan simpan konfigurasi php-fpm.

Selanjutnya membuat direktori php session dan change owner nya menjadi nginx sebagai berikut:

[[email protected] ~]#
[[email protected] ~]# mkdir -p /var/lib/php/session
[[email protected] ~]# chown -R nginx:nginx /var/lib/php/
[[email protected] ~]# mkdir -p /run/php-fpm
[[email protected] ~]# chown -R nginx:nginx /run/php-fpm/
[[email protected] ~]#

Silakan start, enable dan pastikan service php-fpm Anda sudah running dengan normal sebagai berikut

[[email protected] ~]# 
[[email protected] ~]# systemctl start php-fpm
[[email protected] ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[[email protected] ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-11-24 11:18:37 UTC; 12s ago
 Main PID: 15302 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php-fpm.service
           ├─15302 php-fpm: master process (/etc/php-fpm.conf)
           ├─15303 php-fpm: pool www
           ├─15304 php-fpm: pool www
           ├─15305 php-fpm: pool www
           ├─15306 php-fpm: pool www
           └─15307 php-fpm: pool www

Nov 24 11:18:37 srv-web.hamim.web.id systemd[1]: Starting The PHP FastCGI Process Manager... 
Nov 24 11:18:37 srv-web.hamim.web.id systemd[1]: Started The PHP FastCGI Process Manager.    
[[email protected] ~]#
[[email protected] ~]# netstat -pl | grep php-fpm.sock
unix  2      [ ACC ]     STREAM     LISTENING     66249    15302/php-fpm: mast  /run/php-fpm/php-fpm.sock
[[email protected] ~]# 

Langkah selanjutnya unduh Magento dan ekstract Magento di dokumen root Nginx sebagai berikut

[[email protected] ~]#
[[email protected] ~]# cd /usr/share/nginx/html/
[[email protected] html]# 
[[email protected] html]# wget wget https://github.com/magento/magento2/archive/2.2.tar.gz
--2019-11-24 11:21:00--  http://wget/
Resolving wget (wget)... failed: Name or service not known.
wget: unable to resolve host address 'wget'
--2019-11-24 11:21:00--  https://github.com/magento/magento2/archive/2.2.tar.gz
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/magento/magento2/tar.gz/2.2 [following]   
--2019-11-24 11:21:00--  https://codeload.github.com/magento/magento2/tar.gz/2.2
Resolving codeload.github.com (codeload.github.com)... 13.250.162.133
Connecting to codeload.github.com (codeload.github.com)|13.250.162.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: '2.2.tar.gz'

    [                                                             <=>                                               ] 43,295,067  3.88MB/s   in 12s    

2019-11-24 11:21:13 (3.36 MB/s) - '2.2.tar.gz' saved [43295067]

FINISHED --2019-11-24 11:21:13--
Total wall clock time: 13s
Downloaded: 1 files, 41M in 12s (3.36 MB/s)
[[email protected] html]#

Ekstrack dan ubah direktori magento menjadi magento2, untuk penamaan direktori ini bersifat optional silakan disesuaikan dengan keinginan Anda masing - masing.

[[email protected] html]#
[[email protected] html]# tar -xzvf 2.2.tar.gz
[[email protected] html]# mv magento2-2.2/ magento2     
[[email protected] html]# 

Setup permission dan change owner direktori magento2 sebagai berikut

[[email protected] html]#
[[email protected] html]# cd magento2/
[[email protected] magento2]# 
[[email protected] magento2]# find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
[[email protected] magento2]# find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
[[email protected] magento2]# chown -R nginx:nginx .
[[email protected] magento2]# chmod u+x bin/magento
[[email protected] magento2]# 

Langkah selanjutnya instalasi composer gunakan perintah

[[email protected] magento2]#
[[email protected] magento2]# curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
All settings correct for using Composer
Downloading...

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

[[email protected] magento2]# 

Update dependensi Magento 2.2 menggunakan composer sebagai berikut

[[email protected] magento2]# composer install

Silakan tunggu sampai selesai.

Jika sudah selanjutnya konfigurasi Virtual Block Nginx sebagai berikut:

[[email protected] ~]#
[[email protected] ~]# vim /etc/nginx/conf.d/magento.conf

Isikan konfigurasi nginx sebagai berikut:

upstream fastcgi_backend {
  server unix:/run/php-fpm/php-fpm.sock;
}

server {

  listen 80;
  server_name hamim.web.id;
  set $MAGE_ROOT /usr/share/nginx/html/magento2;
  include /usr/share/nginx/html/magento2/nginx.conf.sample;
}

Silakan disesuaikan untuk server name nya, jika sudah silakan simpan konfigurasi virtualblock Nginx.

Langkah selanjutnya verivikasi konfigurasi Nginx dan restart nginx

[[email protected] ~]#
[[email protected] ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected] ~]#
[[email protected] ~]# systemctl restart nginx
[[email protected] ~]# systemctl status  nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-11-24 12:08:35 UTC; 1min 9s ago
  Process: 8519 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 8516 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 8514 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 8521 (nginx)
   CGroup: /system.slice/nginx.service
           ├─8521 nginx: master process /usr/sbin/nginx
           ├─8522 nginx: worker process
           └─8523 nginx: worker process

Nov 24 12:08:35 nur-srv-web02.novalocal systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Nov 24 12:08:35 nur-srv-web02.novalocal systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 24 12:08:35 nur-srv-web02.novalocal nginx[8516]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
Nov 24 12:08:35 nur-srv-web02.novalocal nginx[8516]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 24 12:08:35 nur-srv-

Akses Instance Database Magento

Langkah selanjutnya yaitu melakukan setup database magento, terlebih dahulu update sistem operasi CentOS 7 Anda menggunakan perintah

[[email protected] ~]#
[[email protected] ~]# yum update -y

Jika sudah silakan install database Magento, disini saya menggunakan MySQL Community versi 5.6. Unduh repository MySQL Community gunakan perintah berikut

[[email protected] ~]#
[[email protected] ~]# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm && sudo rpm -ivh mysql-community-release-el6-5.noarch.rpm
--2019-11-24 11:37:31--  http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.53.161.122
Connecting to repo.mysql.com (repo.mysql.com)|23.53.161.122|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5824 (5.7K) [application/x-redhat-package-manager]
Saving to: 'mysql-community-release-el6-5.noarch.rpm'

100%[==============================================================================================================>] 5,824       --.-K/s   in 0s      

2019-11-24 11:37:31 (137 MB/s) - 'mysql-community-release-el6-5.noarch.rpm' saved [5824/5824]

Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el6-5    ################################# [100%]
[[email protected] ~]# 

Install MySQL Server menggunakan perintah

[[email protected] ~]# 
[[email protected] ~]# yum install mysql-server -y

Untuk melihat versi MySQL yang telah berhasil di install gunakan perintah

[[email protected] ~]#
[[email protected] ~]# mysql -V
mysql  Ver 14.14 Distrib 5.6.46, for Linux (x86_64) using  EditLine wrapper
[[email protected] ~]#

Silakan start MySQL server Anda dan pastikan service nya suah running dengan normal sebagai berikut,

[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl status mysqld
● mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Sun 2019-11-24 11:42:06 UTC; 16s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 25278 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
 Main PID: 25564 (mysqld)

Setup username dan password root MySQL Server Anda gunakan perintah berikut

[[email protected] ~]#
[[email protected] ~]# mysql_secure_installation
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:   
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "C.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY! 

In order to log into MySQL to secure it, we'll need the current    
password for the root user.  If you've just installed MySQL, 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 MySQL
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 MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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]
 ... 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]
 ... Success!

By default, MySQL 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]
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - 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]
 ... Success!




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

Thanks for using MySQL!


Cleaning up...
[[email protected] ~]#

Konfigurasi max allowed packet MySQL pada my.cnf

[[email protected] ~]#
[[email protected] ~]# vim /etc/my.cnf

Seperti berikut

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
max_allowed_packet=16M
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

Jika sudah silakan simpan konfigurasi diatas.

Selanjutnya membuat database Magento yang di grant ke server web Magento, sebagai berikut

[[email protected] ~]#
[[email protected] ~]# vim /etc/my.cnf
[[email protected] ~]#
[[email protected] ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.6.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database magento;
Query OK, 1 row affected (0.00 sec)

mysql> create user hamimaja identified by 'Isikan_Password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on magento.* to [email protected] identified by 'Isikan_Password';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[[email protected] ~]#

Jika sudah silakan verisikasi atau pastikan di sisi web server magento sudah dapat remote database magento seperti berikut:

[[email protected] ~]#
[[email protected] ~]# mysql -u hamimaja -p -h 192.168.10.17
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.46 MySQL Community Server (GPL)

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

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

MySQL [(none)]> show databases;
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| magento            |  
+--------------------+  
2 rows in set (0.00 sec)

MySQL [(none)]> 

Konfigurasi Magento 2.2

Pada tahap terakhir terdapat 2 pemilihan untuk setup magento bisa menggunakan CLI ataupun Web Based.

Disini saya akan menggunakan yang Web Based namun saya akan memberikan contoh menggunakan CLI sebagai berikut:

Jika Anda ingin menggunakan CLI Anda dapat menggunakan tahapan berikut:

Pindah ke direktori root Magento

[[email protected] ~]# cd /usr/share/nginx/html/magento2/  
[[email protected] magento2]# 
[[email protected] magento2]# cd bin/
[[email protected] bin]# 
[[email protected] bin]# 

Berikut command yang dapat Anda gunakan bila ingin menggunakan CLI, namun sebelum itu Anda dapat menyesuaikan terlebih dahulu seperti, url magento, koneksi database (nama, username, password database), Username Magento, Credential Admin (username, password Magento), Nilai mata Uang yang digunakan, time atau waktu zona Anda berada, dan bahasa yang ingin Anda gunakan. Contohnya sebagai berikut:

[[email protected] bin]# ./magento setup:install --base-url=http://www.magento-dev.com/ \
--db-host=localhost --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=Magento --admin-lastname=User [email protected] \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1

Disini saya menggunakan Web Based saja berikut tahapannya:

Silakan akses melalui browser IP atau domain yang sudah di konfigurasi pada saat membuat virtual block Nginx sebelumnya.

Selanjutnya klik menu Start Readiness Check untuk melihat atau check ekstensi PHP dan melanjutkan ke tahapan berikutnya,

Konfigurasi database, silakan isikan semua credential database yang telah di setup sebelumnya pada server Database magento seperti berikut,

Konfigurasi Web, disini Anda dapat menyesuaikan URL yang ingin digunakan silakan disamakan dengan server name yang telah dibuat sebelumnya pada konfigurasi Nginx dan pada menu ini Anda dapat menentukan juga URL Admin Magento sesuai dengan keinginan Anda,

Sesuaikan time atau zona dimana Anda berada saat ini, mata uang yang ingin Anda gunakan, dan bahasa yang ingin Anda gunakan,

Membuat Admin Account disini Anda dapat menentukan credential untuk login ke Admin magento nantinya, silakan sesuaikan dengan keinginan Anda masing - masing.

Tahapan terakhir yaitu melakukan instalasi magento, silakan klik Install Now

Tunggu proses install sampai selesai yang membutuhkan waktu,

Jika sudah berhasil Anda akan mendapatkan informasi sebagai berikut

Silakan login ke Admin Magento, dan isikan username dan password yang telah Anda buat sebelumnya,

Berikut tampilan Dashboard Magento 2.2

Berikut tampilan default Magento 2.2

Selamat Mencoba semoga bermanfaat bagi kita semua !.

See You >.<