Installing Composer

PHP library dependency manager

Composer the per-project dependency management

Composer is a tool used for dependency management in PHP. You are probably familiar with Pear, the PHP extension and application repository.

I personally do not like Pear mainly because you are forced to install dependencies system wide and because most packages are out of date or alpha.

Composer is not a package management, composer deals with packages and libraries however it does based on per-project basis. That means if your project has dependencies, that’s where Composer come in handy, by default Composer does not install anything globally.

Composer will take the heavy lifting for you by installing all dependencies even if the package or library also has dependencies. There is a great website called Packagist if you are looking for packages or libraries, there is no need to reinvent the wheel.

Installation

Linux:

The following command will download the file composer.phar to your working directory but if you want to install somewhere else, all you have to do is pass this parameter --install-dir=directory.

curl -sS https://getcomposer.org/installer | php 

Note: The file composer.phar is the Composer binary, so I suggest you make this global by moving it somewhere like /usr/share/composer/composer.phar and create a symlink to /usr/local/bin, this way you can invoke composer from anywhere instead of php composer.phar. 

Mac OSX:

Composer is part of the homebrew-php project. Tap the homebrew-php repository into your brew installation if you haven't  done so yet:

brew tap josegonzalez/homebrew-php

then

brew install josegonzalez/php/composer

Use Composer with the composer command.

Note: If you receive an error saying PHP53 or higher is missing use this command to install php.

brew install php53-intl

Windows:

This is the easiest way to get Composer set up on your machine. Download and run Composer-Setup.exe, it will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line.

Installing dependencies

To resolve and download dependencies just run:

php composer.phar install

or if you installed global:

composer install

Comments

blog comments powered by Disqus