Composer is a dependency manager for PHP, which allows you to require all dependant libraries for a particular project. In layman terms, composer can bring in all dependant libraries required on a project by project basis and keeps them all at one place. You may read this article from PHILIP BROWN@culttt.com who has explained it better.
Well, we’ll quickly see how to install composer.
Download Composer Installer
# curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading...
Composer successfully installed to: <current_dir_path>/composer.phar
Use it: php composer.phar
# mv composer.phar /usr/local/bin/composer
Make sure you set PATH variable to read ‘composer’
How to Install a package using Composer
Let us assume that you wish to install PHP7 compatibility checker, say php7cc.
# composer global require sstalle/php7cc Changed current directory to /home/peter/.composer Using version ^1.0 for sstalle/php7cc ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) - Installing nikic/php-parser (v1.4.1) Downloading: 100% - Installing pimple/pimple (v3.0.2) Downloading: 100% - Installing symfony/polyfill-mbstring (v1.0.0) Downloading: 100% - Installing symfony/console (v2.8.0) Downloading: 100% - Installing sstalle/php7cc (1.0.2) Downloading: 100% symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing symfony/process () symfony/console suggests installing psr/log (For using the console logger) Writing lock file Generating autoload files
The ‘global’ option allows commands to run in the global composer directory and ‘require’ adds required packages to your composer.json and installs them.