Skip to main content
Blog General

Magento 2 – Installing Composer

Premnath M
August 27, 2015 |
MAGENTO-2-Installing-Composer

What is a composer?

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Dependency management

To quote verbatim from getcomposer.org – Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with “packages” or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it will never install anything globally. Thus, it is a dependency manager.

Why Composer?

PEAR was built using the assumption, that PHP library components would be installed system-wide. As it turns out, this isn’t the best solution. In practice, different projects require different versions of the same libraries. If you upgrade system wide libraries, all dependent projects have to be upgraded, too.

So, composer fixes this issue. It installs required libraries separately for each project.

Suppose:

1. You have a project that depends on a number of libraries.

2. Some of those libraries depend on other libraries.

Composer:

3. Enables you to declare the libraries you depend on.

4. Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).

Composer Repository

The Packagist website shows which packages can be installed through Composer. There is also a repository of Magento specific packages available on the Firegento website.

Packagist is used as a default repository for Composer, but you can add Firegento’s repository by editing your Composer configuration file. First, however, you’ll need to install Composer itself.

Magento 2 – Installing Composer 

First 

Composer basic Commands

a) All existing package

          composer show

 b) One particular package

          composer show vendor/package

 c) Update few packages and not all

          composer update vendor/package vendor/package2

 d) Update commands

          php composer.phar update  – Linux

          php composer update  – Windows

 e) Command removes packages

          php composer.phar remove vendor/package vendor/package2

 Basic Constraints

 1. Exact

          Example: 1.0.2

 2. Range

           Valid operators are >, >=,

Examples:

  • >=1.0
  • >=1.0
  • >=1.0 =1.2

 3. Range (Hyphen)

          1.0 – 2.0

 4. Wildcard *

          1.0.* is the equivalent of >=1.0

 Version compatibility

-dev

  • -stable
  • -alpha
  • -beta
 Lock file  (To find the error log in the composer.lock file)

 composer.lock

 How to handle composer

 We need to use Tab key for configuring the composer.json file

Second

Third

This is just an introduction to Magento 2 – Installing Composer, there is a lot more to it – know more please go through the below documentations –

Premnath M

Premnath is a Magento Developer Plus certified developer.

More posts by Premnath M