magento 2 | CLI commands list


 below is the most commonly used CLI commands by magento2...

 

| Instalation Command
php -f bin/magento setup:install --base-url=http://domain.com/ --backend-frontname=admin --db-host=localhost --db-name=dev_magento --db-user=root --db-password=root --admin-firstname=Magento --admin-lastname=Admin --admin-email=saleh.awal@gmail.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=Africa/Cairo --use-rewrites=1 --elasticsearch-host=elasticsearch


| Reset Admin Pass
bin/magento admin:user:create --admin-user="saleh" --admin-password="jomlahSA001" --admin-email="saleh.awal@gmail.com" --admin-firstname="Saleh" --admin-lastname="El-Jabarty"e
# Admin User Unlock
 bin/magento admin:user:unlock admin


| Cache Files Remove
rm -fr generated/metadata/*
rm -fr generated/code/*
rm -fr var/cache/*
rm -fr var/page_cache/*
rm -fr var/view_preprocessed/*
rm -fr pub/static/*
rm -fr var/tmp/*


| Backup
magento setup:backup --code --db --media


| Manage Modules
bin/magento module:status
bin/magento module:enable module_name
bin/magento module:disable module_name1 module_name2 module_name3
bin/magento module:uninstall module_name3 --backup-code --backup-media --backup-db --remove-data --clear-static-content


- SQL | Remove Module
SELECT * FROM setup_module WHERE module LIKE 'Itcforu%';
DELETE FROM setup_module WHERE module LIKE 'Itcforu%';


| Maintanace
bin/magento maintenance:status
bin/magento maintenance:enable
bin/magento maintenance:disable


| Operation Mode
bin/magento deploy:mode:show
bin/magento deploy:mode:set developer
bin/magento deploy:mode:set production


| Reset File Permission

- localhost
sudo find . -type f -exec chown muser:www-data {} +
sudo find . -type d -exec chown muser:www-data {} +
sudo find generated generated var pub -type f -exec chmod 777 {} +
sudo find generated generated var pub -type d -exec chmod 777 {} +
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 {} +
chmod u+x bin/magento
sudo chown -R :www-data .

- Google Server
sudo find . -type f -exec chown muser:www-data {} +
sudo find . -type d -exec chown muser:www-data {} +
sudo find generated generated var pub var -type f -exec chmod 777 {} +
sudo find generated generated var pub var -type d -exec chmod 777 {} +
sudo su muser
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 {} +
chmod u+x bin/magento
sudo chown -R :www-data .
 

| Deploy
bin/magento maintenance:enable
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento indexer:reset
bin/magento indexer:reindex
bin/magento setup:static-content:deploy -f en_US ar_SA
#bin/magento setup:static-content:deploy --theme Magento/backend --theme Vnecoms/vendor --theme Sm/metro -f en_US ar_SA
bin/magento cache:enable
bin/magento cache:clean
bin/magento cache:flush
bin/magento maintenance:disable
echo 'DONE';


| Clean
bin/magento cache:clean
bin/magento cache:flush

- SQL | Store not Found
SELECT * FROM core_config_data WHERE scope = 'stores';
DELETE FROM core_config_data WHERE scope_id != 1 AND scope = 'stores';


| Change Base URL
bin/magento setup:store-config:set --base-url="http://dev.domain.com/"
bin/magento setup:store-config:set --base-url-secure="https://dev.domain.com/"
bin/magento cache:flush
-- Update Domain Info
UPDATE core_config_data SET value = 'dev.domain.com' WHERE path = 'web/cookie/cookie_domain';
UPDATE core_config_data SET value = 'dev.domain.com' WHERE path = 'design/header/logo_alt';
UPDATE core_config_data SET value = 'http://dev.domain.com/' WHERE path = 'web/unsecure/base_link_url';
UPDATE core_config_data SET value = 'https://dev.domain.com/' WHERE path = 'web/secure/base_link_url';
UPDATE core_config_data SET value = 'http://seller.dev.domain.com/' WHERE path = 'vendors/url/custom';
-- Clear CDN
UPDATE core_config_data SET value = '' WHERE path = 'web/unsecure/base_static_url';
UPDATE core_config_data SET value = '' WHERE path = 'web/unsecure/base_media_url';
UPDATE core_config_data SET value = '' WHERE path = 'web/secure/base_static_url';
UPDATE core_config_data SET value = '' WHERE path = 'web/secure/base_media_url';
-- Update CDN
UPDATE core_config_data SET value = 'http://old.domain.com/ar/customer/address/new/' WHERE path = 'custom_login_redirect/register/custom_redirect_url';
UPDATE core_config_data SET value = 'http://251599-955718-raikfcquaxqncofqfm.stackpathdns.com/pub/static/' WHERE path = 'web/unsecure/base_static_url';
UPDATE core_config_data SET value = 'http://251599-955718-raikfcquaxqncofqfm.stackpathdns.com/pub/media/' WHERE path = 'web/unsecure/base_media_url';
UPDATE core_config_data SET value = 'https://251599-955718-raikfcquaxqncofqfm.stackpathdns.com/pub/static/' WHERE path = 'web/secure/base_static_url';
UPDATE core_config_data SET value = 'https://251599-955718-raikfcquaxqncofqfm.stackpathdns.com/pub/media/' WHERE path = 'web/secure/base_media_url';


| Find domain entries
SELECT * FROM core_config_data WHERE path like '%url%';
SELECT * FROM core_config_data WHERE value LIKE '%.com';


| Update Static and Media Base URL
UPDATE core_config_data SET value = '' where path like '%base_static_url';
UPDATE core_config_data SET value = '' where path like '%base_media_url';


| Create Admin User
bin/magento admin:user:create --admin-user="admin" --admin-password="adminPa$$" --admin-email="admin@domain.com" --admin-firstname="admin" --admin-lastname="admin"

- SQL | Update Admin Password
UPDATE admin_user SET `password` = CONCAT(SHA2('Jbassword$$0o0', 256), ':xxxxxxxx:1') WHERE `username` = 'saleh';


| Magento API | Test

- test
curl -X POST "https://magento.host/index.php/rest/V1/integration/customer/token" -H "Content-Type:application/json" -d "{"username":"mobile", "password":"jomlahAppPa$$w00rd"}"

- Modules API Documentation
http://beta.domain.com/swagger


| Admin Path
bin/magento setup:config:set --backend-frontname="admin"


| Version Upgrade
bin/magento cache:disable
bin/magento setup:backup --db
composer require magento/product-community-edition 2.2.3 --no-update
composer update
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:enable


| Translation File
bin/magento i18n:collect-phrases -o "app/code/jomlah/Magento_Catalog/i18n/ar_SA.csv" app/code/jomlah/Magento_Catalog
app/design/frontend/Codazon/fastest/bigmarket/i18n/ar_SA.csv
/home/ztgcdath/public_html/app/i18n/magento/ar_SA
bin/magento i18n:pack app/i18n/magento/ar_SA/ar_SA.csv -d ar_SA


| Images
- resize
bin/magento catalog:images:resize
bin/magento cache:clean

- fix images thumnail size
bin/magento s:up;
bin/magento catalog:images:resize;
bin/magento s:s:d -f;
bin/magento c:f;
bin/magento s:up
bin/magento c:f


| PHP Session Save Path
php_admin_value[session.save_path] = /home/master/applications/rzmwqvsukr/public_html/var/sessions


| Magento Clearn Up
bin/magento catalog:product:attributes:cleanup
bin/magento dev:profiler:disable
bin/magento dev:query-log:disable
bin/magento dev:template-hints:disable


| Change Order Number Sequence
- Remove Old Sequences
DELETE FROM sales_sequence_meta WHERE store_id not in (0,1,15,16)
- Increase Incremental Order Number
INSERT INTO sequence_order_15 (sequence_value) VALUES (450543)

Comments