How to Install and use PHP Composer on Linux?
Last Updated :
13 Apr, 2022
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:
- Composer is used to enabling the declaration of the libraries which is needed for a certain project.
- According to the project, Composer finds out the proper version of the package and automatically installs it in the project.
- Using Composer individuals can update all dependencies all at a time in one command.
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.
Similar Reads
How to Install Eclipse For PHP on Linux? Eclipse is a free open source platform, Integrated Development Environment (IDE) with the help of which applications are made using the Java programming languages and other programming languages are also used such as C/C++, PERL, Python, Ruby, etc. It is composed of many plug-ins and is designed to
1 min read
How to Install PHP on Alpine Linux? Alpine Linux is a Linux distro that is lightweight and security-focused. The main aim of alpine is to be minimalistic be it in scope or space. Since it is small in size it is used in those containers which require less time for booting. Unlike other distros which use GNU, Glibc alpine used musl, bus
2 min read
How to Install PHP Composer on Windows? Composer is essentially a package manager for PHP. You can effectively manage libraries and packages in your PHP projects by using Composer, a dependency management for PHP. Composer makes package management easier for both small and large-scale applications by automating the installation and update
3 min read
How to Install PHP Composer on MacOS? A composer is a tool for dependency manager in PHP. It is an important package manager for PHP. The package manager means it allows anyone to import codebases into the project and keep them updated and also helps in managing dependencies. Or we can say that it allows users to install the required li
2 min read
How to Install PHP on Linux? PHP is a popular server-side scripting language that is especially used in web development. If you're working on a Linux environment, whether it's a personal development setup or a production server, you will likely need PHP installed. In this article, we will see the step-by-step guide to install P
2 min read