Composer PHP dependency management - Installation

What is Composer?

In simple words, Composer is a dependency management tool for PHP. If you are familiar with tools such as Maven, npm, or Gradle then the concept of Dependency management is not new to you.
For those who don’t know dependency management just a primer here.
Suppose you are working on a project and you need to use some libraries. You add them to your project, but if those libraries depend on multiple others then this task becomes a nightmare.
This is where a dependency management tool comes handy. You just define what are the libraries your project depends on and this tool will take care of finding all the dependencies, downloading them, and putting them in their proper places.

What composer can do for you?

This is a very conservative list of things that composer does out of the box for you.
  1. Enables you to define a list of libraries along with their versions
  2. Identify the list of versions for all the direct and transitive dependencies
  3. Download these packages from a repository
  4. Update the versions of dependencies with one single command
  5. Enables you to define your own scripts and task executions
For a detailed list of features and documentation please check their website.[]

Installing Composer

Installing composer is very easy. You just need to have PHP version 5.3 or higher installed on your system.
Just run the below commands from your terminal. To get the latest code you can check the download page.[], since the SHA code keeps changing with every release.
Before running below script make sure you have changed the memory_limit to 2G or more.
php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
This script will download the installer and check your PHP.ini configurations.
Once the installation is done you’ll have a composer.phar file in the directory.
You can run it to check the version.
php composer.phar -V
On Linux based systems you just need to change the file mode to the executable and rename it to composer from composer.phar.

On windows, to use composer directly from the command line as a program you’ll need to create a batch file on windows.
echo @php "%~dp0composer.phar" %*>composer.bat
Just put this file on your path and you can run it directly.
C:\zuber\composer> composer -V
Composer version 1.10.8 2020-06-24 21:23:30

Popular Posts