Install Magento Extension via CLI
In this article
Installing a Magento extension from the command line is the fastest and most reliable method, especially for production environments. It bypasses the admin panel's slower file uploads and gives you full control over the process. You'll use Composer to fetch the extension package, then run Magento's built-in CLI commands to register, upgrade, and deploy static content. Before starting, ensure you have SSH access to your server, the Magento file system permissions are set correctly, and you have the extension's Composer name (e.g., vendor/module-name) and version.
What You'll Need
- SSH or terminal access to the server where Magento is installed.
- Composer installed globally or available in the Magento root directory.
- The extension's Composer name (vendor/module) and version, or a direct package URL.
- Magento file system permissions set so the web server user can read/write (typically
bin/magentois executable). - Authentication keys (public/private) if the extension is from Magento Marketplace or a private repository.
Step-by-Step
- Backup your store – Before any extension installation, create a full backup of your Magento files and database. Use your hosting control panel or command-line tools like
mysqldumpandtar. - Navigate to the Magento root directory – Usually
/var/www/htmlor/home/user/public_html. Runpwdto confirm you're in the correct folder that containsbin/magentoandcomposer.json. - Set your Magento to maintenance mode – Run
php bin/magento maintenance:enable. This prevents customers from seeing errors during installation. - Require the extension using Composer – Type
composer require vendor/module-name:version. For example:composer require example/module-shipping:1.2.3. If you don't know the exact version, omit it and Composer will pick the latest stable release:composer require vendor/module-name. - Wait for Composer to resolve dependencies – Composer will download the extension and any required packages. If you're prompted for a username/password, enter your Magento Marketplace public and private keys (or repository credentials).
- Run the Magento setup upgrade – Execute
php bin/magento setup:upgrade. This applies database schema changes and registers the module with Magento. - Compile the dependency injection (DI) if needed – In production mode, run
php bin/magento setup:di:compile. In developer mode, this is optional but recommended. - Deploy static content – Run
php bin/magento setup:static-content:deploy(add-fif you're in developer mode to force re-deployment). For multiple locales, specify them:php bin/magento setup:static-content:deploy en_US. - Clear the cache – Run
php bin/magento cache:flushto clear all cache types. - Disable maintenance mode – Run
php bin/magento maintenance:disableto bring your store back online. - Verify the installation – Check the module list:
php bin/magento module:status– your extension should appear as enabled. Also test the frontend and admin areas.
Common Mistakes
- Forgetting to run
setup:upgrade– the module appears in the code but doesn't work. - Running commands as the wrong user (e.g., root) – this can cause file permission issues. Use the same user that owns the Magento files (often
www-dataor a cPanel user). - Not using the correct Composer repository – if the extension is from a private repo, you must add it to
composer.jsonfirst. - Skipping static content deployment – the store looks broken (missing CSS/JS) especially in production mode.
- Ignoring version conflicts – Composer will abort if the extension requires a different PHP version or a conflicting module.
Tips
- Always test on a staging environment first if possible.
- Use
composer why vendor/module-nameto see why a package is installed. - Keep a log of the exact commands you run – this helps if you need to rollback.
- If the extension requires specific cron jobs, set them up after installation (check the extension's documentation).
- For Magento 2.4.6 and later, you can use
php bin/magento setup:upgrade --keep-generatedto skip regenerating static files if you're in developer mode.
Troubleshooting
- Composer authentication error – If you get a 401 or 403, your credentials are wrong. Re-run
composer config http-basic.repo.magento.com your_public_key your_private_key. - Module not appearing in module:status – Check that the module's
registration.phpis in the correct directory and that the namespace matches the composer package name. - White screen after installation – Likely a static content or DI compilation issue. Run
php bin/magento setup:static-content:deploy -fandphp bin/magento setup:di:compileagain, then clear cache. - Database errors during setup:upgrade – Check the extension's install scripts. Sometimes you need to manually drop a table or column if a previous install failed.
- Composer memory limit error – Run
php -d memory_limit=2G /usr/local/bin/composer require vendor/module(adjust path to composer). - Extension conflicts with another module – Use
php bin/magento module:disable vendor_module --clear-static-viewto disable the conflicting one temporarily, then re-enable after fixing.
Frequently Asked Questions
Do I need to install the extension via Composer?
Yes, Magento 2 officially supports Composer installation. It's the only method that ensures proper dependency management and easy upgrades.
What if I don't know the Composer name of the extension?
Check the extension's documentation or the composer.json file if you have the package. On Magento Marketplace, the name is listed on the product page.
Can I install a free extension from GitHub using the command line?
Yes, you can add the GitHub repository to your composer.json using composer config repositories.module-name vcs https://github.com/user/repo, then require it as usual.
How do I uninstall an extension via CLI?
Run php bin/magento module:uninstall vendor_module – this removes the module's database data and then you can remove the package with composer remove vendor/module.
What is the difference between developer and production mode for installation?
In developer mode, static content is generated on the fly, so you can skip the deploy step. In production mode, you must run setup:static-content:deploy and setup:di:compile.
Why do I see a 404 after installing?
This often happens when the extension's routes conflict. Clear the cache and check the url_rewrite table. Also ensure you've run setup:upgrade.