Skip to main content

Magento 2 - Some bash commands


Below are some of the bash commands used in magento 2, which i use regularly. Will update, if any new command is added up.

#!/bin/bash

basedir="path/to/magento/root"
cd $basedir

sudo chmod -R 777 pub var

echo "Enable/Disable module? (y/n)"
read enable_disable
if [[ $enable_disable == 'y' ]]; then
    echo "Module Name"
    read module_name
    echo "Enable the module? (y)"
    read enable_module
    if [[ $enable_module == 'y' ]]; then
        sudo php bin/magento module:enable --clear-static-content $module_name
    else
        sudo php bin/magento module:disable --clear-static-content $module_name
    fi
fi

echo "Upgrade setup? (y/n)"
read upgrade_setup
if [[ $upgrade_setup == 'y' ]]; then
    sudo php bin/magento setup:upgrade 
fi

echo "Compile magento code? (y/n)"
read compile_code
if [[ $compile_code == 'y' ]]; then
    sudo rm -rf var/di
    sudo php bin/magento setup:di:compile 
fi

echo "Reindex the data? (y/n)"
read reindex
if [[ $reindex == 'y' ]]; then
    sudo php bin/magento indexer:reindex
fi

echo "Clear cache? (y/n)"
read clear_cache
if [[ $clear_cache == 'y' ]]; then
    sudo php bin/magento cache:clean
fi


sudo chmod -R 777 pub var



Comments

Popular posts from this blog

Magento 2 - Create Attributes in Setup

Sometimes in our module we require to create product or category attributes automatically on module install. Also, we might require to add extra fields to quote, sales order, invoice, creditmemo tables. We will go through how to do that in magento 2. You can find the sample code in the git repo .