Magento 2 | CLI Commands & Common problems

January 17th, 2019

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]

Flush Cache Storage:

php bin/magento cache:clean

short version:

php bin/magento c:c

Flush Magento cache:
magento
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

php bin/magento module:status

Disable a module

php bin/magento module:disable --clear-static-content


php bin/magento setup:upgrade

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 beprime (utente beprime )