composer

Composer is a package manager for PHP.

Install

Read the installation docs.

Moving composer.phar into /usr/local/bin/composer makes it available from any directory. Make sure this directory is added to your shell’s PATH environment variable.

Update

# Requires sudo to write
sudo composer self-update

Usage

Install packages

Install the exact package versions specified in composer.lock. This should be used immediately:

  • After project setup
  • After changing Git branches
composer install

Update packages

Updates all packages, their dependenices, and composer.lock.

composer update

Update specific packages

Updates a specific package, its dependencies, and composer.lock.

composer update {namespace}/{packageName}

Troubleshooting

Authentication

Create the file: ~/.composer/auth.json

{
   "github-oauth": {
     "github.com": "<personalAccessToken>"
   },
   "http-basic": {
      "repo.magento.com": {
         "username": "<username>",
         "password": "<password>"
      }
   }
}

Missing GMP extension

Composer requires PHP + GMP extension to execute. The PHP library in your shell’s PATH may not include that. Switch PHP versions:

  1. Develop: Command Line: PHP
  2. Try running composer install again.

Memory limit

If Composer runs out of memory run it like this, which allows to up 1.5 GB of memory.

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223
COMPOSER_MEMORY_LIMIT=-1 composer install

In my ZSH config, I have this aliased to memcomposer.