Install Magento Extension via Composer: Step-by-Step
In this article
Installing a Magento extension via Composer is the recommended method for Magento 2 because it keeps your store manageable, simplifies updates, and avoids direct file modifications that can break upgrades. Instead of manually copying files, Composer pulls the extension from a repository, registers it with Magento's component manager, and then you run a few commands to enable and deploy it. This guide walks you through the entire process, from preparation to verification.
What You'll Need
- A Magento 2 installation (open source or Commerce) with SSH access to the server.
- Composer installed on your server (check with
composer --version). - The extension's Composer name (e.g.,
vendor/module-name) and its version, usually found on the extension's page or in its documentation. - If the extension is commercial, you may need an access key (public and private) from the Magento Marketplace or the vendor's repository.
- Backup of your store files and database (always a good practice before installing anything).
Step-by-Step
- Back up your store. Before making any changes, create a full backup of your Magento files and database. You can use your hosting control panel, a backup tool, or command-line tools like
mysqldumpandtar. - Log into your server via SSH. Navigate to your Magento root directory (the folder containing
bin/magentoandcomposer.json). For example:cd /var/www/magento2. - Authenticate with Magento Marketplace (if needed). If the extension is from the Magento Marketplace, you'll need to authenticate with your public and private keys. Run
composer config http-basic.repo.magento.com your_public_key your_private_key. You can generate these keys in your Magento Marketplace account under My Profile → Access Keys. - Add the extension to Composer. Run the following command, replacing
vendor/module-namewith the actual extension name andversionwith the desired version (or use*for latest):composer require vendor/module-name:version. Composer will resolve dependencies and download the extension. - Enable the extension. After the package is installed, run
php bin/magento module:enable Vendor_Module(replaceVendor_Modulewith the actual module name). This tells Magento to activate the module. - Run the upgrade and compile commands. Execute
php bin/magento setup:upgradeto update the database schema and register the module. Then runphp bin/magento setup:di:compileto generate dependency injection configuration. If you're in production mode, also runphp bin/magento deploy:mode:set production(or skip if already in production). - Deploy static content. Run
php bin/magento setup:static-content:deployto generate static files (CSS, JS, images) for your storefront. If you have multiple locales, specify them, e.g.,en_US. - Clear the cache. Run
php bin/magento cache:cleanandphp bin/magento cache:flushto clear all caches. - Verify the installation. Log into your Magento admin panel and check under Stores → Configuration → Advanced → Advanced that the module is listed as Enabled. Also, check the frontend to ensure the extension's features are visible. You can also run
php bin/magento module:statusto see the module's status.
Common Mistakes
- Skipping the backup – If something goes wrong, you may lose data or have to spend hours fixing the store.
- Using the wrong module name – The Composer package name (e.g.,
vendor/module) is not the same as the module's internal name (e.g.,Vendor_Module). Make sure you use the correct one in themodule:enablecommand. - Not running
setup:upgrade– This command is essential for the module to be recognized and for database changes to be applied. - Forgetting to deploy static content – In production mode, without this step, CSS/JS files may not load correctly.
- Running commands as the wrong user – Ensure you have proper file permissions. Usually, you should run commands as the same user that owns the Magento files (often
www-dataor your SSH user).
Tips
- Always check the extension's compatibility with your Magento version before installing. The extension page usually lists supported versions.
- Use version constraints in
composer require, like^2.0, to allow minor updates while preventing major breaks. - If you're using a version control system (like Git), commit the
composer.jsonandcomposer.lockchanges after installation so you can track changes. - Test the extension on a staging site first if possible, especially for critical storefronts.
- Keep a list of installed extensions and their versions in a README for future reference.
Troubleshooting
- Composer authentication errors – If you get a 401 or authentication error, re-check your access keys. Make sure you're using the correct public and private keys, and that they are active.
- Module not showing in admin – Run
php bin/magento module:statusto see if it's enabled. If it's listed as disabled, runphp bin/magento module:enable Vendor_Moduleagain and thensetup:upgrade. - “Class not found” errors – This usually means the dependency injection compilation is outdated. Run
php bin/magento setup:di:compileagain. - Static content not loading – Run
php bin/magento setup:static-content:deploywith the correct locale(s). If you're in developer mode, you may need to runphp bin/magento cache:clean. - Database errors during
setup:upgrade– Check the error message. It might be due to a conflict with another extension. Try disabling the other extension temporarily, or check the extension's support documentation. - Composer memory limit errors – Increase PHP memory limit for the command:
php -d memory_limit=2G bin/magento setup:upgradeor setCOMPOSER_MEMORY_LIMIT=-1before running composer.
Frequently Asked Questions
Do I need to install via Composer for all Magento extensions?
It's strongly recommended for Magento 2. Composer ensures proper dependency management, easier updates, and cleaner uninstallation. Some extensions may offer manual installation, but it's not recommended as it can cause issues with future upgrades.
Can I install a free extension from GitHub using Composer?
Yes, if the extension has a composer.json file and is hosted on a repository like GitHub, you can add the repository to your composer.json and require it. You'll need to specify the VCS repository URL in your composer.json.
What is the difference between composer require and composer update?
composer require adds a new package to your composer.json and installs it. composer update updates all dependencies to the latest versions allowed by your constraints. Use require for new installs, and update only when you want to upgrade existing packages.
Do I need to run setup:upgrade after every extension install?
Yes, setup:upgrade is required to apply any database schema changes and register the module with Magento. Skipping it can lead to errors or the module not working.
How do I uninstall an extension installed via Composer?
Run composer remove vendor/module-name, then run php bin/magento setup:upgrade and php bin/magento setup:di:compile. Finally, clear the cache. This should remove the module and its database changes.
Can I install an extension without SSH access?
If you only have FTP access, you can still install via Composer by downloading the package and manually uploading it to the app/code directory, but this is not recommended. For proper Composer-based installs, SSH is required.