Composer is a dependency manager for PHP similar to npm for Node.js or pip for Python.
Composer pulls all the required PHP dependency packages for our project and manage them for us. It is used in all modern PHP frameworks and platforms such as Magento 2, Symfony and Drupal.
In this tutorial, we will go through the steps of installing and using Composer on a CentOS 7 machine.
Prerequisites
The following prerequisites must be fulfilled before we continue with this tutorial:
- Logged in as a user with sudo privileges
- Have PHP 7 installed on your CentOS 7 system.
We can install Composer with a simple command below
# yum install composer
Installing Composer on CentOS
The following steps describe how to install Composer on a CentOS 7 system.
We just need to download composer executable and put under bin directory.
# curl -sS https://getcomposer.org/installer | php
The following commands will make composer available globally for all users in our system, which can be used for all PHP applications on the system.
# mv composer.phar /usr/local/bin/composer # chmod +x /usr/local/bin/composer
The last step is to verify the installation:
# composer
The command above will print the Composer’s version, commands, and arguments.
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.8.5 2019-04-09 17:46:47 Usage: command [options] [arguments]
This completes the Composer installation tutorial. Enjoy using Composer!