Composer is a package manager, which is an application-level, for PHP programming language. Composer is used for managing PHP application dependencies and libraries.
Here, in this article, I am giving steps to install composer on the Ubuntu servers 18.04, 20.04, and 22.04 LTS. Many modern applications are uses Composer to manage dependencies. Recently I installed Flarum Forum, using PHP Composer which is an open-source application.
Prerequisites
- PHP 5.3.2+
- Git, SVN, Fossil, or Mercurial depending on how the package is version-controlled.
- Linux, Mac, or Windows
Install Composer on Ubuntu 18.04, 20.04, 22.04
As mentioned above about the prerequisites, you must have installed PHP and Git on the system.
To install PHP you check out the tutorial and for Git you must execute sudo apt install git
.
And in this tutorial, I have explained the steps to install Composer on the Ubuntu server. And following the same steps, you can install Composer in other Linux distributions like Debian, etc.
Step – 1. Get Composer Package
sudo curl -s https://getcomposer.org/installer | php
Step – 2. Move composer.phar
to /usr/local/bin/
directory
sudo mv composer.phar /usr/local/bin/composer
Step – 3. Check Composer Installed version
composer -V
Useful Commands for Composer
Update The Latest Version of Composer:
composer -selfupdate
Clear the Cache memory of Composer:
composer clearcache
Search Composer Library Packages:
composer search library_name
Create A Project using Composer:
sudo composer create-project vendor/package .
Remove Composer Project:
sudo composer remove vendor/package
FAQs
What does PHP Composer do?
Composer is an application-level package manager and a tool for dependency management in PHP. It also allows you to install and update the libraries of your project.
How do I use the Composer library?
Using the command line you can use the PHP Composer library. The command will be sudo composer create-project vendor/package
.
Why is Composer used in Laravel?
Laravel uses Composer to utilize package libraries and dependencies.
What is composer.lock in Laravel?
composer.lock stores the records of the exact version that is installed in the system.
Who created PHP Composer?
Composer is developed by Nils Adermann and Jordi Boggiano.
Summary
Composer is a free and open-source tool that excellently helps project developers to manage, maintain, and update applications and libraries. It’s used for managing project/application dependencies and libraries with different version requirements. The composer can create an isolated environment on your local machine for development.