Skip to content

Instantly share code, notes, and snippets.

@acjbizar
Last active February 16, 2022 12:40
Show Gist options
  • Select an option

  • Save acjbizar/c7f15df603e0381af87b9781e27a013b to your computer and use it in GitHub Desktop.

Select an option

Save acjbizar/c7f15df603e0381af87b9781e27a013b to your computer and use it in GitHub Desktop.
Front-end development in Magento 2 requires more command line instructions than is probably reasonable. Let’s make a collection.

Install dependencies

Install Node (with npm)

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install nodejs

Navigate

cd /var/www/html

Goes to the correct folder. (Replace with the folder that contains your application.)

Rights

chmod -R 777 pub/ generated/ var/

Set rights very loosely so that won’t be an issue (which is often is).

Modules

php bin/magento module:status

Get list of available modules and their enabled/disabled status.

php bin/magento module:enable Vendor_Module

Enables a specific module.

php bin/magento module:disable Vendor_Module

Disables a specific module.

More

php bin/magento deploy:mode:show
php bin/magento deploy:mode:set production

Sets production mode. This compiles certain files that it does not in developer mode. Useful when you miss specific JavaScript files like jquery-storageapi. You can set it back to developer mode after the files are compiled.

php bin/magento dev:template-hints:enable

Enable template hints. Unlike n98-magerun2, this applies to all stores.

rm -rf pub/static/* var/view_preprocessed/*

Clear processed views. Needed when overwriting module specific CSS for the first time (for example).

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

Deploy static files. Appears to only do the default locale for some reason. If you want to deploy for another locale, add it to the instruction specifically.

grunt exec
grunt less
grunt watch

Start Grunt task that will watch Less file changes. The first two can be done theme specific.

kill -9 $(ps -aux | grep "[g]runt" | awk '{print $2}')

Kills any Grunt task that might be running. (You can exit with Ctrl + C if you have Grunt running in a terminal, but this is not always the case.)

php bin/magento setup:upgrade

TODO: Description.

php bin/magento indexer:reindex

Fixes indexes.

php bin/magento setup:di:compile

Compile code.

php bin/magento cache:clean
php bin/magento cache:flush

Clean the cache.

composer update

Update the project.

php bin/magento admin:user:create --admin-user='username' --admin-password='strong-password' --admin-email='[email protected]' --admin-firstname='John' --admin-lastname='Doe'

Add new admin user (when locked out).

php bin/magento admin:user:unlock _username_
php bin/magento --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment