Magento 2 composer complete manual. Steps. Common issues.

Magento 2 modules installation using composer. Steps. Common issues.

This guide explains how to quickly install composer. You will go through the Magento 2 installation using composer. We will also show you simple ways to install, update and remove Magento 2 modules. You will learn about one easier method of extension installation.

Find out more about common problems with composer installation and updates. Follow the step by step instructions.

What is the composer and how to install it?

In the following, you find instructions to install Magento 2 with the composer. Let’s see first what the composer is.

A composer is a tool for dependency management in PHP. A valuable tool for any developer as it allows you to declare the libraries your project depends on. And then the composer will install and update them for you.

Here are some advantages of using a composer:

  • Ability to reuse third-party libraries without bundling them with Magento 2 source code.
  • A proven way to reduce compatibility issues.
  • Its component-based architecture with a big number of dependencies and available packages.
  • Ability to repackage Magento 2 code with other components.

Install Composer

At the time of writing, Magento 2 does not support composer version 2. To install composer 1.x in the current folder, use command:

curl -sS https://getcomposer.org/installer | php -- --1 --filename=composer

To make composer accessible globally in system, execute the command:

sudo mv composer /usr/local/bin/composer

Ensure the Composer installed: type composer -V.

Note: Check the list of available commands in Composer. You have to run the command composer list and press Enter.

Mostly you will work with composer require and composer update commands.

  • Run composer require to install your packages.
  • Run composer update to install future updates when they’re available.

Okay, we'll check in on that later.

ProTip: Install Prestissimo composer plugin that downloads packages in parallel. It will speed up the installation process. Run the command:

composer global require hirak/prestissimo

Prestissimo is available at GitHub.

How to install Magento 2 with Composer

We are going to install Magento Open Source 2.4.1.

Get the Magento metapackage

Please follow steps:

  1. Log in to your Magento server as, or switch to, the Magento file system owner.
  2. Change to the web server docroot directory or a directory that you have configured as a virtual host docroot.
  3. Create a new Composer project using the Magento Open Source or Magento Commerce metapackage. For Magento Open Source 2.4.1, you have to run command:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.1 <install-directory-name>

Set file permissions

Before you install the Magento software, you should set read-write permissions for the webserver group. This is what it takes for the command line to write files to the Magento file system.

cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento

Install Magento

Before installing Magento 2.4+, you have to install Elasticsearch.

Please use the command line to install Magento. The next example assumes that:

  • the Magento install directory is named magento2
  • the db-host is on the same machine (localhost)
  • the db-name, db-user, and db-password are all magento:
bin/magento setup:install \
--base-url=http://localhost/magento2 \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

Note: please replace the values of a parameter with yours during installation on a real server. See the full list of parameters.

More information is available at Magento DevDocs.

Verify the installation

Now you have to verify the storefront. Follow the steps:

  • Go to the storefront in a web browser. For instance, if your Magento installation base URL is http://www.example.com, enter it in your browser’s address or location bar.
  • Review a sample storefront page.

The next step is to verify the Magento Admin.

  • Go to the Magento Admin in a web browser. For instance, your Magento installation base URL is http://www.example.com, and the Admin URI is admin. Then you have to enter http://www.example.com/admin in your browser’s address or location bar.
  • When requested, log in as a Magento Administrator.

Above we have passed through Composer installation. You also have a solid understanding of how to install Magento 2 via Composer.

Sometimes it happens that users face issues during installation. It is ok, so we prepared a list of common problems and solutions. Keep reading the guide.

Now let's get ready for installing Magento 2 modules via Composer.

How to install Magento 2 extensions with Composer

Let us show you the ways to install and update modules from the Magento Marketplace using composer. We'll also run commands to help you remove the extensions if required.

Later in the post, we will show you how to avoid using composer for module installation. There's a much easier and faster way. No using commands. No technical skills. Read to the end.

Well, let's start.

First we recommend enabling maintenance mode and making a backup of your store before modules installation.

bin/magento maintenance:enable

Install modules from Magento Marketplace

All modules installed via composer are downloaded to the vendor folder. By default, Magento uses repo.magento.com URL for loading the module if you buy it at Magento Marketplace.

To install modules from Magento Marketplace, you need Marketplace credentials.

Follow the steps:

  1. Add an extension's package to the root composer.json with the command:
composer require vendor/package

For instance, the next command will install the latest available version of the FireCheckout extension.

composer require swissup/firecheckout

It is also possible to install specific module version with the command:

composer require swissup/firecheckout:^1.25

At this step, you will see a request for credentials to access Marketplace. Please use access keys from your Marketplace account.

  1. Register the extension with bin/magento setup:upgrade command.
  2. Clear the cache by bin/magento cache:clean.

If your Magento uses Production Mode you need to deploy static content and run compilation:

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

To install an extension from a third-party repository, please continue with the instructions below.

Install third-party module

If you buy a module from a third-party site, you should add a vendor repository to composer.json. It would be necessary for a third-party module download and installation.

Usually, vendors provide the instructions.

For instance, we install the module from the SwissUpLabs extensions club.

Run the composer config command:

composer config repositories.swissuplabs composer https://ci.swissuplabs.com/api/packages.json

Then you have to follow the same steps as we mentioned for Magento Marketplace modules installation. Use command:

composer require vendor/package
bin/magento setup:upgrade

And for Production Mode:

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

Update modules using a composer

To update all installed modules and Magento dependencies, run the command in the Magento root folder:

composer update

To update only specific module, run

composer update vendor/module-name

Many Magento modules and themes are distributed as meta-packages. To update metapackage, run

composer update vendor/module-name --with-dependencies

For example, to update Argento theme and all included modules, run

composer update swissup/argento-m2 --with-dependencies

You can also update few modules running

composer update vendor/module-name1 vendor/module-name2

or even update all vendor modules

composer update vendor/*

For example, the following command will update all Swissup modules:

composer update swissup/*

To update the module installed with a specific version, you have to change its version in composer.json:

composer require “vendor/module-name:^x.x.x”

After updating, run:

setup:upgrade for updating module
bin/magento cache:clean

And for Production Mode:

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

Remove Magento 2 modules using a composer

To remove modules, run the command

composer remove vendor/package

For instance:

composer remove swissup/firecheckout
bin/magento cache:clean

Common problems with composer installation and updates

chmod problem

To prevent the issue, please set permissions correctly. Please follow Magento's recommendations.

Memory problem

Sometimes the composer commands can be interrupted/stopped with a similar message:

mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 2103975936) (tried to allocate 4096 bytes)

That means php on your server has not enough memory. Due to Magento2 requirements, it should be at least 2G of RAM. Yet "heavy" operations can take more.

Sometimes the following command can help:

php -d memory_limit=-1 composer ...... //allow using all available memory

But we recommend you create a swap file:

https://support.magento.com/hc/en-us/articles/360032980432

Note: If you still get this error - please contact your hosting as your server doesn't have such a memory amount.

Wrong composer version (using 2.x composer while require 1.x or old 1.x version)

The good practice is to use the latest updated software versions. Yet Magento 2.4 and earlier versions are still not compatible with Composer 2.0 version.

If you have permissions to change the composer on the server please use the following command to downgrade to the latest 1.x version:

composer selfupdate --1 

If you have no permission to change the system composer, please download your own composer. Then use it for running further commands.

Go to your store root and download composer:

curl -sS https://getcomposer.org/installer | php -- --1 --filename=composer

It will put the latest composer 1.x to the store root.

Wrong PHP version

Magento 2 is using PHP7.3 and PHP7.4.

Note: Make sure your server runs one of these versions with command

php -v

Contact the hosting if you have another version. They will provide you instructions on how to switch the terminal PHP version or run the commands under another version without changing it.

Sometimes you can run the commands with the key "--ignore-platform-reqs" that will not consider the PHP version while running the command. Use it as an example:

php composer require swissup/module-easytabs --ignore-platform-reqs

Missing required PHP modules such as ext-soap and wrong PHP version

See as an example:

Problem 1
- Installation request for magento/product-community-edition 2.3.4 -> satisfiable by magento/product-community-edition[2.3.4].
- magento/product-community-edition 2.3.4 requires ext-soap * -> the requested PHP extension soap is missing from your system.

If you have faced this problem, please check the Magento requirements. Here you can see the full list of required extensions. Please notice that Magento checks the modules during installation via composer. You might see the missing PHP modules.

Autoload error

Autoload error may occur when the module is at vendor and app/code at the same time. You have to:

  • Make a full backup of before deleting the modules.
  • Delete the module from app/code.

Error HTTP request failed

It may happen when customers are trying to install the module. The error will be like that.


Command "show" failed: 
In RemoteFilesystem.php line 560.
The "http://ci.swissuplabs.com/api/packages.json" file could not be downloaded: failed to open stream: HTTP request failed! 

This means that wrong repositories access information is stored in auth.json

So you have an issue with the access to the Swissup module repository. Make sure you have installed the Swissup Marketplace module and enabled swissuplabs channel with the command:

bin/magento marketplace:channel:enable swissuplabs

Installing Magento 2 themes and modules from the admin panel

You' ve seen all you need to install Magento 2 modules via composer. Instructions, steps, recommendations, and possible problems.

Now we offer you the installation process without issues when performing complex commands.

This is a nice alternative to the Web Setup Wizard extension manager provided by Magento earlier. Users had the opportunity to install, uninstall, and manage modules in the admin panel. Magento removed the manager.

We still offer you this fast, safe, and accurate way. Installing Magento 2 themes and modules directly from the backend is available via the Marketplace module.

This is a one-click installer. See what the Marketplace module does:

  • Automates a bunch of complex commands to run via CLI and backend interface.
  • Allows adding an unlimited number of custom software update channels.
  • Registers the packages repository in the composer.json file and saves its credentials to the auth.json file.
  • Simplifies after-installation tasks.
  • Allows integrating your Magento 2 store with third-party software.

You have to use only the admin panel!

That's it for today. We hope the guide will help you with composer installation and installing Magento 2 themes and modules.

We mentioned the most common issues and the ways to resolve them. In case you face other problems with composer installation and updates, please post them in the comments.

We will be glad to help you.

Leave a Reply