What is Composer?
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
First of all, there is a complete and official tutorial to be found in https://getcomposer.org/doc/00-intro.md
Yes i know, it’s a bit hard to follow for first time user, that’s why i cover this basic tutorial just to get you started using composer.
Download and install composer in your local machine
https://getcomposer.org/Composer-Setup.exe
The default path on windows if you use auto installer is: C:\ProgramData\ComposerSetup\bin
If the above directory is not added on your System Environment Path, do it.
Now it’s time to test them out.
Open your favorite command terminal
There are many ways to test if you have successfully installed them correctly, for me i just test them by asking the version of the apps you have installed.
composer -v
The above image shows that i have successfully installed them correctly.
Installing your first app dependency
You can search the app you want to install here: https://packagist.org/ and get the name of the app you want to install.
Here is the list of the commands you may want to learn and explore but for the sake of this tutorial i will just cover the basic installation: https://getcomposer.org/doc/articles/scripts.md
In my case, i am going to install my app in C:\test, if you have not make your composer globally go ahead and make a copy of composer.phar inside your app directory:
php -r "readfile('https://getcomposer.org/installer');" | php
after running the command, you should have a copy of composer.phar inside your app directory
Ready to install the app? run this command below: (cakephp/cakephp is the name of the app from package list , while name_of_your_app is the name of your project app)
php composer.phar create-project –prefer-dist cakephp/cakephp name_of_your_app
create-project – command to create your project
–prefer-dist – There are two ways of downloading a package source (beta or the source code) and dist (stable package)
To update your dependency:
php composer.phar update
Other useful command can be found here
Comment your questions. Thanks for reading!