Before Composer was born, we often struggled with dozens of third-party libraries to manage. The update is very difficult and not to mention the installation stages are very difficult to remember. With the introduction of Composer, everything changed completely. In this article we will learn about Composer – a tool to manage libraries in projects.

Viewing: What is Composer

What is Composer?

Composer is a PHP Dependency Management tool that manages the libraries your Php project uses. More precisely Composer manages the dependencies of the resources in the project. It allows declaring the libraries that your project uses, composer will automatically load the code of the libraries. It generates the necessary files into your project, and updates the libraries when new versions are available.

Composer Benefits

The idea of ​​composer is not new, it is inspired by tools like Node’s npm. Its operation is also very similar to APT (available on Ubuntu) or Yum (available on CentOS), but composer is only within the Php project, not on the whole OS like the two guys above.

In the past when you deployed projects based on these, you would have faced some of the following:

Does your project use some external libraries. You have to download them and put them in the project folder before you can use them. Some of those libraries use (dependencies) on other libraries. You will have difficulty updating the versions of the libraries. . If library A, uses library B, library B uses library C. Then if one of these libraries has an update, you will have to manually dig back to its root to update.

READ MORE  Meaning Of Rip

However, the work will be easy with Composer, you will do:

Declare the libraries that the project uses. Centrally manage the libraries in use for the project and their versions easily through the composer.json file. Find the versions of the packages that are installable and needed for the project, and then install them into the project. project ie download them to project.

See also: How to Download Game Audition

Maybe you are interested:

Use Composer

To use composer, we need a composer.json file. This file contains information describing the dependencies that we need in the project. The contents of the file can be:

{ “name”: “laravel/laravel”, “description”: “The Laravel Framework.”, “keywords”: , “license”: “MIT”, “require”: { “laravel/framework”: “5.8.* ”,}, ….} The requirements for dependencies will be listed in the require key. Above is an example for the default composer.json file of laravel framework version 5.8. The * part means that we accept the new update version like 5.8.11 or 5.8.12 for example.

Using the terminal, in the project folder we execute the composer install command. It will look in the directory where the composer.json file exists and do the work that the file requires including putting all the dependencies into the project and doing other necessary work.


In the main project file, add this line:

include_once “./vendor/autoload.php”; All the packages you need are now added to the project, ready for you to use. Or as in Laravel you can simply type:

composer dump-autoload then all the libraries in composer are available for use in the entire project.

READ MORE  How to Fix Error Font, Vietnamese Font #3

Update package

You just need to type composer update . Composer will automatically update the packages in use. If you want to update to newer versions or releases, edit composer.json

Note: Never run composer update command in production environment, but check on machine to avoid incompatibility.

See also: What is Na – Na Orientation


Composer is used everywhere in the PHP world, so as a Php developer you need to equip yourself with the basics of composer. After that, we just need to focus on the product and put aside the thought of updating the package.