Composer is a dependency manager for PHP, similar to npm for JavaScript. In this tutorial, we will show how to setup composer to install PHP library in a project.

1. Download Official Installer in project folder

Execute following command in terminal:

$ cd path/to/project
$ curl -sS | php

2. Download the PHP library required

$ php composer.phar require <library>

3. Include library in PHP code

After adding following above the code, we can start using the library.

use <library>;

4. Add composer generated files to .gitignore


This is done so that these files are untracked and will not be pushed to remote origin branch (e.g. Github).

5. Command to install all dependencies in composer.json

$ php composer.phar install


Hopefully you are able to successfully use Composer in your PHP project now. 😃
Please let me know how it goes in the comments below. Thank you for reading! 😊


  1. MailGun Documentation