Magento 2 CLI and Linux commands used on daily basis

As a Magento 2 developer you will be using commands daily to manage your store and development environment.

I decided to list commands I use every day just so I have a record of it somewhere 🙂

These are just random and might need tweaking on your own development environment.

Docker Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
LAUNCH IMAGES
docker-compose up -d

STOP IMAGES
docker-compose stop

DESTROY IMAGES
docker-compose down

DESTROY IMAGES (destroys image volumes)
docker-compose down -v

DELETE EVERYTHING INCLUDING IMAGES
docker-compose down -v --rmi all

LIST CONTAINERS
docker-compose ps

LOGIN INTO CONTAINER
docker-compose exec CONTAINER bash

READ DOCKER LOGS
docker-compose logs -f

RESTART CONTAINER
docker-compose restart

 

MAGENTO BIN COMMANDS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
UPGRADE MAGENTO (UPDATE PLUGINS / INSTALL NEW DB DATA)
php bin/magento setup:upgrade

CODE COMPILATION
php bin/magento setup:di:compile

DEPLOY ALL THEMES (ADMIN / FRONTEND)
php bin/magento setup:static-content:deploy -f

DEPLOY FRONT-END THEME LUMA
php bin/magento setup:static-content:deploy en_CA --theme="Magento/luma" -f

DEPLOY ADMIN AREA THEME
php bin/magento setup:static-content:deploy --area adminhtml

FLUSH CACHE
php bin/magento cache:flush

UNINSTALL PLUGIN (I DON'T RECOMMEND IT)
php bin/magento setup:uninstall

GET STATUS OF INDEXES
bin/magento indexer:status [indexer]

RESET/INVALIDATE INDEX
bin/magento indexer:reset [indexer]

REINDEX ALL INDEXES
bin/magento indexer:reindex

LIST INDEXES
bin/magento indexer:info

LIST OF INDEXES
design_config_grid                       Design Config Grid
customer_grid                            Customer Grid
catalog_category_product                 Category Products
catalog_product_category                 Product Categories
catalogrule_rule                         Catalog Rule Product
catalog_product_attribute                Product EAV
inventory                                Inventory
catalogrule_product                      Catalog Product Rule
cataloginventory_stock                   Stock
catalog_product_price                    Product Price
catalogsearch_fulltext                   Catalog Search

SET UP MAGENTO CRON
bin/magento cron:install

SHOW MAGENTO MODE (DEFAULT/DEVELOPER/PRODUCTION)
bin/magento deploy:mode:show

SET MAGENTO MODE (PRODUCTION)
bin/magento deploy:mode:set production

 

LINUX CLI COMMANDS (UBUNTU)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
RESET MAGENTO PERMISSIONS
sudo find var/cache var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
sudo find var/cache var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
sudo chown -R user:www-data .
sudo chmod u+x bin/magento

START/STOP/RESTART NGINX
sudo service nginx start
sudo service nginx stop
sudo service nginx restart

IS NGINX SYNTAX CORRECT?
sudo nginx -t

RELOAD NGINX WITHOUT DROPPING CUSTOMERS
sudo service nginx reload

LIST CRONTAB FILE
crontab -l

EDIT USER'S CRON TAB
crontab -e

CRONTAB SCHEDULE EXPRESSIONS
https://crontab.guru/

SET NANO AS YOUR EDITOR FOR CRONTAB
alias crontab='EDITOR=nano /usr/bin/crontab'

USE NANO AS YOUR EDITOR FOR CRONTAB TO EDIT WWW-DATA USER'S CRONTAB
sudo EDITOR=nano crontab -u www-data -e

CHECK ELASTICSEARCH VERSION
curl -XGET 'http://localhost:9200'

 

COMPOSER COMMANDS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
UPDATE PACKAGES
composer update

AND THEN YOU FOLLOW IT UP WITH
sudo php -dmemory_limit=2G bin/magento setup:upgrade
sudo php -dmemory_limit=2G bin/magento setup:di:compile
sudo php -dmemory_limit=2G bin/magento setup:static-content:deploy -f
sudo php -dmemory_limit=2G bin/magento cache:flush

REQUIRE NEW PACKAGE
composer require "vendor/package:2.*"

CLEAR COMPOSER CACHE
composer clearcache

INSTALL COMPOSER
sudo apt-get update
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

 

MYSQL

1
2
3
4
5
6
DUMP DATABASE
mysqldump -u root -proot magentodb > magentodb.sql

UPDATE MAGENTO URL
update core_config_data set value = 'http://example.com/' where path = 'web/unsecure/base_url';
update core_config_data set value = 'http://example.com/' where path = 'web/secure/base_url';

 

GIT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
INIT REPOSITORY
git init

PUSH TO MASTER BRANCH ON REMOTE
git push origin master

PULL FROM MASTER BRANCH ON REMOTE
git pull origin master

SHOW ALL BRANCHES
git branch -a

DELETE LOCAL BRANCH
git branch --delete <branch>

DELETE REMOTE BRANCH
git push origin --delete <branch>

Leave a Reply