Magento2

Nesse artigo será exibido detalhadamente os processos feito via terminal para a instalação do Magento2 e diversas dicas

Ola

Execute os comandos efetuando as devidas alterações personalizando para seu projeto

Criação de diretório e atualização do Composer

cd ~/dados/public_html
pwd
ls
mkdir magento-2.3.0-dev04
cd magento-2.3.0-dev04
composer --version && sudo composer self-update && composer clear-cache

Install Magento

# Requirements
# https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html

	echo -e "\e[1;33m --( disk space usage )-- \e[0m"
	df -h
	echo -e "\e[1;33m --( Git Version )-- \e[0m"
	git --version
	echo -e "\e[1;33m --( Composer Version )-- \e[0m"
	composer -V
	echo -e "\e[1;33m --( PHP Version (7.1.3+, 7.2.x) )-- \e[0m"
	php -v
	echo -e "\e[1;33m --( MySQL Version (5.6, 5.7) )-- \e[0m"
	mysql -V
	echo -e "\e[1;33m --( Info CPU (min: 8 cores) )-- \e[0m"
	lscpu

# Get the metapackage
# https://devdocs.magento.com/guides/v2.3/install-gde/composer.html

	composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2 -vvv
	mv magento2/{.[!.],}* .
	ls

# Set file permissions

	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 {} +
		# Ubuntu
		sudo chown -R :www-data . 
		sudo chmod u+x bin/magento

# MySQL

	# mysqladmin -h 'localhost' -u root -p DROP "magento230dev04";

	mysqladmin -h 'localhost' -u root -p CREATE "magento230dev03"

# Install Magento
php bin/magento setup:install \
--base-url=http://localhost/htdocs/magento-2.3.0-dev03/ \
--db-host=127.0.0.1 \
--db-name=magento230dev03 \
--db-user=root \
--db-password=root \
--backend-frontname=admin \
--admin-firstname=Marcio \
--admin-lastname=Amorim \
[email protected] \
--admin-user=admin \
--admin-password=123456a \
--language=pt_BR \
--currency=BRL \
--timezone=America/Sao_Paulo \
--use-rewrites=1
	php index.php

Pós Install Magento

echo -e "\e[1;33m --( pwd )-- \e[0m" ;\
pwd ;\
echo -e "\e[1;33m --( bin/magento cache:disable )-- \e[0m" ;\
php bin/magento cache:disable ;\
echo -e "\e[1;33m --( bin/magento cache:clean )-- \e[0m" ;\
php bin/magento cache:clean ;\
echo -e "\e[1;33m --( bin/magento cache:flush )-- \e[0m" ;\
php bin/magento cache:flush ;\
echo -e "\e[1;33m --( bin/magento cache:status )-- \e[0m" ;\
php bin/magento cache:status ;\
echo -e "\e[1;33m --( bin/magento deploy:mode:show )-- \e[0m" ;\
php bin/magento deploy:mode:show ;\
echo -e "\e[1;33m --( bin/magento deploy:mode:set developer )-- \e[0m" ;\
php bin/magento deploy:mode:set developer ;\
echo -e "\e[1;33m --( bin/magento indexer:reindex )-- \e[0m" ;\
php bin/magento indexer:reindex ;\
echo -e "\e[1;33m --( bin/magento indexer:status )-- \e[0m" ;\
php bin/magento indexer:status ;\
echo -e "\e[1;33m --( bin/magento maintenance:disable )-- \e[0m" ;\
#php bin/magento maintenance:disable ;\
echo -e "\e[1;33m --( bin/magento maintenance:status )-- \e[0m" ;\
php bin/magento maintenance:status ;\
echo -e "\e[1;33m --( bin/magento module:status )-- \e[0m" ;\
php bin/magento module:status ;\
echo -e "\e[1;33m --( bin/magento setup:db:status )-- \e[0m" ;\
php bin/magento setup:db:status ;\
echo -e "\e[1;33m --( bin/magento setup:upgrade )-- \e[0m" ;\
php bin/magento setup:upgrade ;\
echo -e "\e[1;33m --( bin/magento cron:run )-- \e[0m" ;\
# php bin/magento cron:run ;\
echo -e "\e[1;33m --( update/cron.php )-- \e[0m" ;\
# php update/cron.php ;\
echo -e "\e[1;33m --( bin/magento setup:cron:run )-- \e[0m" ;\
# php bin/magento setup:cron:run ;\
echo -e "\e[1;33m --( bin/magento )-- \e[0m" ;\
php bin/magento ;\
echo -e "\e[1;33m --( index.php )-- \e[0m" ;\
php index.php

Performance

# Developer

# https://www.youtube.com/results?search_query=magento+2+speed+optimization

# https://www.goivvy.com/blog/speed-up-magento

	mysql -h 'mysql' -u 'root' -p -e "
	SHOW VARIABLES LIKE '%query_cache%';
	"
# https://devdocs.magento.com/guides/v2.3/extension-dev-guide/build/optimal-dev-environment.html

# https://magento.stackexchange.com/questions/152221/why-magento-2-is-extremely-slow

# https://magenticians.com/why-magento-2-is-slow/

	php bin/magento config:set catalog/frontend/flat_catalog_product 1
	# php bin/magento config:set dev/js/enable_js_bundling 1 # Production
	php bin/magento config:set dev/js/merge_files 1
	php bin/magento config:set dev/js/minify_files 1
	php bin/magento config:set dev/css/merge_css_files 1
	php bin/magento config:set dev/css/minify_files 1
	php bin/magento config:set dev/static/sign 1

	php bin/magento setup:static-content:deploy -f --jobs 4

# https://magento.stackexchange.com/questions/198084/magento-2-2-often-extremely-slow-100-processor-usage-after-setupupgrade

# To force M2 to deploy the static data in developer mode in order to skip the long wait.

	php bin/magento setup:static-content:deploy -f

# Remount

	rm -rf pub/static/* 
	rm -rf var/*
	php bin/magento cache:flush		
	php bin/magento setup:static-content:deploy -f # Recompile the pub static folder

# Production

# https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/js-bundling.html


# Deploy

	php bin/magento setup:upgrade
	php bin/magento setup:di:compile
	php bin/magento setup:static-content:deploy
	bin/magento cache:flush
	bin/magento cache:enable

Config Memcached

# https://devdocs.magento.com/guides/v2.3/config-guide/memcache/memcache_magento.html

# https://www.cloudways.com/blog/magento-2-memcached/

# How to check if memcached is running

	ps aux | grep memcached

# How to check if memcached module is running

	php -m | grep memcache

# Edit

	cd /shared/httpd/localhost/htdocs/magento-2.3.0-dev03

	nano app/etc/env.php

# https://devdocs.magento.com/guides/v2.3/config-guide/redis/redis-pg-cache.html

	php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0

	php bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1

# https://devdocs.magento.com/guides/v2.3/config-guide/redis/config-redis.html

# https://devdocs.magento.com/guides/v2.3/config-guide/redis/redis-session.html#result

	php bin/magento setup:config:set --session-save=redis --session-save-redis-host=localhost --session-save-redis-log-level=3 --session-save-redis-db=2

# Clean Cache

	sudo rm -rf pub/static/*
	sudo rm -rf var/*
	php bin/magento cache:flush

SQL Útil

mysql -h 'mysql' -u 'root' -p 'magento-007' < 'database_2018.07.20_15.17.53.sql' ;

mysql -h 'mysql' -u 'root' -p 'magento230dev03' -e "
SELECT * FROM core_config_data WHERE path = 'web/seo/use_rewrites';
UPDATE core_config_data SET value = '1' WHERE path = 'web/seo/use_rewrites';
SELECT * FROM core_config_data WHERE path = 'web/seo/use_rewrites';
"

mysql -h 'mysql' -u 'root' -p 'magento230dev02' -e "
SELECT * FROM core_config_data WHERE path like '%base_url%';
UPDATE core_config_data SET value = 'https://magentodev03.devilbox/' WHERE path like '%secure/base_url%';
SELECT * FROM core_config_data WHERE path like '%secure/base_url%';
"

Install Sample Data

# https://devdocs.magento.com/guides/v2.3/install-gde/install/sample-data-after-magento.html

	php -d memory_limit=-1 bin/magento sampledata:deploy
	php bin/magento setup:upgrade

Magento PWA Studio

# https://magento-research.github.io/pwa-studio/

# https://magento-research.github.io/pwa-studio/venia-pwa-concept/setup/

	cd /shared/httpd/localhost/htdocs/magento
	git clone https://github.com/magento-research/pwa-studio.git
	cd pwa-studio/
	npm install
	cp packages/venia-concept/.env.dist packages/venia-concept/.env
	nano .env
	npm run watch:all

	cd pwa-studio/packages/venia-concept
	npm run validate-queries

# NOTE

	NOTE: Manual static content deployment is not required in "default" and "developer" modes.               
	In "default" and "developer" modes static contents are being deployed automatically on demand.           
	If you still want to deploy in these modes, use -f option: 'bin/magento setup:static-content:deploy -f'

Local Dev

[email protected]:
	ssh [email protected]

[email protected]:
	cd ~/dados/git/clone/devilbox-2019-02-05

	docker-compose down --remove-orphans && docker-compose up

	./shell.sh
		cd /shared/httpd/localhost/htdocs/magento-2.3.0-dev03

[email protected]:
	cd ~/dados/mount/www/localhost/htdocs/magento-2.3.0-dev03/

# https://magentodev03.devilbox/

Install/Uninstall Extensions

# https://github.com/topics/magento2?o=desc&s=updated
# https://packagist.org/?query=magento2

# https://github.com/netz98/n98-magerun2

	wget https://files.magerun.net/n98-magerun2.phar
	chmod +x ./n98-magerun2.phar
	./n98-magerun2.phar --version
	./n98-magerun2.phar
	./n98-magerun2.phar db:status
	./n98-magerun2.phar db:maintain:check-tables
	./n98-magerun2.phar sys:check

# https://github.com/gwillem/magento-malware-scanner

	wget https://mwscan.s3.amazonaws.com/mwscan.txt
	grep -Erlf mwscan.txt .

# https://github.com/Smile-SA/magento2-module-debug-toolbar

	composer require smile/module-debug-toolbar --dev -vvv

	# php bin/magento config:set smile_debugtoolbar/configuration/enabled 1

# https://github.com/ho-nl/magento2-Ho_Templatehints

	composer require honl/magento2-templatehints:dev-master --dev -vvv

# https://github.com/AydinHassan/m2-opcache-monitor

	composer require trash-panda/m2-opcache-monitor

# https://github.com/magehost/performance-dashboard

	composer require magehost/performance-dashboard

# https://github.com/magestat/magento2-split-order

	composer require magestat/module-split-order -vvv

# https://github.com/mcspronko/banner-widget

	composer config repositories.pronko git https://github.com/mcspronko/banner-widget
	composer require pronko/banner-widget:dev-master -vvv

# https://github.com/mailchimp/mc-magento2

	composer require mailchimp/mc-magento2 -vvv

# https://github.com/kiwicommerce/magento2-cron-scheduler

	composer require kiwicommerce/module-cron-scheduler -vvv

# https://github.com/blackbird-agency/magento-2-disabled-reports

	composer require blackbird/module-disable-reports -vvv

# https://packagist.org/packages/auroraextensions/magecroncloudfunctions

	composer require auroraextensions/magecroncloudfunctions

# https://packagist.org/packages/bangerkuwranger/magento2-google-cloud-storage

	composer require bangerkuwranger/magento2-google-cloud-storage

# https://packagist.org/packages/magefan/module-cli

	composer require magefan/module-cli --dev

# https://packagist.org/packages/magefan/module-conflict-detector

	composer require magefan/module-conflict-detector --dev

# https://packagist.org/packages/magefan/module-rocketjavascript

	composer require magefan/module-rocketjavascript

# https://github.com/cichondev/module-customers-extra-fields ??? Semelhante
# https://github.com/eduardoddias/Magento-SystemCode_BrazilCustomerAttributes ??? Semelhante
# https://packagist.org/packages/techspot/

	composer require techspot/addresslabel -vvv
	composer require techspot/brcustomer -vvv
	composer require techspot/brestimateshipping -vvv
	composer require techspot/documentupload -vvv
	composer require techspot/sendquote -vvv

# https://packagist.org/packages/magento2translations/language_pt_br
# https://github.com/rafaelstz/traducao_magento2_pt_br#via-composer

	composer require rafaelstz/traducao_magento2_pt_br:dev-master -vvv
	php bin/magento setup:static-content:deploy pt_BR -f
	php bin/magento cache:clean

# ###
# Module Creator

	https://mage2gen.com/load/c6103687-4faa-4766-807e-1f89587453d8
	https://mage2gen.com/download/c6103687-4faa-4766-807e-1f89587453d8.tar

# https://github.com/UltimateModuleCreator/umc

	mkdir umc
	cd umc
	git clone https://github.com/UltimateModuleCreator/umc.git .
	composer install
	cp .env.dist .env

# ###
# Pós Install
# Optimization in localhost - https://www.youtube.com/watch?v=jPYm0Bz5FqA

	php bin/magento setup:upgrade
	php bin/magento setup:static-content:deploy -f
	# php bin/magento cache:flush

# Uninstall

	cat composer.json
	composer remove mageplaza/module-webhook -vvv
	composer remove rafaelstz/traducao_magento2_pt_br -vvv
	composer validate -vvv
	composer update
	# composer dump-autoload
	php bin/magento setup:upgrade
	php bin/magento cache:flush

# Clean Cache

	rm -rf pub/static/* 
	rm -rf var/*
	php bin/magento cache:flush

# Module

	php bin/magento module:status

(*) Re-Install Magento

# diff -qr /home/marcio/dados/downloads/Magento-CE-2.3.0-2018-11-27-10-18-29/ /home/marcio/dados/mount/www/localhost/htdocs/magento2002/magento

	cd /shared/httpd/localhost/htdocs/magento-2.3.0-dev03

	rm app/etc/config.php
	rm app/etc/env.php
	rm -fr generated/code/*

	rm -fr pub/media/theme/*

# Clean Cache

	rm -rf pub/static/*
	rm -rf var/*
	php bin/magento cache:flush

# Na necessidade de acessar o MySQL Client e ver os processos

	mysql -h 'mysql' -u 'root' -p

	show processlist;

Links

https://webkul.com/blog/multi-website-setup-in-magento-2/

Dicas

Registros Cron

A tabela cron_schedule armazena as tarefas a executar e executadas

TRUNCATE `cron_schedule`;
SELECT * FROM `cron_schedule`;
SELECT * FROM `cron_schedule` WHERE `job_code` like '%mozg%' AND `status` != 'success';

Reexecutar os scripts de setup do módulo

-- add table prefix if you have one
DROP TABLE IF EXISTS mozg_boxpacker_packing;
SELECT * FROM `setup_module` WHERE `module` like '%mozg%';
DELETE FROM setup_module WHERE module like '%mozg%';
DELETE FROM core_config_data WHERE path like '%mozg%';