What is Composer, How to Install and Use?

If you have been developing software with PHP for a while, you may have noticed that wasting time to re-download, write, and try to use the current version is a huge loss. If you are projecting using libraries such as Zend, Symfony, and Laravel, you need more.


Dependency management tool for PHP. It allows you to define the libraries your project needs and install and update them for you. The important thing here is that the update does not automatically do so according to its own head.

In fact, this application is not the first program made for this work; Based on the nmp in Node.js and the Bundler in  Ruby.

Who Should Use?

I think anyone who writes code with PHP should use it and need it. You must be using certain libraries or frameworks, etc.; and using the latest version always makes more sense. There is a constant need for major libraries and it will be difficult to get one at a time.

How to Install Composer?

You need PHP 5.3.2 and higher to work for it – think even Composer needs it in our projects when there is a need.

Curl if available;

if your computer does not have curl you can install it with PHP exe:

Note: If you are going to install it in PHP and have not shown PHP as Path; You need to install it from the directory where PHP.exe is installed. For example, if I want to re-establish it right now, you have to follow a path like;

Command Prompt (cmd)

In Linux, you should go with a cd command in the same directory where PHP is installed.

Windows Setup

The simplest way to install on Windows is to download and install  Composer-Setup.exe. When installing, it will add the composer directly to PATH, which will allow you to use the composer from Command Prompt without typing a directory.

How to use it?

Now that we have installed our Composer, we can install the packages we need. To create a Composer setup file, we need to create a JSON directory in the root directory of the project. If you don’t know JSON, I recommend you to learn about it, knowing JSON makes your job a lot easier.

For example, you will need to create a composer.json file as follows to download the PSR Log Pack.

To install PSR Log, all you need to do is go to your project directory (terminal or cmd) and run the following code.

When you look at the main directory of your project, you may see that the vendor has created a folder called psr and that you have downloaded the necessary PHP files. Isn’t that easy?

You can make your own packages (zip, repo (vcs), files, etc.) not only ready packages but also add them to your projects.

Automatic Loading

You have several packages and you may need to install them automatically in your project. The good side composer will also help you with this.

Add the following line of code to the top of your index.php or bootstrap file. It will add and drop/include/require to your project.

I hope it has been a useful article.