A Magento 2 extension can nowadays be installed in two ways: via a Zip archive or via Composer. There used to be an option of installing it via the browser-based Web Setup Wizard, the latter having some limitations, but is is deprecated as of Magento 2.3.6 and this service has already been removed in Magento 2.4.0 (the installation via the command line is offered as an alternative to the Web Setup Wizard). Among these three ways installation via Composer is now considered the preferred option; choose this option where possible.
Note: You should always make backups of your store’s database and files before performing such tasks as extension installation or update. These backups will help you to avoid data loss in case of a failed installation. Also you need to install and test any new extension in a development environment before doing it in production.
Install an extension using a Zip archive
In this case you will need a .zip archive with the extension files. Usually you can either get it from the Magento Marketplace or directly from the extension developer. To install the extension via an archive follow steps below. Please note that each extension usually has an installation guide. Be sure to read it because it may contain requirements specific to this particular extension.
Step 1: Enable maintenance mode
Before you install the extension, you should put your store into maintenance mode in order to temporarily restrict visitors from accessing your website while you’re installing the extension. Enable maintenance mode by running this command:
$ php bin/magento maintenance:enable
Step 2: Upload and extract the archive on the server
For this action you need to have an SFTP client (WinSCP, FileZilla, etc.) that is compatible with your operating system. Connect to the server with your store and upload the extension archive to a folder inside the Magento root directory, for example, /magento-root/data
. Once the archive has been uploaded, extract it into a separate folder running the following command in your terminal:
$ cd </magento-root/data> $ unzip <archive.zip> -d <extension-dir>
where <archive.zip>
is the extension archive, and <module-dir>
is the future destination /magento-root/data/module-dir/
where the archive’s contents are to be extracted.
Step 3: Copy the extension files into the Magento filesystem
Once you’ve extracted the files of the extension, you can replace it into app/code. The Zip archive can contain extension files starting from the extension root; or starting from the directory with the extension name; or starting from the directory with the name of the vendor, and may even contain files from another vendor, if they are dependencies for the installed extension; or starting from app
or code
directories. One way or another, you need to replace all extracted files so that the extension root would be at /magento-root/app/code/<vendor-name>/<extension-name>
, where <vendor-name>
and <extension-name>
are the vendor and extension names respectively.
Install an extension using Composer
If the extension is available as a Composer package, you can follow these steps to install it on your store. Please note that each extension usually has an installation guide. Be sure to read it because it may contain requirements specific to the extension in question.
Note: It is required that you have installed and configured Composer for this to work. Also you will need the extension’s Composer name (and specific version number, if necessary), so make sure you have it at hand before proceeding. You can get this info from the Magento Marketplace after purchasing the extension. Alternatively, you can find the Composer name and version of the extension in the extension’s composer.json file (if you already have files of this extension, for example, after manual installation).
Step 1: Enable maintenance mode
Enable maintenance mode by running this command:
$ php bin/magento maintenance:enable
Step 2: Add the extension to the composer.json file and update dependencies
Go to your Magento root directory and run the following command to add the extension to your composer.json file and update dependencies:
$ composer require <composer-name>:<version>
or if you need the latest version available:
$ composer require <composer-name>
Make sure you replace ‘composer-name’ with the Composer name of your extension.
Step 3: Verify the extension has been installed
Once Composer has finished updating your project dependencies, run the following command to verify the extension has been successfully installed:
$ php bin/magento module:status <vendor-name>_<extension-name>
By default, the extension can be disabled:
Module is disabled
<vendor-name>_<extension-name>
is not a Composer name of extension. If you doubt the extension’s <extension-name>, you can run the command ‘php bin/magento module:status’
without params that return you a list of all extensions. You can find the extension name under the List of disabled modules
.
Steps to complete installation for both modes
Step 1: Enable the extension
Enable the extension and clear static view files (if needed) by running the following command:
$ php bin/magento module:enable <vendor-name>_<extension-name> --clear-static-content
Step 2: Register the extension
Finally to register the extension and complete the installation, you must run the following commands in your command line:
$ php bin/magento setup:upgrade $ php bin/magento setup:di:compile $ php bin/magento setup:static-content:deploy
The first command registers the extension in your Magento store and performs some actions with the database required by the extension. The second command generates code, interception, etc. The third command writes static files.
Step 3: Check the status of the extension
To verify your extension is installed and enabled run the following command:
$ php bin/magento module:status <vendor-name>_<extension-name>
You should receive an output stating < code>Module is enabled. This message confirms that your extension has been installed and enabled successfully.
You can now clean the cache by running the following commands:
$ php bin/magento cache:clean $ php bin/magento cache:flush
Check the permissions to the files of your store. Safely disable maintenance mode:
$ php bin/magento maintenance:disable
And then go to the admin panel to proceed with the configuration of your newly installed extension.