Nexcess Logo

Magento Composer install and troubleshooting guide

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
January 18, 2023

Magento uses Composer (also known as Magento Composer and PHP Composer) to manage the Open Source components and their dependencies. Reusing third-party libraries without bundling them with source code is possible when obtaining the Magento Open Source meta package using Composer.

By using a component-based architecture and robust dependency management, you can minimize extension conflicts and compatibility problems. You can also repackage Magento Open Source with other components and use it in a production setting, among other things.

Magento Composer install and troubleshooting guide

This article will assist you in understanding Magento Composer, Magento Composer installs and upgrades, common Magento Composer issues, and relevant troubleshooting techniques.

An overview of Magento Composer

Magento Composer is a dependency manager for PHP programs.

Why Magento Composer?

Developers can specify project dependencies in a composer.json file, and Composer will take care of the rest automatically. Only application code should go in the git repository because Composer makes it easier to keep vendor libraries out of your repository. Additionally, it makes it simpler to maintain the most recent versions of all necessary libraries because you can just run composer update to get the most recent compatible packages. Composer can also be used to manage Magento extensions.

What does Magento Composer do?

When determining which PHP packages to use in your project, the Composer looks for a valid composer.json file. The crucial require section serves that purpose and require-dev identifies a subset of items intended solely for development and testing as opposed to production use. You'll find more items than specified in your composer.json file because each of your required packages might also need dependencies of its own. These packages will be installed in the vendor directory of your project. The Composer was created to handle the challenge of safely managing these packages and requirements.

Composer updates packages by your constraints and those of every other dependency in the tree when you run composer update, navigating through the intricate web of dependencies. If there are no conflicts, the pertinent vendor files are updated, and composer.lock is written to track what was downloaded and at what version, exactly.

Magento Composer installs and upgrades

When developing any project using composer packages, the Magento composer update and Magento composer install commands are beneficial. The Magento Composer install command reads the composer.lock file and installs any dependencies listed in it when you run it from the terminal.

If the composer.lock file is missing

What happens, however, if the composer.lock file is missing? In this instance, the composer.json file is read, the dependencies are installed, and then the composer.lock file is created. Only the dependencies you used during development should be used in production, and their exact versions can be found in the composer.lock file. Thus, the primary use of this command is in production. However, it is also applicable to the development stage.

The Magento composer update command processes the composer.json file, installs dependencies, and generates a composer.lock file with the most recent dependencies when you run it. The command updates the dependencies version in the lock file but does not process the composer.lock file.

The Magento composer update command should only be used during the project's development phase. Because it updates both the composer.lock file and the dependencies. Running this command in a live environment could break your code because it updates the dependencies, which is bad because the version might change. Therefore, before updating the Composer version, you will need to check and confirm the compatibility of the most recent composer version with the production site.

About Composer Magento troubleshooting

Use the following Composer Magento troubleshooting techniques if you are having problems installing or updating with the Magento Composer.

Terminal command: composer diagnose

For a quick sanity check, run the composer diagnose terminal command. Use it to rule out more fundamental system-level issues. Here is the output:

Code snippet

$ composer diagnose
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.0.6
PHP version: 7.4.12
PHP binary path: /usr/local/Cellar/php/7.4.12/bin/php
OpenSSL version: OpenSSL 1.1.1h 22 Sep 2020
cURL version: 7.73.0 libz 1.2.11 ssl OpenSSL/1.1.1h
zip extension: OK

Image of code snippet

For a quick sanity check, run the composer diagnose terminal command. Use it to rule out more fundamental system-level issues.


Permissions issues

System permissions may vary, but Composer should always be run by the user who normally executes PHP. Therefore, it is most likely necessary to address permissions issues if you are experiencing them. To prevent further problems, you should make sure the resulting vendor/ directory has the proper permissions before running Composer as a super user (sudo). This may force a particular action to succeed where it had previously failed.

Increase Composer's verbosity

Try adding the -vvv flag when troubleshooting composer require magento/module_name:

Code snippet

composer require magento/module_name -vvv

Image of code snippet

Try adding the -vvv flag when troubleshooting composer require magento/module name.


Update Composer itself

Composer versions that are too old can lead to issues. Simply execute the self-update command to update Composer to the newest version:

Code snippet

composer self-update

Image of code snippet

Composer versions that are too old can lead to issues. Simply execute the self-update command to update Composer to the newest version.


Most common issues with Composer for troubleshooting

Below we have documented the responses to some of the most common issues.

Common issue #1: Composer error resulting from the setup:upgrade command when working with Magento 2


The section references code snippets and material from:

Solved: Composer error in setup:upgrade command in Magento2 - TheCoachSMB

When running a command php bin/magento setup:upgrade in Magento 2, you could encounter the following Composer error:

Code snippet

Running data recurring...Reading ****/magento/composer.json
Loading config file ****/magento/composer.json
Failed to initialize global composer: Composer could not find the config file: ****/magento/var/composer_home/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading ****/magento/vendor/composer/installed.json
Reading ****/magento/composer.lock
Checking for "magento/composer-root-update-plugin: 1.1.1" for the Web Setup Wizard...
Reading ****/magento/var/vendor/magento/composer-root-update-plugin/composer.json Loading config file ****magento/var/vendor/magento/composer-root-update-plugin/composer.json No Web Setup Wizard update needed for magento/composer-root-update-plugin;version 1.1.1 is already in ****magento/var.


Image of code snippet

When running a command php bin/magento setup:upgrade in Magento 2, you could encounter the following composer error.


To fix this issue, open the composer.json file in the site's Magento root directory and delete the listed module (for example, "magento/composer-root-update-plugin: 1.1").

After removing the module from composer.json and uploading the file once more, you must run the following command:

Code snippet

composer update

Image of code snippet

After removing the module from composer.json and uploading the file once more, you must run the composer update command.


Your problem will be resolved when you run this command because it will update any recent changes made in composer.json to the composer.lock file.

Common issue #2: Permission denied error

If you try to use the command composer self-update and receive the following error:

Image of code snippet

If you try to use the command composer self-update and receive this error.


To fix the error, the Composer must be downloaded and installed locally by running the following commands:

Code snippet

mkdir -p ~/.local/bin ; cd ~/.local/bin ; wget https://getcomposer.org/composer-2.phar ; chmod 755 ./composer-2.phar ;mv composer-2.phar composer ; echo "export PATH="$HOME/.local/bin:$PATH"" >> ~/.bashrc ; echo "COMPOSER 2 INSTALLED" ; source ~/.bashrc ; composer -V

Image of code snippet

To fix the error, the Composer must be downloaded and installed locally by running the following commands.


Common issue #3: Packages will not be available — you should upgrade to Composer 2 error

Any older composer commands may not function if you are using PHP 8.0. You must substitute the Composer v2.x version instead. For instance, the Composer 2 requires the module_name command should be used to install the package. Alternatively, you could use an older version of PHP.

Common issue #4: Wrong Composer version (using Composer 2.x while requiring Composer 1.x or older Composer 1.x version)

Using the most recently updated software versions is a good practice. However, Magento 2.4 and earlier versions are still incompatible with Composer 2.0. To revert the Composer to the most recent 1.x version, use the following command:

Code snippet

composer self-update --1

Image of code snippet

To revert the composer to the most recent 1.x version, use the following command.


You can also upgrade or downgrade to a specific version by providing the version number to self-update:

Code snippet

composer self-update <version>

Image of code snippet

By providing the version number to self-update, you can also upgrade or downgrade to a specific version.


Any self-update can be followed by a --rollback option to return to the previously installed version:

Code snippet

composer self-update
composer self-update --rollback

Image of code snippet

Any self-update can be followed by a --rollback option to return to the previously installed version.


If you want to update to a prerelease version, run the following command:

Code snippet

composer self-update --preview

Image of code snippet

If you want to update to a pre-release version, run this command.


Common issue #5: Memory exhausted

You can try running Magento Composer with the unlimited memory flag to resolve the memory exhausted problem:

Code snippet

php -d memory_limit=-1 /usr/local/bin/composer [COMMAND]


Image of code snippet

You can try running Magento composer with the unlimited memory flag to resolve the Memory exhausted problem.


When using a local composer, you can use the following command:

Code snippet

php -d memory_limit=-1 composer.phar [COMMAND]

Image of code snippet

When using a local composer, you can use the following command.


Common issue #6: "Your requirements could not be resolved due to an installable set of packages and no such file or directory in /autoload.php" errors

The most frequent message associated with update failures will always be preceded by information describing one or more dependency conflicts.

For example, an app like Craft can include the autoload.php file that Composer creates and updates once to load all of its dependencies. An altered or corrupt vendor folder may cause missing file errors mentioning autoload.php or autoload_real.php. The simplest solution in this scenario is typically to remove the vendor folder and reinstall all the dependencies:

Code snippet

rm -rf vendor
composer install

Image of code snippet

The simplest solution in this scenario is typically to remove the vendor folder and reinstall all the dependencies.


Common issue #7: Wrong PHP version

You can run the command with the option --ignore-platform-reqs to run the command without taking the PHP version into account if you are having trouble installing or upgrading Composer with the wrong PHP version:

Code snippet

php composer require module_name --ignore-platform-reqs

Image of code snippet

You can run the command with the option --ignore-platform-reqs to run the command without taking the PHP version into account if you are having trouble installing or upgrading composer with the wrong PHP version.


Common issue #8: chmod problem

If you are facing permission issues while running a Magento Composer install or upgrade, you will need to set permissions correctly in order to avoid the problem. You can do this by entering the following commands from the site's Magento root directory in the correct order:

Code snippet

cd <Magento root directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
chmod u+x bin/magento

Image of code snippet

If you are facing permission issues while running Magento composer install or upgrade, you will need to correctly set permissions in order to avoid the problem.


Conclusion

Magento Composer is a PHP and Magento 2 application-level package manager that offers a standard format for managing the dependencies of the Magento 2 application and necessary libraries. In addition to providing autoload capabilities for libraries, Composer enables developers to install PHP applications on Packagist. You can contact our support team anytime if you need help with the Magento Composer installation on your website.

Managed Magento hosting plans

Spin up instantly with free features like SSLs, an advanced Magento stack, RAM burst capacity, PCI compliance, SSH access, extensive support for M1 and M2, and more.

Our customer service representatives are highly knowledgeable about Magento Composer installation problems, troubleshooting methods, and their solutions. In addition, whenever you want to buy a hosting package suitable for your Magento website, you can also get in touch with us.

Depending on your needs, we'll assist you in selecting the best hosting option from the Magento hosting plans.

Recent articles

Related articles

Mohammed Noufal
Mohammed Noufal


Mohammed Noufal is a B.Tech graduate with a decade of experience in server administration and web hosting. He has a specialization in various cloud technologies and server management, including monitoring, configuring, troubleshooting, and maintenance.

He is a father to two daughters and finds fulfillment in their growth. In his free time, he enjoys blogging about technology, sharing experiences, traveling, making new friends, social networking, and listening to music.

With a strong technical background, family commitment, and creative outlets, he represents a well-rounded life journey.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.