Tuesday, June 16, 2020

Magento 2.4 Installation on Ubuntu 20


Topics: NTP clock, scan, ulimit -s 65536, Elasticsearch, memcachedRabbitMQVarnish,  RedisMail 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

No comments:

Post a Comment