Composer – Dependency manager for PHP
Composer
is free dependency manager for PHP projects that manages packages of application. It manages libraries of your particular project in vendor
folder inside your project. It works with packages and libraries and keeps you up to date. It simply finds version of libraries you are using in project and installs Latest version of libraries you need. Composer runs through command line and allow user to install dependencies from packagist.org.
Package is top repository. Now a days several most popular PHP frameworks are using composer as an internal part to manage dependencies such as laravel and symfony.
Download composer setup to install latest version of composer. Now you just need to set path of composer in path environment variable. Then you can use it via composer
keyword in command line simply. Composer’s official website let you know how to install composer. Composer installation in Ubuntu is so simple completes in two or three steps.
First of al, Update you package manager using below command
1
|
sudo apt-get update
|
Before installing composer you need to install serval dependencies. git
is used to download dependencies by composer. curl
and php5-cli
need to installing and running composer.
1
|
sudo apt-get install curl php5-cli git
|
Below command will download latest version of composer and install it in dir /usr/local/bin
1
|
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
|
That’s it, you are ready to use composer. Test your installation by running composer from terminal. Type composer
in command line. If you would not get any error then you have successfully install composer.
Now quick step to install any dependencies in your project.
1
2
|
$ cd www/project/directory/path
$ composer require [package name]
|
and it will download and install package in your project.
Update all dependencies of project
1
2
|
$ cd www/project_directory_path
$ composer update
|
Go to project path throughcd [project path]
and run composer update
command it will update all the libraries added in composer.json
file in require
key. require
simply tell to composer which dependencies project required.
If you are developing project using PHP framework and not using composer then use it and leave worrying about package management.
Sumit Jani
Away sum article @Gopal. I am beginner in PHP and have some confusions regarding actually what is composer that’s solved by your article.
Thanks you