User Agents

Web browsers and everyday web tech, explained

Install Magento Extension via Composer: Step-by-Step

· 5 min read · Extensions

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. 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 mysqldump and tar.
  2. Log into your server via SSH. Navigate to your Magento root directory (the folder containing bin/magento and composer.json). For example: cd /var/www/magento2.
  3. 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.
  4. Add the extension to Composer. Run the following command, replacing vendor/module-name with the actual extension name and version with the desired version (or use * for latest): composer require vendor/module-name:version. Composer will resolve dependencies and download the extension.
  5. Enable the extension. After the package is installed, run php bin/magento module:enable Vendor_Module (replace Vendor_Module with the actual module name). This tells Magento to activate the module.
  6. Run the upgrade and compile commands. Execute php bin/magento setup:upgrade to update the database schema and register the module. Then run php bin/magento setup:di:compile to generate dependency injection configuration. If you're in production mode, also run php bin/magento deploy:mode:set production (or skip if already in production).
  7. Deploy static content. Run php bin/magento setup:static-content:deploy to generate static files (CSS, JS, images) for your storefront. If you have multiple locales, specify them, e.g., en_US.
  8. Clear the cache. Run php bin/magento cache:clean and php bin/magento cache:flush to clear all caches.
  9. 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:status to 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 the module:enable command.
  • 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-data or 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.json and composer.lock changes 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:status to see if it's enabled. If it's listed as disabled, run php bin/magento module:enable Vendor_Module again and then setup:upgrade.
  • “Class not found” errors – This usually means the dependency injection compilation is outdated. Run php bin/magento setup:di:compile again.
  • Static content not loading – Run php bin/magento setup:static-content:deploy with the correct locale(s). If you're in developer mode, you may need to run php 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:upgrade or set COMPOSER_MEMORY_LIMIT=-1 before 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.