Learn some CentOS Linux : Redhat Linux

This is mostly about Centos Linux. However, this also shows commands related to how to install Magento 2 on LEMP (E for Nginx Web-server). Some PHP related stuff are there as well.

LEMP + CentOS + Magento 2 : VM Image or one click install: I did not see readily available on Upcloud, AWS Lightsail, Vultr, and Digital Ocean. I might share the Image for this cloud instance. Magento 2 + Ubuntu is there; though not with CentOS.

1 php -v

2 systemctl status nginx
3 systemctl status httpd

5 systemctl status mysql
6 mysql
8 yum update
9 reboot

Create SWAP
10 fallocate -l 1G /swapfile

12 chmod 600 /swapfile
13 mkswap /swapfile

15 swapon /swapfile

Make swap permanent
16 vi /etc/fstab
17 /swapfile swap swap defaults 0 0
18 swapon --show

Check disk spaces
19 free -h
20 cat /proc/sys/vm/swappiness
21 cat /etc/fstab
22 swapon --show
23 free -h
24 cat /proc/sys/vm/swappiness
25 sysctl vm.swappiness=10
26 vi /etc/sysctl.conf

Create a user: Better not to work as root

27 useradd sahmed
30 passwd sahmed

Assign sahmed to wheel group i.e. make sahmed as sudo

31 usermod -aG wheel sahmed

33 su - sahmed
34 mysql -u root -p
35 mysql

Install PHP Modules as will be required by Magento and by many other PHP based applications and frameworks

36 sudo yum install php-mysql php-opcache php-xml php-mcrypt php-gd php-soap php-redis php-bcmath php-intl php-mbstring php-json php-iconv php-fpm php-zip
37 vi configure.sh
38 su - sahmed
39 reboot

PHP-FPM is faster
40 systemctl restart php-fpm
41 sudo su - magento
42 sudo chmod 750 /opt/magento
43 sudo su - magento
44 sudo systemctl restart php-fpm
45 sudo su - magento
46 vi /etc/php.ini
47 su - magento

ext-intl, and php-intl might give you a hard time

48 yum -y install ext-intl
49 yum -y install php*intl
50 yum -y list php*intl
51 yum -y install php-intl.x86_64
52 yum -y list php*intl
53 yum -y install php72u-intl.x86_64

Couple of above lines might not work or might not give good results

Creating a user for magento though not required. You can create any sudo user other than root (better not to use root)

54 sudo su - magento
55 exit
56 su - root
57 su - magento
58 su - sahmed

60 yum -y install php72*

The above line will help a lot : 60. Will install many of the required packages though might install some more

61 yum update
62 yum makecache
63 su - sahmed
64 reboot
65 su
66 su - magento
67 vi /etc/php.ini
68 systemctl restart php-fpm
69 su - magento
70 systemctl reload php-fpm
71 systemctl restart php-fpm
72 su -
73 mysql
74 history | grant
75 mysql
76 sudo su - sahmed

Configure your domain under nginx web-server

77 vi /etc/nginx/nginx.conf
78 vi /etc/nginx/conf.d/shopforsoul.com.conf
79 systemctl reload nginx
80 ping shopforsoul.com
81 ping shopforsoul.com

82 ifconfig
83 hostname

lynx a web-browser
84 lynx shopforosul.com
85 yum -y install lynx
86 lynx shopforosul.com

Check access and error log: why not working
87 ls /var/log/nginx/access.log
88 tail /var/log/nginx/access.log
89 tail /var/log/nginx/error.log
90 vi /etc/nginx/conf.d/shopforsoul.com
91 tail /var/log/nginx/error.log

Issues were there related to lets encrypt i.e. ssl. as I modified /etc/hosts and assigned the cloud instance to the domain. domain is pointing to a different ip in reality. though used the domain so that I can test. later the domain DNS can be just changed to this cloud instance

On config files, duplicates entries were for the domain i.e. duplicate server {}
also under server: some lines were related to let's encrypt and ssl ports. commented thouse out
Let's encrypt command as used here will work for sure. Last line for let's crypt might not work as DNS for the domain in real life points to another IP. when this is adjusted everything will work

92 vi /etc/nginx/conf.d/default.conf
93 systemctl reload nginx
94 systemctl restart nginx
95 tail /var/log/nginx/error.log
96 vi /etc/nginx/conf.d/shopforsoul.com
97 rm /etc/nginx/conf.d/shopforsoul.com
98 vi /etc/nginx/conf.d/shopforsoul.com.conf
99 systemctl restart nginx
100 systemctl reload nginx
101 vi /etc/nginx/conf.d/shopforsoul.com.conf
102 pwd
103 cd /opt/magento/public_html/
104 ls
105 ls app/etc/env.php
106 vi app/etc/env.php

Check what is the admin url for magento 2

107 php bin/magento info:adminuri
108 history > /home/sahmed/magento_install_history.txt

----

The following commands were also used as part of installing Magento 2. However, under the user sahmed.

1 sudo ls -l /root

3 systemctl status php-fpm

PHP repos: remi is one, ius is another.

4 yum repolist | grep epel
5 yum repolist
6 epel/x86_64

This is let's encrypt and SSL. You might want to do this before configuring Nginx and also before starting to install magento. Though remember, the domain will need to be a live one with proper DNS settings.

7 yum install certbot
8 sudo yum install certbot
9 sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
10 sudo mkdir -p /var/lib/letsencrypt/.well-known
11 sudo chgrp nginx /var/lib/letsencrypt
12 sudo chmod g+s /var/lib/letsencrypt
13 sudo mkdir /etc/nginx/snippets
14 cat /etc/nginx/snippets/letsencrypt.conf
15 vi /etc/nginx/snippets/letsencrypt.conf
16 sudo vi /etc/nginx/snippets/letsencrypt.conf
17 cat /etc/nginx/snippets/ssl.conf
18 vi /etc/nginx/snippets/ssl.conf
19 sudo vi /etc/nginx/snippets/ssl.conf
20 cat /etc/nginx/conf.d/shopforsoul.com
21 sudo vi /etc/nginx/conf.d/shopforsoul.com
22 sudo systemctl reload nginx
23 sudo certbot certonly --agree-tos --email sahmed --webroot -w /var/lib/letsencrypt/ -d shopforsoul.com

The above line though a must might fail if domain/DNS not appropriate

24 mysql -u root -p
25 mysql
26 sudo mysql
27 exit
28 sudo rm -f /opt/magento/public_html/*
29 sudo su ma- gento
30 sudo su - magento
31 exit

Adjust configurations as are important for Magento 2
32 sudo sed -i "s/memory_limit = .*/memory_limit = 756M/" /etc/php.ini
33 sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php.ini
34 sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php.ini
35 sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php.ini
36 sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php.ini
37 sudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php.d/10-opcache.ini

Use composer to install Magento 2
38 curl -sS https://getcomposer.org/installer | php
39 sudo mv composer.phar /usr/local/bin/composer
40 sudo useradd -m -U -r -d /opt/magento magento
41 sudo usermod -a -G magento nginx
42 sudo chmod 750 /opt/magento
43 cat /etc/php-fpm.d/magento.conf
44 vi /etc/php-fpm.d/magento.conf
45 sudo vi /etc/php-fpm.d/magento.conf
46 sudo systemctl restart php-fpm
47 sudo su - magento
48 yum install php-intl
49 sudo yum install php-intl
50 php -v

52 sudo yum install php-pecl-intl

54 yum install php-intl

56 sudo yum update

59 sudo yum makecache
60 sudo yum update

68 php -v
69 sudo systemctl restart nginx
70 sudo systemctl restart php

75 sudo yum install --skip-broken php-intl
76 sudo yum -y install php-common
77 sudo yum -y --skip-broken install php-common
78 sudo yum install --skip-broken php-intl
79 sudo yum install php-intl
80 sudo yum install --skip-broken php-intl

better try not to use the --skip-broken option
yum -y install php72* helped a lot to fix missing package issue. You can ignore yum install php-intl ext-intl php72-intl or similar. yum -y install php72* is the solution

Creating another user for magento 2
81 su - magento
82 sudo su - magento
83 reboot
84 exit
85 su - magento
86 sudo su - magento
87 exit
88 sudo su - magento
89 exit

91 sudo su - magento
92 sudo vi /etc/nginx/conf.d/shopforsoul.com.conf
93 su - magento
94 exit
95 sudo su - magento
96 exit
97 history | grep encrypt
98 history

--

Some commands as executed with user Magento
1 ls /opt/
2 ls /opt/magento/
3 ls /opt/magento/public_html/
4 ls /opt/magento/public_html/ -la

where I kept Magento: /opt/magento/public_html/

5 rm -rf .*
6 rm -rf *.*

You might need rm for cases installation fails and you need to reinstall

7 ls /opt/magento/public_html/ -la
8 rm .gitignore
9 pwd
10 rm -rf /opt/magento/public_html/.*
11 ls /opt/magento/public_html/ -la
12 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html

Use public key as user id
use private key as password

13 php -i
14 php -i | grep php.ini
15 vi php.ini
16 exit

You know repeating as things went wrong esp. missing packages for php

17 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
18 rm -rf /opt/magento/public_html/*
19 rm -rf /opt/magento/public_html/.*
20 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
21 exit
22 rm -rf /opt/magento/public_html/.*
23 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
24 rm -rf /opt/magento/public_html/.*
25 rm -rf /opt/magento/public_html/*
26 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
27 yum repolist | grep php72
28 yum list | grep php72
29 exit
30 rm -rf /opt/magento/public_html/*
31 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
32 rm -rf /opt/magento/public_html/*
33 rm -rf /opt/magento/public_html/.*
34 composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html
35 exit
36 cd ~/public_html/
37 ls

This is how you install magento 2

38 php bin/magento setup:install --base-url=sayedum" --admin-user="shopforsoul" --admin-password="" --db-name="magento" --db-host="localhost" --db-user="magento" --currency=USD --timezone=America/Chicago --use-rewrites=1 --db-password=""

Crontab for Magento System Tasks

39 php ~/public_html/bin/magento cron:install
40 crontab -l
41 vi /etc/nginx/conf.d/shopforsoul.com.conf
42 sudo vi /etc/nginx/conf.d/shopforsoul.com.conf
43 exit
44 systemctl reload nginx
45 exit
46 history