Open In App

How to Install and use PHP Composer on Linux?

A composer is a tool that is used for dependency management in PHP. But Composer is not a package manager. Composer is an application-level manager that is completely used for PHP programming language. A package manager is used to import codebases into the project and make it up to date. Composer helps to declare necessary libraries and dependencies requires for a particular project. However, it helps to install some packages which are not easily available on Packagist.org. and it also allows adding require project libraries to a certain project. It is used to download required packages for some projects. 

Features:



Installing PHP Composer on Linux

Follow the following step to install PHP Composer on Linux:

Step 1: At first, Linux Terminal should be opened. Then the below-mentioned command should be run. Only this command is enough to install the appropriate version of Composer as per the machine requirements. It will take some time. Wait for the process’s completion.



curl -Ss https://getcomposer.org/installer | php

 

Step 2: After downloading the Composer follow the below-mentioned commands. This command will first move into the location where the Composer is installed. Then the second command will make it executable. 

sudo mv composer.phar /usr/local/bin/composer

chmod +x /usr/local/bin/composer

 

Step 3: Now, the installation and configuration process is completed. Now, the below-mentioned command should be run to check the version of the Composer. It will give the output as shown in the image below. Hence installation is completed.

composer

 

Use of Composer

For using Composer for any project, any specific dependency or library should be installed. There are many packages available for Composer. Among them, the easiest one to install is the Slugify package. Slugify is used to convert a string into a Slug. As a sample installation process, Slugify is mentioned here.

Step 1: At first, the Linux terminal should be opened. Then one directory should be created. Below mentioned commands should be followed step by step. It will create one directory called slugify.

cd ~
mkdir slugify

cd slugify

 

Step 2: For installing Slugify package manager in Composer browse to this link. There search for Slug in the search bar. Then click on the below mention option to move forward.

 

Step 3: After clicking, the below-mentioned command can be found. This command should be copied. It will use for further process.

composer require cocur/slugify

 

Step 4: After running the above command it will provide the output same as below. It will configure Composer for the project where Slug package manager is needed. Simply it will install package manager in Composer and hence the first project is created in Composer.

 

Article Tags :