Thursday, June 18, 2020

LAMC stack - U20-Apache-CGI-M (Installing Ubuntu 20LTS) * bearbone server

Technologies:

Ubuntu 20.04.1 LTS / MySQL 8 /PHP 7.4-(fpm)(mod_security)  /Composer 1.7 /Redis-6.0.9 / ElasticSearch7.10
Apache FastCGI with PHP-FPM is one of the best stacks to host PHP applications. This stack is not as easy as setting up a basic LAMP stack, but it is far better than the basic LAMP stack when it comes to performance. The key ingredient in this stack is FPM which stands for Fast Process Manager. In this stack, Apache will send all the PHP files for processing to FPM. It will then return the rendered output to the browser -
Hello hello how are you
Hello hello its good to see you! 
I say hello, to you and all your friend.
I say hello, lets meet them together! lets play together
Lets have fun with friends.
We are all friends.
Song credit: Sing along to the Hello song from 'Something Special'. Visit http://www.bbc.co.uk/cbeebies to find even more fun games and videos for your pre-schooler in a safe child friendly environment.


Pertition:
swap  - 0% to 200% of system memory.
/boot - if needed, 2.5GiB or less.
/opt  - only if explicitly needed. Size as req'd
/app  - same as opt
/var  - only if needed, 5 to 10GiB
/tmp  - put it on root, otherwise 512MiB to 2.5GiB
/usr  - put it on root, otherwise 35 to 40GiB
/     - (root) 10GiB min (if other parts used), otherwise 65GiB
/home - Whatever is left

----- What I use on my non-work computers -----
/     - 100GiB
/var  - only if needed, 10GiB
swap  - no more than 100% or 150% of system memory
/boot - if needed, 2.5GiB or less.
/home - Whatever is left
Ubuntu version
lsb_release -a
service --status-all
Hostname
sudo hostnamectl
hostname
hostname --fqdn
dnsdomainname

sudo vi /etc/hosts
127.0.1.1 www.ejamuna.com node1
vi /etc/hosts
# IPv4 and IPv6 localhost aliases
127.0.0.1  node2.mg.com  node2 localhost
::1        node2.mg.com  node2 localhost

Securing your Server *

Update Your System–Frequently
sudo apt update && sudo apt upgrade -y

Adding a Limited User Account

$useradd tommy -m -s /bin/bash -g users -c "my comments"
$passwd tommy (change password for the mentioned user)
(Make a sudo previlage: adduser example_user sudo)

Change passwd for the root user:

$sudo passwd root

Create an Authentication Key-pair (client pc)

  • Upload the public key to your Server.
  • Test your keys are working and make a note for the passcodes.
Inside the /etc/ssh/sshd_config file:
    Disallow root logins over SSH
        PermitRootLogin no
    Disable Password authentication
        PasswordAuthentication no
sudo service sshd restart
Test: ssh mg@192.168.10.115 password login is denied by public key!

Handy scripts (create ssh for a user)

sudo useradd tommy -m -s /bin/bash -g users -c "my comments"
sudo passwd tommy 
sudo mkdir -p /home/tommy/.ssh
sudo chown tommy:users -R /home/tommy/.ssh/
sudo chmod -R 700 /home/tommy/.ssh/
ls -al /home/tommy
sudo vi /etc/ssh/sshd_config
  PasswordAuthentication no
sudo service sshd restart

# Local pc
ssh-keygen -t rsa -b 4096 -f /drives/c/Users/Rita/OneDrive/Programming/SSH/ejamuna_com -C "admin@ejamuna.com"
ssh-copy-id -i /drives/c/Users/Rita/OneDrive/Programming/SSH/ejamuna_com.pub mg@192.168.10.13

sudo vi /etc/ssh/sshd_config
  PasswordAuthentication yes
sudo service sshd restart

Installing packages

Update Your System–Frequently
sudo apt update && sudo apt upgrade -y
Install example
Check if the package exists on https://packages.ubuntu.com/
apt install vim
apt update
Reinstall
apt-get install --reinstall systemctl
List the full path of the files inside this package
dpkg -L systemctl
Check if any output for systemctl
apt-cache search systemctl
Using Init scripts to manage services on Ubuntu
To start a service: /etc/init.d/ufw start
To stop a service: /etc/init.d/ufw stop
To stop a service: /etc/init.d/ufw restart
To check the status of service: /etc/init.d/ufw status

How To Install Package on Ubuntu

sudo apt-get update -y
sudo apt-get install -y unzip
apt-get install net-tools

MySQL 8 in Ubuntu 20

Uninstall


sudo -i
service mysql stop
killall -KILL mysql mysqld_safe mysqld
apt-get --yes purge mysql-server mysql-client
apt-get --yes autoremove --purge
apt-get autoclean
deluser --remove-home mysql
delgroup mysql
rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld
updatedb
exit


Installing MySQL 8 on Ubuntu:

sudo apt update && sudo apt upgrade -y
sudo apt install curl nano git
It is important to specify the version of mysql, e.g. (apt purge on an already removed package. Usually, apt remove is more than enough for uninstalling a package.)
apt --yes purge mysql-server-5.7 mysql-client-5.7
sudo apt-cache search mysql | grep client
    >output>    mysql-client-8.0 - MySQL database client binaries
sudo apt-cache search php- | less
>Custom install> sudo apt-get install mysql-server-5.7 mysql-client-5.7 -y
To install MySQL, run the following command from a terminal prompt:
sudo apt install mysql-server
The network status of the MySQL service can also be checked by running the ss command at the terminal prompt:
sudo ss -tap | grep mysql
When you run this command, you should see something similar to the following:
LISTEN    0         151              127.0.0.1:mysql             0.0.0.0:*       users:(("mysqld",pid=149190,fd=29))
LISTEN    0         70                       *:33060                   *:*       users:(("mysqld",pid=149190,fd=32))
If the server is not running correctly, you can type the following command to start it:
mysql -V
sudo service mysql restart
A good starting point for troubleshooting problems is the systemd journal, which can be accessed at the terminal prompt with this command:
sudo journalctl -u mysql
[
/usr/bin/mysql -u root -p
***
mysql> quit;
]
Do not write mysql -u root, Just write "sudo mysql", In Ubuntu systems running MySQL 5.7 (and later), the root user is authenticated by the auth_socket plugin by default.
(For version MySQL 5.7 and later, enter the following command in the mysql shell, replacing password with your new password:)

Secure the MySQL

sudo mysql_secure_installation utility
Answer them all with ...y

Start /stop

sudo service mysql start 
sudo service mysql stop 
sudo service mysql restart 
After making a configuration change, the MySQL daemon will need to be restarted:
sudo systemctl restart mysql.service

Start the server on System startup

sudo systemctl enable mysql

Create a new database, user, and to grant privileges for the database to the user /revoke.

Create user and Database
sudo mysql
REVOKE ALL PRIVILEGES ON dbname.* TO 'user1'@'localhost';
DROP database dbname;
DROP USER 'user1'@'localhost';
CREATE DATABASE dbname;
CREATE USER 'user1'@'localhost' IDENTIFIED BY '%^passg7W';
>Only for below 8>GRANT ALL PRIVILEGES ON dbname.* TO 'user1'@'localhost' IDENTIFIED BY '%^passg7W';

MySQL8 = (
 GRANT ALL ON dbname.* TO 'user1'@'localhost';
 ALTER USER 'user1'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
)

FLUSH PRIVILEGES;
quit
Views
mysql> SELECT User, Host, authentication_string FROM mysql.user;
mysql> show databases;
mysql> DROP database dumbschool;
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Display MySQL User Account Privileges:
SHOW GRANTS FOR 'user1'@'localhost';
Revoke Privileges from a MySQL User Account
mysql> REVOKE ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
Remove an Existing MySQL User Account
mysql> DROP USER 'user'@'localhost'
Import a Database
mysql -u username -p database_name < FILE.sql

Firewall: SELinux

Todo
Todo

Firewall: UFW

https://linuxize.com/post/how-to-setup-a-firewall-with-ufw-on-ubuntu-18-04
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04
Got connection refused! plz check bellow.
apt-get install  ufw
sudo ufw app list
sudo ufw status verbose
sudo ufw status
Let us look into the “Apache Full” profile. To do so, run:
sudo ufw app info 'Apache Full'
Run the following command to allow incoming HTTP and HTTPS traffic for this profile:
sudo ufw allow 'Apache Full'
sudo ufw allow 'OpenSSH'
sudo ufw allow 10000/tcp
Configure Your Firewall:
sudo ufw disable
sudo ufw enable
ufw reset ( turn off UFW completely and delete all the rules)
Delete rule:
sudo ufw status numbered
ufw delete *2
ufw delete allow http123
Anything actually listening on port 80 :
netstat -lpn | grep :80


iptables *

chkconfig iptables
iptables -L -v -n --line-number
sudo lsof -n -sTCP:LISTEN -i:80
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
Then to prevent it from losing the iptables configuration on restart, use:
sudo apt install iptables-persistent
sudo /etc/init.d/netfilter-persistent save
./firewall-reload
iptables-save > /etc/iptables/iptables.rules
reboot now

netplan

ip a
ip route
 
nslookup google.com
ifconfig
 
netplan generate
netplan apply

Install Apache2.4


sudo apt update && sudo apt upgrade -y
sudo apt-get install curl nano git wget vim -y
sudo apt-cache search apache2 | grep ver
sudo apt-get install apache2 -y
apache2 -version
Enable on Startup: 
sudo systemctl enable apache2
Backup your orginal site config file
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.orginal sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf.orginal sudo cp /etc/apache2/mods-enabled/fastcgi.conf /etc/apache2/mods-enabled/fastcgi.conf.backup

Redhat: /etc/httpd/

Install FastCGI:

CGI like FastCGI processes are persistent and they can handle more than one requests per processes.
sudo apt-cache search apache2 | grep libapache2-mod-fcgi
Note: sudo apt install libapache2-mod-fcgi (not working now. 2019)
sudo apt install libapache2-mod-fcgid -y (working...2020 )

cd /tmp && wget https://mirrors.edge.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb
sudo dpkg -i libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb

Start: 
sudo systemctl start apache2.service 
service apache2 start
Status: 
sudo systemctl status apache2
service apache2 status
Restart: 
sudo systemctl restart httpd
sudo systemctl restart apache2.service
service apache2 restart
Reload: 
sudo systemctl reload apache2.service
service apache2 reload
Stop: 
sudo systemctl stop apache2.service

Configuration files:

Redhat: /etc/httpd/conf/httpd.conf
/etc/apache2/apache2.conf – This is the main Apache configuration file and controls everything Apache does on your system. Changes here affect all the websites hosted on this machine.

/etc/apache2/ports.conf – The port configuration file. You can customize the ports Apache monitors using this file.  By default, Port 80 is configured for Http traffic.
/etc/apache2/sites-available – Storage for virtual host files. A virtual host is a record of one of the websites hosted on the server.
/etc/apache2/sites-enabled – This directory holds websites that are ready to serve clients. The a2ensite command is used on a virtual host file in the sites-available directory to add sites to this location.

Default webroot: /var/www/html/

*** Checking the inbound rules from the EC2 dashboard, from below we can see that only the “PORT 22” is open, which is only for “SSH“.
See the ufw firewall section.

Install Modules:
a2enmod proxy_http 
a2enmod proxy

service apache2 reload

PHP 7.4 (fpm - Fast Process Manager)

sudo apt update && sudo apt upgrade -y
sudo apt-cache search php7.2 | grep php
To verify if PHP is installed already, in the command line, type:
php -v
Uninstall PHP
For General PHP-fpm install:
$ sudo apt-get install php7.4-fpm php7.4-mysql php7.4-mbstring php7.4-curl php7.4-dom -y
For Magento General PHP install with req modules: (replace the php7.2 with the phpfpm one)
$ sudo apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-iconv php7.2-soap -y
For Magento with FPM only
$ sudo apt install php7.4-fpm libapache2-mod-php7.4 php7.4-common php7.4-gd php7.4-mysql php7.4-curl php7.4-intl php7.4-xsl php7.4-mbstring php7.4-zip php7.4-bcmath php7.4-iconv php7.4-soap -y
php -v

Laravel Server Requirements mention that BCMath, Ctype, JSON, Mbstring, OpenSSL, PDO, Tokenizer, and XML extensions are required. Most of the extensions are installed and enabled by default. 

PHP version-specific installation (if PHP 7.4 installed) 

sudo apt-get install zip unzip php-zip


sudo apt install php7.4-fpm php7.4-common php7.4-bcmath openssl php7.4-json php7.4-mbstring php-xml php-mysql php7.4-curl -y

sudo phpenmod pdo_mysql

libapache2-mod-php7.4

sudo apt-cache search apache2 | grep libapache2-mod-e
$ sudo apt install php7.3-fpm libapache2-mod-php7.3 php7.3-common php7.3-gd php7.3-mysql php7.3-curl php7.3-intl php7.3-xsl php7.3-mbstring php7.3-zip php7.3-bcmath php7.3-iconv php7.3-soap -y
Verify that all required PHP extensions were installed:
sudo php -me

and check "Server API Apache 2.0 Handler" that is PHP-FPM is not configured yet!

To locate the PHP command-line configuration, enter
php --ini | grep "Loaded Configuration File"


Configure Apache with PHP-fpm on Ubuntu 20

Right now, Our Apache web server and PHP-FPM are configured and can work individually. But we still have to tell our Apache webserver to pass PHP requests to PHP fast process manager.
To enable PHP 7.4 FPM in Apache2 do (after php7.2-fpm installed): [If disable the older version of PHP (a2dismod [oldversion])] [Edit for 7.* if version changed]
sudo cat /etc/apache2/conf-available/php7.4-fpm.conf
sudo cp /etc/apache2/conf-available/php7.4-fpm.conf /etc/apache2/conf-available/php7.4-fpm.conf.orginal
sudo vi /etc/apache2/conf-available/php7.4-fpm.conf
<IfModule mod_fastcgi.c>
        AddHandler php7-fcgi .php
        Action php7-fcgi /php7-fcgi
        Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
        FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.4-fpm.sock -pass-header Authorization -idle-timeout 60
        <Directory /usr/lib/cgi-bin>
                Require all granted
        </Directory>
</IfModule>
Test conf script for errors:
sudo apache2ctl configtest
PHP 7.4 FPM disabled by default. To enable PHP 7.4 FPM in Apache2 do:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.4-fpm
sudo a2enmod actions expires
sudo systemctl restart apache2
sudo systemctl reload apache2
The module proxy_fcgi provides support for the FastCGI protocol. The associated setenvif sets the variables sent to the FastCGI.
sudo systemctl restart php7.4-fpm apache2
sudo service php7.4-fpm status



Making a new website with a domain

Make a particular user for a particular site standard practice and also put him to the www group.
sudo mkdir -p /var/www/ejamuna.com
Then assign the ownership of the directory to Apache2 through the following commands:

Is Apache running as www-data?
ps axu | grep -E 'apache|www-data|http'

sudo chown -R <www-data>:www-data /var/www/ejamuna.com
no need: sudo chmod -R 755 /var/www/ejamuna.com


[ no need also
        sudo chown -R ec2-user:apache /var/www

        sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;

        find /var/www -type f -exec sudo chmod 0664 {} \;
]


Create HTML file:
echo "ejamuna!" > /var/www/ejamuna.com/index.php 
or
sudo vi /var/www/ejamuna.com/j.php
<h1>eJamuna!</h1>
<?php
 phpinfo();
?>
If you want to change Apache to serve PHP files rather than others, move index.php to first position in the dir.conf file as shown below:
sudo vi /etc/apache2/mods-enabled/dir.conf
Apache needs a virtual host file to serve the contents of your domain from the server.
sudo vi /etc/apache2/sites-available/ejamuna.com.conf
<VirtualHost *:80>
 ServerAdmin webmaster@ejamuna.com
 ServerName ejamuna.com
 ServerAlias www.ejamuna.com
 DocumentRoot /var/www/ejamuna.com

 #ProxyPass / http://localhost:3000/
 #ProxyPassReverse / http://localhost:3000/

 <Directory "/var/www/ejamuna.com">
   AllowOverride All
 </Directory>

 <FilesMatch \.php$>
  SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
 </FilesMatch>
 ErrorLog ${APACHE_LOG_DIR}/ejamuna.com-error.log
 CustomLog ${APACHE_LOG_DIR}/ejamuna.com-access.log combined
</VirtualHost>
Test for errors:
sudo apache2ctl configtest

Enable the domain configuration file:

sudo a2ensite ejamuna.com.conf
a2ensite 000-default.conf
a2ensite default-ssl.conf
To disable a website:
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
sudo service apache2 reload
Handy codes:
sudo mkdir /var/www/ejamuna.com
sudo chown -R <www-data>:www-data /var/www/ejamuna.com

SSL

Update Your System–Frequently
sudo apt update && sudo apt upgrade -y

Install Certbot Apache on Ubuntu 20.04

Enable the universe repository
sudo apt-get update 
sudo apt-get install software-properties-common 
sudo add-apt-repository universe 
sudo apt-get update
Install the Certbot 
Run this command on the command line on the machine to install Certbot. 
sudo apt-get install certbot python3-certbot-apache
Version (24 Jun, 2020)
certbot --version
My version of certbot was 0.40.0

Get a certificate with Route 53 plugin

Install correct DNS plugin
-sudo apt install python3-certbot-dns-<PLUGIN>
sudo apt install python3-certbot-dns-route53
Manual

The access keys for an account with these permissions must be supplied in one of the following ways, which are discussed in more detail in the Boto3 library’s documentation about configuring credentials.


Examples: 
certbot certonly \
  --dns-route53 \
  --dns-route53-propagation-seconds 30 \
  -d example.com \
  -d www.example.com

Install certificate Manually( without Plugins)


Generate Strong Dh (Diffie-Hellman) Group
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

Obtaining a Let’s Encrypt SSL certificate
sudo vi /etc/apache2/conf-available/letsencrypt.conf
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

sudo vi /etc/apache2/conf-available/ssl-params.conf
# SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:\
ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA256:\
ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:\
ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA256:\
ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:\
DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256

SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder On
# Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4
SSLCompression off
# Requires Apache >= 2.4.11
SSLSessionTickets Off
# Activate OCSP stapling on Apache 2.4+
# https://www.tbs-certificates.co.uk/FAQ/en/active-ocsp-apache.html

# SSLUseStapling on
# SSLStaplingCache "shmcb:logs/stapling_cache(128000)"
SSLStaplingCache shmcb:/var/tmp/ocsp-stapling-cache/cache(128000000)
SSLUseStapling on
SSLStaplingResponderTimeout 2
SSLStaplingReturnResponderErrors off
SSLStaplingFakeTryLater off
SSLStaplingStandardCacheTimeout 86400

# https://www.tbs-certificates.co.uk/FAQ/en/install-cert-ssl-apache-2-4-8.html
SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"
SSLOpenSSLConfCmd ECDHParameters secp384r1
# https://httpd.apache.org/docs/current/mod/mod_ssl.html 
SSLOptions +StrictRequire
# Add vhost name to log entries:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
Test for errors: 
sudo apache2ctl configtest
Enable these mods: 
sudo a2enmod ssl headers
Enable these scripts: 
sudo a2enconf letsencrypt ssl-params
Enable these mods: 
sudo a2enmod http2 rewrite
Reload Apache2: 
sudo systemctl reload apache2 (conf)
sudo systemctl restart apache2 (mod)
sudo service apache2 reload
Apache Status checking: 
sudo systemctl status apache2


sudo mkdir -p /var/lib/letsencrypt/
sudo chgrp www-data /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt
sudo mkdir -p /var/lib/letsencrypt/.well-known/acme-challenge/
sudo chmod -R 775 /var/lib/letsencrypt
Testing the setup:
sudo gpasswd -a tommy_user javagroup     (add user to a group)
sudo echo -n "Testing acme-challenge" >  /var/lib/letsencrypt/.well-known/acme-challenge/test
sudo curl -ikL http://www.ejamuna.com/.well-known/acme-challenge/test
Setting directories with g+s makes all new files created in the said directory have their group set to the directory's group. When used on a directory, instead, the setgid bit alters the standard behaviour so that the group of the files created inside said directory, will not be that of the user who created them, but that of the parent directory itself. This is often used to ease the sharing of files (files will be modifiable by all the users that are part of said group).
This can actually be really handy for collaborative purposes if you have the umask set so that files have group write by default.

Obtain the certificate 

Getting a certificate:
Ref: Example 1:
Ref: Example 2:
certbot certonly \
        -d example.com \
        -d *.example.com \
        --dns-route53 \
        --logs-dir /home/username/letsencrypt/log/ \
        --config-dir /home/username/letsencrypt/config/ \
        --work-dir /home/username/letsencrypt/work/ \
        -m email@example.com \
        --agree-tos \
        --server https://acme-v02.api.letsencrypt.org/directory
Renew example:
certbot renew --dns-route53 \
        --logs-dir /home/username/letsencrypt/log/ \
        --config-dir /home/username/letsencrypt/config/ \
        --work-dir /home/username/letsencrypt/work/ \
        --server https://acme-v02.api.letsencrypt.org/directory \
        --post-hook "sudo service nginx reload"
dns-route53 plugin: certbot website
sudo certbot certonly \
        -i apache \
        --dns-route53 \
        --dns-route53-propagation-seconds 30 \
        -d dumbschool.com \
        -d www.dumbschool.com \
        --agree-tos \
        --email bdjunayed@gmail.com
Webroot: authenticator plugin (Single domain)
sudo certbot certonly \
 -i apache \
 -a webroot \
 -w /var/www/haanz.online/ \ -w /var/lib/letsencrypt/ \
 -d haanz.online \
 -d www.haanz.online \
 --email bdjunayed@gmail.com \
 --agree-tos \
 --server https://acme-v02.api.letsencrypt.org/directory
Webroot: authenticator plugin (to obtain a single certificate for multiple domains)
To use the webroot plugin, your server must be configured to serve files from /.well-known
sudo certbot certonly \
        --webroot \
        -w /var/www/d1.com \
        -d d1.com \
        -w /var/www/d2.com \
        -d d2.com
        --agree-tos \
        --email bdjunayed@gmail.com \
Manual: kind of webroot plugin but manual.
sudo certbot certonly \
        --preferred-challenges=dns \
        --manual
        -d example.com \
        -d www.example.com \
Manual: (CrazyDomain don't allow the TXT record)
sudo certbot certonly \
        --preferred-challenges=http \
        --manual \
        -d saustralasia.online \
        -d www.saustralasia.online \
        --email bdjunayed@gmail.com \
        --agree-tos \
        --server https://acme-v02.api.letsencrypt.org/directory
Successful output sample: 
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Cert not yet due for renewal
You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/saustralasia.online.conf)
What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Keep the existing certificate for now
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Renewing an existing certificate
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/saustralasia.online/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/saustralasia.online/privkey.pem
   Your cert will expire on 2020-03-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
root@node1:~#
Now, you have the certificate files, edit your domain virtual host configuration as follows:

sudo vi /etc/apache2/sites-available/ejamuna.com.conf

<VirtualHost *:80>
        ServerAdmin admin@ejamuna.com
        ServerName ejamuna.com
        ServerAlias www.ejamuna.com
        DocumentRoot /var/www/ejamuna.com/pub
        <Directory /var/www/ejamuna.com>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
         #ProxyPass / http://localhost:3000/
         #ProxyPassReverse / http://localhost:3000/

<FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/" </FilesMatch>
        ErrorLog ${APACHE_LOG_DIR}/ejamuna.com-error.log
        CustomLog ${APACHE_LOG_DIR}/ejamuna.com-access.log combined

        #Redirect permanent / https://ejamuna.com/

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.ejamuna.com [OR]
        RewriteCond %{SERVER_NAME} =ejamuna.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName ejamuna.com
        ServerAlias www.ejamuna.com
        ServerAdmin admin@ejamuna.com

        Protocols h2 http:/1.1

        #<If "%{HTTP_HOST} == 'www.ejamuna.com'">
        #        Redirect permanent / https://ejamuna.com/
        #</If>

        DocumentRoot /var/www/ejamuna.com/pub
# Apache 2.4 If you are not the administrator of the server, you depend # on the AllowOverride Level that theses admins allows for you. <Directory /var/www/ejamuna.com> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory>
         #ProxyPass / http://localhost:3000/
         #ProxyPassReverse / http://localhost:3000/

<FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/" </FilesMatch>
        # Allow encoded slashes
        AllowEncodedSlashes NoDecode
        ErrorLog ${APACHE_LOG_DIR}/ejamuna.com-error.log
        CustomLog ${APACHE_LOG_DIR}/ejamuna.com-access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        SSLEngine On
        # Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/ejamuna.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/ejamuna.com/privkey.pem
        # SSLCertificateChainFile /etc/letsencrypt/live/saustralasia.online/chain.pem (Obsolute)

        Header always set Strict-Transport-Security "max-age=31536000"
        Header always set Content-Security-Policy upgrade-insecure-requests
</VirtualHost>
</IfModule>
Test for errors: 
sudo apache2ctl configtest
Reload Apache2 for conf: 
sudo service apache2 reload
Test your certificate: 

Auto-renewing Let’s Encrypt SSL certificate

Ref: Certbot documentation
Let’s Encrypt’s certificates are valid for 90 days. To automatically renew the certificates before they expire, the certbot package creates a cronjob which runs twice a day and will automatically renew any certificate 30 days before its expiration.
FIY, it will dry-run for all the domains already added.
Once the certificate is renewed we also have to reload the Apache service. Append --renew-hook "systemctl reload apache2" to the /etc/cron.d/certbot file so that it looks like the following:
sudo vi /etc/cron.d/certbot
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload apache2"

 --renew-hook "systemctl reload apache2"
Test automatic renewal:
sudo certbot renew --dry-run
Delete cert:
sudo certbot delete --cert-name dumbschool.com
List cert:
sudo certbot certificates

Certbot troubleshoots:

grep -r 443 /etc/apache2
If there are no errors, it means that the renewal process was successful! Or visit: Check DNS, Urls + Redirects, Certificates and Content of your Website
Dismental a site:
sudo apache2ctl configtest
sudo certbot certificates
sudo certbot delete --cert-name saustralasia.online
sudo a2dissite saustralasia.online.conf
sudo service apache2 reload
sudo service apache2 status






Installing Composer

Prerequisite: Php

Installing Globally

Run as a sudo user
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php
sudo php -r "unlink('composer-setup.php');"

sudo mv ~/composer.phar /usr/local/bin/composer
or
sudo mv composer.phar /usr/local/bin/composer
or
mg@node1:~$ sudo mkdir -p ~/bin/composer
mg@node1:~$ sudo mv composer.phar ~/bin/composer/

sudo vi ~/.bashrc
alias composer='/home/mg/bin/composer/composer.phar'

For Local changes:
source ~/.bashrc
For Global Changes:
sudo vi /etc/bash.bashrc


To update Composer itself
/usr/local/bin/composer/composer.phar self-update
Uninstall composer?

Changing your PATH

Check the current path settings: 
mg@node1:~$ echo $PATH
Simply add /place/with/the/file to the $PATH variable with the following command:
export PATH=$PATH:/place/with/the/file


Check which shell is running
echo $0
Set your PATH permanently
A file called ~/.bash_profile, ~/.bashrc, or ~/.profile. ~/.bashrc is a good choice.
#added to set the PATH
PATH=$PATH:/home/mg/composer.phar
To test your path, run
composer --version
See these also (if not required):
The COMPOSER_HOME var allows you to change the Composer home directory. This is a hidden, global (per-user on the machine) directory that is shared between all projects.
echo $COMPOSER_HOME
echo $COMPOSER_BIN_DIR

Magento 2.4



Elasticsearch - Ubuntu 20

Java runtime is required for the Elasticsearch.

Install Java

java -version
sudo apt update && sudo apt upgrade -y
apt search openjdk
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-11-jdk-headless
sudo apt install openjdk-14-jre-headless
sudo apt install openjdk-14-jdk-headless
java -version
javac -version

Java Environment setup

You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
sudo vi /etc/bash.bashrc
# At the end
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
export PATH=$PATH:$JAVA_HOME/bin

Uninstall Elasticsearch


You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
sudo vi /etc/bash.bashrc

Installing Elasticsearch ref1

sudo apt-get install apt-transport-https
Download and install the Debian package manually
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-amd64.deb
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-amd64.deb.sha512
shasum -a 512 -c elasticsearch-7.7.1-amd64.deb.sha512 
sudo dpkg -i elasticsearch-7.7.1-amd64.deb
Elasticsearch is not started automatically after installation. How to start and stop Elasticsearch depends on whether your system uses SysV init or systemd (used by newer distributions). You can tell which is being used by running this command:
ps -p 1

Running Elasticsearch with systemd

To configure Elasticsearch to start automatically when the system boots up, run the following commands:
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
Elasticsearch can be started and stopped as follows:
sudo systemctl stop elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl status elasticsearch.service
sudo systemctl restart elasticsearch
These commands provide no feedback as to whether Elasticsearch was started successfully or not. Instead, this information will be written in the log files located in /var/log/elasticsearch/.

Elasticsearch loads its configuration from the /etc/elasticsearch/elasticsearch.yml file by default. The format of this config file is explained in Configuring Elasticsearch.
sudo vi /etc/elasticsearch/elasticsearch.yml
Test the Elasticsearch working: (no need to open port 9200)
curl -XGET http://localhost:9200/
To verify that Elasticsearch is working, enter the following command on the server on which it is running:
curl -XGET '<host>:9200/_cat/health?v&pretty'
curl -XGET 'localhost:9200/_cat/health?v&pretty'

Set up a proxy for Apache 2.4

This section discusses how to configure an Elasticsearch proxy using a virtual host.

Enable mod_proxy as follows:
a2enmod proxy_http
Use a text editor to open /etc/apache2/sites-available/000-default.conf
Add the following directive at the top of the file:
Listen 8080
Add the following at the bottom of the file:
<VirtualHost *:8080>
    ProxyPass "/" "http://localhost:9200/"
    ProxyPassReverse "/" "http://localhost:9200/"
</VirtualHost>
Test config and Restart Apache:
sudo apache2ctl configtest
sudo service apache2 reload
Verify the proxy works by entering the following command:
curl -i http://localhost:<proxy port>/_cluster/health
For example, if your proxy uses port 8080:
curl -i http://localhost:8080/_cluster/health
Messages similar to the following display to indicate success:
HTTP/1.1 200 OK
Date: Tue, 23 Feb 2016 20:38:03 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 389
Connection: keep-alive
{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":5,"active_shards":5,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":5,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":50.0}

Configure Magento 2 Elasticsearch

Reindexing catalog search and refreshing the full page cache.

After you change Magento’s Elasticsearch configuration, you must reindex the catalog search index and refresh the full page cache using the Admin or command line.
bin/magento cache:clean
bin/magento indexer:reindex catalogsearch_fulltext
bin/magento indexer:reindex
Wait until reindexing completes.
Unlike the cache, indexers are updated by a cron job. Make sure cron is enabled before you start using Elasticsearch.

Secure communication with Apache

Step 1: Create a password

which htpasswd
/usr/bin/htpasswd
If a path displays, it is installed; if the command returns no output, htpasswd is not installed.
If necessary, install htpasswd:
Ubuntu: apt-get -y install apache2-utils
Create a password file(http://httpd.apache.org/docs/2.4/howto/auth.html)
sudo mkdir -p /usr/local/apache/password
Example 2: Elasticsearch You must set up authentication for two users: one with access to Nginx and one with access to Elasticsearch. To create password files for these users, enter the following commands:
mkdir -p /usr/local/apache/password
htpasswd -c /usr/local/apache/password/.<password file name> <username>
sudo htpasswd -c /usr/local/apache/password/.htpasswd_elasticsearch haanz_online
sudo htpasswd    /usr/local/apache/password/.htpasswd_elasticsearch ejamuna_com
Add additional users: To add another user to your password file, enter the following command as a user with root privileges:
htpasswd /usr/local/apache/password/.htpasswd <username>
sudo htpasswd /usr/local/apache/password/.htpasswd_elasticsearch mg

Step 2: Secure communication with Apache

This section discusses how to specify who can access the Apache server.
Use a text editor to add the following contents to your secure virtual host.

Apache 2.4:
sudo vi /etc/apache2/sites-available/000-default.conf

Listen 8080

<VirtualHost *:8080>
    ProxyPass "/" "http://localhost:9200/"
    ProxyPassReverse "/" "http://localhost:9200/"
</VirtualHost>

<Proxy "*">
    Order deny,allow
    Allow from all

    AuthType Basic
    AuthName "Elastic Server"
    AuthBasicProvider file
    AuthUserFile /usr/local/apache/password/.htpasswd_elasticsearch
    Require valid-user

  # This allows OPTIONS-requests without authorization
  <LimitExcept OPTIONS>
        Require valid-user
  </LimitExcept>
</Proxy>
<VirtualHost *:80>...
Verify communication is secure
Test config and Restart Apache:
sudo apache2ctl configtest
sudo service apache2 reload
Use a curl command to verify cluster status
curl -i http://<hostname, ip, or localhost>:<proxy port>/_cluster/health
For example, if you enter the command on the Elasticsearch server and your proxy uses port 8080:
curl -i http://localhost:8080/_cluster/health
The following message displays to indicate authentication failed:
HTTP/1.1 401 Unauthorized
Date: Tue, 23 Feb 2016 20:35:29 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
WWW-Authenticate: Basic realm="Restricted"
Now try the following command:
curl -i -u <username>:<password> http://<hostname, ip, or localhost>:<proxy port>/_cluster/health
curl -i -u magento_elasticsearch:mypassword http://localhost:8080/_cluster/health
curl -i -u gcrecruitment_site:55Uu*^ http://localhost:8080/_cluster/health

HTTP/1.1 200 OK
Date: Thu, 18 Jun 2020 07:10:49 GMT
Server: Apache/2.4.29 (Ubuntu)
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
content-type: application/json; charset=UTF-8
content-length: 389
{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":1,"active_shards":1,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":1,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":
Perform the same tasks as discussed in Configure Magento to use Elasticsearch


Tuesday, June 16, 2020

Magento 2.4 Installation on Ubuntu 20


Topics: NTP clock, scan, ulimit -s 65536, Elasticsearch, memcached, RabbitMQ, Varnish,  Redis, Mail Transfer Agent (MTA) or an SMTP server/SES

1. If you expect to import large numbers of products into Magento, you can increase the value for max_allowed_packet that is larger than the default, 16MB.
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
sudo systemctl restart mysql.service
To optionally verify the value you set, enter the following command at a mysql> prompt:
sudo mysql
SHOW VARIABLES LIKE 'max_allowed_packet';
quit
1. Important: Apache required directives    - fulfilled by blog
2. Important: Apache rewrites and .htaccess - fulfilled by blog
3. Apache required modules
    Check if the Security Module is Active: sudo apache2ctl -M | grep security
    list Module command: sudo apache2ctl -M | sort

    b) Mod Expires: - fulfilled by blog

a) PHP 7.2 have bugs use other versions
To find and to see PHP, opcache configuration from the command line: 
php --ini | grep "Loaded Configuration File"
sudo find / -name 'opcache.ini'
sudo find / -name 'php.ini'
php -r "phpinfo();"
To avoid issues during installation and upgrade, we strongly recommend you apply the same PHP settings to both the PHP command-line configuration and to the PHP web server plug-in’s configuration. For more information, see the next section.
sudo find / -name 'php.ini'
sudo vi /etc/php/7.3/apache2/php.ini
sudo vi /etc/php/7.3/fpm/php.ini
sudo vi /etc/php/7.3/cli/php.ini
b) Find the Time Zone list:
timedatectl list-timezones  | grep ca
To Set the Time Zone for PHP:
date.timezone = Asia/Dhaka Australia/Sydney
Save your changes and exit the text editor. Open the other php.ini (if they are different) and make the same changes in it.
Set the system timezone (optional):
timedatectl
timedatectl list-timezones  | grep ca
sudo timedatectl set-timezone Asia/Dhaka America/New_York Australia/Sydney Set OPcache options
c) memory_limit=2G
d) realpath_cache_size = 10M / realpath_cache_ttl = 7200
Set OPcache options:
Locate opcache.save_comments and uncomment it if necessary. 
Make sure its value is set to 1.
sudo find / -name 'opcache.ini'
opcache.save_comments=1

sudo vi /etc/php/7.4/apache2/php.ini
sudo vi /etc/php/7.4/fpm/php.ini
sudo vi /etc/php/7.4/cli/php.ini
Restart your web server: 
sudo service apache2 restart
sudo service php7.4-fpm restart
sudo service php7.4-fpm reload
sudo systemctl restart php7.4-fpm
Optional few settings:
- Disable asp_tags: OK
max_execution_time = 1800
zlib.output_compression = On

Installing Elasticsearch


Set up a server that meets our system requirements
Create the Magento file system owner
Install Composer
Obtain authentication keys for the Magento code repository
To enable the webserver to write files and directories in the Magento file system but to also maintain ownership by the Magento file system owner, both users must be in the same group. 
  • Example: ejamuna.com web store

Two-user ownership and permissions

You typically log in as one user and run the web server as a different user.
Step 1: Create the Magento file system owner and give the user a strong password
adduser <username>
passwd <username>
Step 2: Find the web server user’s group
Typically, the username and the group name are both www-data.
ps aux | grep apache
groups <apache user>
Step 3: Put the Magento file system owner in the web server’s group
usermod -a -G www-data <username>
The -a -G options are important because they add apache or www-data as a secondary group to the user account, which preserves the user’s primary group. Adding a secondary group to a user account helps restrict file ownership and permissions to ensure members of a shared group only have access to certain files.
Make ownership to the webroot folder:
sudo chown -R ejamuna_com:www-data /var/www/ejamuna.com
sudo service apache2 restart

Get the metapackage with the access key
Run the composer command with the Magento user:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .
Set file permissions (Step 5: Set ownership and permissions for the shared group)
You must set read-write permissions for the web server group before you install the Magento software. This is necessary so that the command line can write files to the Magento file system.
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 :www-data . # Ubuntu
chmod u+x bin/magento
Or with the sudo privilege:
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :www-data . # Ubuntu
sudo chmod u+x bin/magento
Step 4: (Easy) Install the Magento archive on your server
sudo rm -rf /var/www/ejamuna.com
rm -rf /var/www/ejamuna.com/
mg@node2-mg:~$ mkdir /var/www/ejamuna.com
tar -xzvf file1 -C destination_folder

mg$ sudo chown -R ejamuna:www-data /var/www/ejamuna.com . 
("." means, including existing directory)
Set file permissions (Step 5: Set ownership and permissions for the shared group)
Log in to your Magento server as, or switch to, the Magento file system owner.

ejamuna@node1:/var/www/ejamuna.com$ cd /var/www/ejamuna.com && 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 :www-data . && chmod u+x bin/magento
OR, from sudo user:
mg@node1:/var/www/ejamuna.com$ cd /var/www/magento2 && sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && sudo chown -R :www-data . && sudo chmod u+x bin/magento

Install Magento

Use the command line options
You can run the installer multiple times with different options to complete.
By default, the installer does not overwrite the Magento database if you install the Magento software in the same database instance. You can use the optional cleanup-database parameter to change this behavior.
You must use the command line to install Magento.
Language: bin/magento info:language:list
en_US
en_AU
bn_BD
Currency: bin/magento info:currency:list
AUD
USD
BDT
Time zone: bin/magento info:timezone:list
Australia/Sydney
America/New_York
Asia/Singapore
Asia/Dhaka
You must use the command line to install Magento. (see one dri)
bin/magento setup:install \
--base-url=http://gcrecment.site \
--use-secure=1 --base-url-secure=https://gcritment.site \
--use-secure-admin=1 \
--db-host=localhost --db-name=gcrecruitment_site \
--db-user=gcrecruitment_site --db-password=%^g*7W \
--admin-firstname=admin --admin-lastname=admin \
--admin-email=admin@gcrecruitment.site \
--admin-user=ADMINYt9vDzC3o --admin-password=bEWzdY5nju \
--backend-frontname=admin_pnyfrtvi \
--language=en_US --currency=USD --timezone=America/Chicago \
--use-rewrites=1

Post installation: 

1. Backup your site after installation.

    See backup section...

2. Create Crontab:

Run from magento folder with the Magento user(user-ejamuna): (Do not run cron as root)
[su <username>] or [sudo su <username>]
bin/magento cron:install
OR, su <Magento file system owner> -s /bin/bash -c <command>
OR, sudo -u ejamuna bin/magento cron:install
List the cron job for the specific user:
sudo crontab -l -u ejamuna_com
Remove the Magento crontab
You should remove the Magento crontab only before uninstalling the Magento application.
bin/magento cron:remove
To see records in the table, log in to the Magento database on the command line and enter
SELECT * from cron_schedule;.
Corn Security: 
(https://devdocs.magento.com/guides/v2.3/config-guide/secy/secy-cron.html)

Continue with this doc

cc

Optionally set a umask

cc


c
3. Config Redis 


4. config Elasticsearch



Modify docroot to improve security

1.) The name and location of your virtual host file depend on which version of Apache you are running. This example shows the name and location of the virtual host file on Apache v2.4.
vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
         ServerAdmin webmaster@localhost
         DocumentRoot /var/www/html/magento2ce/pub
         ErrorLog ${APACHE_LOG_DIR}/error.log
         CustomLog ${APACHE_LOG_DIR}/access.log combined
         <Directory "/var/www/html">
                     AllowOverride all
         </Directory>
 </VirtualHost>
Restart Apache:
sudo systemctl restart apache2
sudo service apache2 reload
.
MTA SES
LAMC



Backup

bin/magento config:set system/backup/functionality_enabled 1

Set ulimit for the web server user

    Open /home/<username>/.bashrc in a text editor.
        Add the following line:
            ulimit -s 65536

Backing up

bin/magento setup:backup --code --media --db
bin/magento info:backups:list

Roll back

Uninstall Magento

Stop and delete cron:


Remove the instalation
sudo rm -rf /var/www/freshexport.online/


Remove the db:




Theme installation

M:
1. Useing site user ejamuna.com
1. Copy the app and the pub folder and paste it into your magento ROOT directory.
2. Since we installed a new module, it recommended to upgrade opration. It will upgrade all existing and new module.
 bin/magento setup:upgrade
bin/magento setup:upgrade --keep-generated
2. After uploaded a new module it is recommended to clear the cash by this command: (optional)
 bin/magento cache:clean
3. JS file needs to render properly. Deploy static content.
bin/magento setup:static-content:deploy -f
4. Flush store cache and log out from the backend and log in again to see changes.
After select the new theme.
php bin/magento cache:clean
Troubleshoots: 
a. If js are not rendered 
 php bin/magento setup:static-content:deploy -f

Extensions Installation

ref: github


bin/magento deploy:mode:set developer
bin/magento cache:flush
composer require mageplaza/module-smtp
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
You need to create smtp user on ses aws.
Enable the extension(if needed): 
php bin/magento --clear-static-content module:enable Mageplaza_Smtp
Clear cache: 
Install extension via composer (not working for MagePlaza Smtp):
composer require mageplaza/module-smtp
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
bin/magento module:status



2. Install Solwin - FreeGo Theme - Magento2 2.3.3
a. Download the FreeGo theme .ZIP file from solwininfotech.com using your Solwin Infotech website account.
b. Extract the .ZIP file which contains another .ZIP files into the theme-files folder.
c. If you are using Magento 2.3.x then you need to extract solwin-freego-theme-2.3.x.zip file.
d. Copy the app and the pub folder and paste it into your magento ROOT directory.
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
Activate the new theme:
Content > Design > Configuration
Content > Design > Configuration
https://www.solwininfotech.com/documents/magento2/freego/#theme_installation


3. Installing the Klaviyo Extension in Magento.
Create a new role:
Role name: Klaviyo
Permission: all
Create a new user(which use for API @ klavikyo:
user: klavikyo
pass: efeafc070680
Fill up this form url: https://www.klaviyo.com/integration/magento_two
Store URL, API and password.
Goto store->System->web setup wizard-> extention manager.
Magento 2 store public key: ***
private key: ***
Install the Klaviyo extention by selecting it.


4. Installing Revo
Installation: copy/paste

bin/magento module:status --disabled
bin/magento module:enable Trive_Core
bin/magento module:enable Trive_Revo
bin/magento module:status --enabled
bin/magento module:status --enabled --static....

To make sure that the enabled modules are properly registered, run 'setup:upgrade'.
Update the database
If you enabled one or more modules, run the following command to update the database:

bin/magento setup:upgrade
Then clean the cache:

bin/magento cache:clean




Uninstall the extension

Commons tasks for both process: (2020 update)
php bin/magento module:status
Disable the module by executing below commands::
php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
php bin/magento module:disable Mageplaza_Smtp --clear-static-content
php bin/magento setup:upgrade
Using composer:
composer remove weltpixel/m2-weltpixel-owl-carousel-slider
bin/magento setup:upgrade
Manually:
Remove extension files
cd app/code/<ExtensionProvider>/
rm -rf <ExtensionName>
(optionally!) php bin/magento setup:upgrade

- Note: you can find the exact match for ExtensionProvider and ExtensionName in composer.json file associated with the extension.

- Note2: you can find the exact match for VendorName and VendorExtension in composer.json file associated with the extension.or under yourmagentoinstallation/com/vendor/<VendorName>/<VendorExtension>

- Note3: You may be asked for composer username and password when uninstalling, you will be able to find them under var/composer_home/auth.json



Upgrade db scheme
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
bin/magento module:status
Disable module
php bin/magento disable:module Magento_Amqp

Clean cache:
bin/magento cache:clean
XML file edit (it load slowly as the cache is generated):
 bin/magento cache:flush



Sending email from command line: 
php -r "mail('me@myEmail.com', 'Is PHP Mail Setup', 'Yes - I got this email');"
Port check: 
telnet smtp.gmail.com 465


Troubleshoots

1. 
url: https://devdocs.magento.com/guides/v2.3/install-gde/trouble/tshoot_sample-data.html?itm_source=devdocs&itm_medium=search_page&itm_campaign=federated_search&itm_term=class%20does%20not%20exist
rm -rf generated/code/* generated/metadata/*
php bin/magento setup:upgrade
2.
https://magento.stackexchange.com/questions/219268/setupstatic-contentdeploy-issue-with-locale
Make sure you've selected English (United States) in your locale settings: Stores > Configuration > General > Locale Options

setup:static-content:deploy by default deploys en_US

If you'd like to use en_AU, change your Locale Settings in the admin to English (Australia) and run setup:static-content:deploy en_AU

Backup and roll back the file system, media, and database

The Magento backup feature is disabled by default. To enable, enter the following CLI command:
bin/magento config:set system/backup/functionality_enabled 1

Set ulimit for the web server user

Why to set ulimit?
Rolling back to a previous backup can silently fail, resulting in incomplete data being written to the file system or database. (This includes all types of rollbacks, including using System Upgrade, Component Manager, or the magento setup:rollback command.)
In some cases, a very long query string causes the user’s allocated memory space to run out of memory because of too many recursive calls. We recommend setting the ulimit for the Magento file system user to a value of 65536 or more.
How to set ulimit
We recommend setting the ulimit for the Magento file system user to a value of 65536 or more.
You can do this either on the command line or you can make it a permanent setting for the user by editing their shell script.
Before you continue, if you haven’t done so already, switch to the Magento file system owner.
Command:
$ ulimit -s 65536
Backing up
bin/magento setup:backup [--code] [--media] [--db]
bin/magento setup:backup --code --media --db
To find the name of your backups, enter:
bin/magento info:backups:list
Restore command example: 
ejamuna@node1:/var/www/ejamuna.com$ bin/magento setup:rollback -m 1576774816_filesystem_media.tgz -c 1576774816_filesystem_code.tgz -d 1576774816_db.sql


Mastering Module development

Upgrade the db scheme: 
php bin/magento setup:upgrade
XML file edit (it load slowly as the cache is generated):
php bin/magento cache:flush

sdsd
sdsd

Friday, June 12, 2020

How to embed code snippets in Blogger/BlogSpot

I would like to share my way with you because it's simple and has mobility. Go to your blogger account click theme >> customize >> Advance >> Add CSS then paste below CSS code
code {
    font-family: Courier, monospace;
    color: #000;
    background-color: #f8f9fa;
    border: 1px solid #eaecf0;
    border-radius: 2px;
    padding: 1px 4px;
}
pre, .mw-code {
    padding: 5px;
    font-family: Courier, monospace;
    font-size: inherit;
    line-height: 1rem;
    color: #000;
    background-color: #f8f9fa;
    border: 1px solid #eaecf0;
    padding: 1em;
    white-space: pre-wrap;
    overflow-x: hidden;
    word-wrap: break-word;
}
To make things work, for example:
To check the MX record of a domain <code> nslookup </code> (in windows):

<pre>temp = foo</pre>

Wednesday, December 18, 2019

Adding domain MX record and DNS in AWS Route53

First, set the NS record. Then, delete all other records from the vendor controll panel including the default MX (Domain provider CrazyDomains) records.

Secondly, add a MX record in AWS Route 53 with your Service providers default server neme, that is (MX, 10 mateswork.com), it will help you to receive emails in your Hosting service provider mailbox.
After these settings, make sure, if you can receive mails in your vendor's inbox.

To check the MX record of a domain (in windows):
nslookup -type=MX domain.com nsservername.com