Magento 2 | CLI Commands & Common problems

CLI Commands

Install Magento 2:

Install Sample data :

php bin/magento sampledata:deploy

After this command, you need to connect to your magento account ( https://marketplace.magento.com/ ), navigate to “Access key”, crete new Access Key, and you have a Public Key ( username ) and Private key ( Password ), you need to insert in Terminal when CLI ask for “repository User and password ”

Check the magento mode

php bin/magento deploy:mode:show

Change magento mode
{mode} is required; it can be either developer or production, –skip-compilation is an optional parameter you can use to skip code compilation when you change to production mode.

php bin/magento deploy:mode:set
or
php bin/magento deploy:mode:set {mode} [-s|--skip-compilation]

Enable the maintenance mode

php bin/magento maintenance:enable --ip=192.168.1.10 --ip=192.168.1.11

So you will disable the maintenance mode for two IP address 192.168.1.10 and 192.168.1.11. There is probably usually the Ip address of developer who wants to debug your website.

Disable the maintenance mode:

php bin/magento maintenance:disable --ip=192.168.1.10 --ip=192.168.1.11

Flush Cache Storage:

php bin/magento cache:clean

short version:

php bin/magento c:c

Flush Magento cache:

php bin/magento cache:flush

short version:

php bin/magento c:f

Update the database schema, you need it if enable new module.
By default, magento setup:upgrade clears compiled code and the cache. Typically, you use magento setup:upgrade to update components and each component can require different compiled classes.

php bin/magento setup:upgrade

Static contents deploy:

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

Reindex content

php bin/magento indexer:reindex

Check the list of all modules including their enable / disable status

php bin/magento module:status

List enabled and disabled modules

Status

php bin/magento module:status

Disable a module ( es : php bin/magento module:disable vendorname_modulename –clear-static-content )

php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content

Enable a module ( es : php bin/magento module:eneble vendorname_modulename / in the terminal, you’ll see a message like ” Updating modules: ” and below this a list with all modules that be updated )

php bin/magento module:enable vendorname_modulename
php bin/magento setup:upgrade

After Enable or Disable modules remember to update the db and clear / flush cache

php bin/magento setup:upgrade
php bin/magento c:c
php bin/magento c:f

Problems :

” Fatal error: Allowed memory size of …. bytes exhausted (tried to allocate ….. bytes) in “

A Quick solutions for memory limit in magento 2 command is directly adding memory limit inside commannd :

For Compilation command,

php -dmemory_limit=5G bin/magento setup:di:compile
For Deployment

php -dmemory_limit=5G bin/magento setup:static-content:deploy

You can change as per 5G to max if issue not resolve.

Remote | Positioning on root of Magento 2.

composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.3.0 .

Docker | Positioning on root of Magento 2.

$ docker exec -it magento_2_webserver_1 /bin/bash

Docker | Switch beetween account

su youraccount (user youraccount )