DED9

What is Composer (PHP plugin) ? And how to install it !

If you are planning to become a PHP programmer, this way, you will hear the name Composer tool. Many of the things that programmers do in different projects are often repetitive. A tool called Composer was developed to prevent this from happening in the PHP programming process. With this tool, programmers can use libraries and packages written by other developers.

A composer is a command-line tool designed to reduce software dependency ( Dependency Management ) on external libraries and packages. Also, you can easily download and manage application packages and libraries using this tool. In other words, Composer has simplified and standardized the process of downloading packages, updating them, and so on. If you are interested in learning how to install Composer and use this practical tool, read on.

Composer installation tutorial

<a class='agl' href='https://7learn.com/course/programming-alphabet'> <strong> Programming Training </strong> </a>

In general, there are two ways to install and use Composer. These methods are local (Locally) and global (Global), which composers can use. This tool is part of the project when a local method is used to install the composer. But if the global method is used, Composer will run on the whole system. It would help if you kept in mind that Composer does not install packages and libraries globally in the system, but they are defined only in the project.

How to install Composer in Windows

The easiest way to install this tool on a Windows operating system is to use the Composer installation file. Also, this method installs the composer globally in the system. To use this tool in your projects, you must use PHP versions 5.3.2 and above. A composer is a multi-platform tool, meaning it runs easily on Windows, Mac, and Linux operating systems. To install this tool, you must first download the tool. To download Composer, visit the official website of this program at  getcomposer.org. Click on Download to download the latest version of this program, as shown below.

On the next page, you will be directed to; there are several ways to install Composer. In this section, the simplest method of installing this tool is reviewed. On this page, click on  Composer-Setup.exe to download the Composer installation file.

Once you have downloaded the Composer executable file, run it and follow the steps like the pictures. In this step of the installation, you must specify the address of the PHP executable file to install Composer. The PHP executable file is usually installed by software such as Xampp, Wamp, and. Of course, the installation file usually automatically identifies the PHP executable file address. If the installer could not automatically detect this file, you will need to do this manually by clicking the Browse button. After doing this, click Next.

It would help if you were connected to the Internet to install this tool. After this step, there is no need to change and perform any special action; click on the Next options and finally Install.

Congratulations, your composer is installed. You will now be able to use this tool by executing the composer command in the directory for each project and accessing many packages and libraries.

 

Composer installation tutorial on Linux operating systems

As mentioned, Composer is a multi-platform tool. So this tool can be installed on operating systems such as Macs and Linux. Composer is easy to install and can be easily installed and activated by the command line. Use the following commands to install Composer on these systems:

$ curl -s https: //getcomposer.org/installer | php 
$ sudo mv composer.phar / usr / local / bin / composer

The first command downloads the composer. phar file to the system. The second command moves this file into the executable folder. In this step, just run the following command to run Composer.

$ composer

When we have different packages and libraries, we need to load them automatically into the project. Composer does this with an auto-upload file. This means that the tool can automatically load all the files related to packages and libraries in the project. To use this feature, add this code to the main project file:

require  'vendor / autoload.php' ;

How does Composer receive PHP packages?

The main source of Composer packages and libraries is the Packagist site, known as the default repository for PHP projects. Various developers make their libraries and various project packages available to other programmers on this site. Accordingly, using the Composer tool, you can easily access the many libraries and packages developed in PHP.

When a package is loaded into a project using Composer, and this package requires other packages, Composer downloads it and places it in the project without any special programming action. Due to this feature, there is no need to worry about the dependencies of the libraries used in the project in the programming process. Another task of the composer is to manage the loading of classes. A class in the project is loaded only if it is used in code. This will greatly affect the loading speed of the project.

Exit mobile version