Steps to install a module on Magento 2

by Remy Pereira on 15th February 2023

In Magento, modules are self-contained packages that extend or modify the core functionality of the system. Modules can be used to add new features, change the appearance of the site, or modify the way certain tasks are handled. You can obtain Magento modules from Magento marketplace, third party providers, Github or from a custom development. Once you have obtained the module, follow these steps to install it on Magento 2.

Backup Magento 2 files and database.

It's a good practice to backup your Magento 2 files and database before making any changes.

  1. Connect to your server using SSH.

  2. Navigate to the Magento 2 root directory.

  3. Create a new directory to store the backup files.

    mkdir backup
  4. Run the following command to create a backup of your Magento database:

    mysqldump -u database_username -p database_password database_name > backup/database.sql

    Replace database_username, database_password, and database_name with your actual database credentials and database name.

  5. Run the following command to create a backup of your Magento files:

    tar -czvf backup/files.tar.gz *

Install via composer or upload files to app/code

There are mainly three ways to install the module.

  1. Install via composer

    • This requires that you create access keys in your marketplace accounts. To create access keys you need to go to My profile → My Products → Access Keys

    • Update your composer.json file in your Magento installation directory.

    • Then run the command

      composer require component-name:version
  2. Upload the files to app/code

    • Download the module you want to install as a .zip file.

    • Extract the .zip file to a temporary directory on your computer.

    • Connect to your server using an FTP client.

    • Navigate to the root directory of your Magento 2 installation.

    • Create a new directory called app/code if it doesn't already exist.

    • Upload the extracted module directory to app/code.

  3. Install from a git repository

    • Clone the Git repository to a local directory on your computer.

      git clone <repository URL>
    • Create a new directory called app/code in your Magento 2 root directory if it doesn't already exist.

    • Copy the module directory from the cloned Git repository to app/code directory in your Magento 2 root directory.

List available Magento modules

This step is to verify that the above steps where executed correctly. You will see your new module name in the disabled category.

sudo bin/magento module:status
.................................
Mageplaza_InstagramFeed
Mageplaza_Productslider
Magepow_Categories
PayPal_Braintree
PayPal_BraintreeGraphQl
ProductPositionImport_PositionImport
Rich_Bluealligator
Rich_Cart
Rich_Wishlist
Rootways_Megamenu
Temando_ShippingRemover
Vertex_Tax
Vertex_AddressValidationApi
Vertex_RequestLoggingApi
Vertex_RequestLogging
Vertex_AddressValidation
Webkul_CustomRegistration
Yotpo_Yotpo

List of disabled modules:
Magento_Mymodule

Enable Magento Module

Run the following command to enable the Magento module that you installed.

sudo bin/magento module:enable Magento_Mymodule

where Magento_Mymodule is the name of the module.

Update Magento 2 database

Run the following command to update Magento 2 database.

sudo bin/magento setup:upgrade

If you encounter issues with store not displaying correctly after upgrade, the following set of commands can solve the issue.

sudo bin/magento setup:di:compile
sudo bin/magento setup:static-content:deploy en_US en_GB -f

The en_GB and en_US locales are for reference. Please change according to your locale.

Then, reset file ownership/permissions according to your webserver configuration. This is because the commands may be executed by a superuser and the generated files may not have correct permissions.

Clear Magento 2 cache

Clear the Magento 2 cache by running the following commands:

sudo bin/magento cache:clean
sudo bin/magento cache:flush

Verify Installation

Finally, check if the module is installed by navigating to the Magento 2 Admin Panel and checking if the module is listed in the Stores → Configuration → Advanced → Advanced section


Post a comment

Comments

Nothing yet..be the first to share wisdom.