Home » Magento 2 | Composer

Magento 2 | Composer

by Online Tutorials Library

Composer

Composer is a dependency management tool for PHP. Nowadays, all the frameworks or any CMS, like Laravel, are using a composer for managing their dependencies. Simultaneously, Magento 2 also uses a composer for dependency management. It is used to manage the Magento components and their dependency. Composer allows us to declare the libraries on which our project depends, and it will also manage install/update for us.

For Example – In our daily life, we create projects and then use the third party libraries to manage the dependencies as for sending Email or for creating PDF. We create our projects at these libraries, and a whole bunch of code becomes very wide. But in that code, we have a minimal part which has been written by us and the other part is the third party library.

Let’s suppose, we want to shift this code from one system to another, that time we are not shifting only our code but also dependency that we have used in that. These dependencies are widely available, we should not ship them from one place to another, and only our code should be shifted, and then the dependency should automatically get on to another system. So, to manage this, PHP’s composer is very widely used.

There are two important commands of Composer, which are given below:

  • composer install – It will be run at the very first time when we install any project. By using this command, all the dependencies are fetched.
  • composer update – It will check that what has been updated based on the composer.lock file. The composer.lock file contains the information that what was installed previously.

System Requirements

  • Composer can be installed on different platforms such as Windows, Unix, Linux, and Mac OS. The latest version of Composer is v1.9.0.
  • Composer requires PHP 5.3.2 and above versions. PHP must be installed on the system before installing composer, otherwise we are not able to use it.
  • XAMPP provides PHP setup so, install the XAMPP Click here.
  • For XAMPP installation steps see the XAMPP installation tutorial Click here.

Why composer is necessary?

We can install the Magento 2 without having a composer, but it should be installed using composer. Composer reads composer.json file in the root directory of Magento to download the third-party dependencies listed in the file.

Installation of Magento 2 is important using composer because whenever we install Magento using composer, it will create a file, i.e., composer.json. This file gives the information that what Magento version we are using, and a couple of other dependency details. These dependencies are automatically loaded based on the Magento version. So, if there is any update release, then we just only need to update the Magento version in composer.json file. Magento will accept the dependencies according to the Magento Community Edition. So, we do not need to worry about the upgrades.

Composer is very important because all the upgrades that we will do in Magento will be done only using composer. For Magento 2 installation using Composer click here.

Advantages of using composer

Installation of Magento 2 using composer offers the following advantages:

  • Without bundling the third-party library with source code, we can reuse them.
  • Reduces the extension conflicts and compatibility issues by using a component-based architecture with robust dependency management.
  • Repackage the Magento Open Source with the other components.
  • Follow the PHP Framework Interoperability Group (FIG) standards.
  • Use the Magento software in a production environment.

Autoloading is an important feature of the composer. Based on the autoload section in composer.json file, composer generates an autoload.php file inside the vendor directory. It ties into the bootstrap process you can see in index.php under the Magento 2. In short, it automatically includes the required code throughout your store.


Next TopicXAMPP Installation

You may also like