Composer is a dependency management tool made for PHP. It allows users to manage and integrate external dependencies and libraries. Using Composer in your project makes the software development process much more efficient. It manages packages or libraries on a per-project basis, installing them in a special folder ‘vendor’. Some packages can depend on other packages, but Composer manages all of these dependencies so all of them are upgraded at the same time.
In this guide, we will install Composer for different systems, Windows and Linux / Unix / macOS.
Table of Contents
Prerequisites
To run Composer in its latest version you will need PHP 7.2.5.
Install Composer on Linux / Unix / macOS
Before installing Composer, you need to download Composer from the official website and verify the installer’s signature (SHA-384) to ensure that the installer file is not corrupt. In your command line, execute the following:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
The long string of characters 55ce33d7678c5a6.. is the installer’s signature. Every time a new version of Composer is available it is changed, so make sure that you get the latest SHA-384 from the Composer Download Page.
The next step is to install Composer either locally or globally. What this indicates is whether your dependency manager will be stored in your current directory or in the /usr/local/bin directory in your system.
Local Installation
php composer-setup.php
Global Installation
php composer-setup.php -–install-dir=/usr/local/bin –filename-composer
Once the installation is complete, the next step is to remove the installer:
php -r "unlink('composer-setup.php');"
To check whether the installation of Composer is successful, you can type:
composer
And you should get the following:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.0.8 2020-12-03 17:20:38
Install Composer on Windows
To install Composer on Windows, you need to do the following steps:
- Download the Composer-setup.exe file. You can find it here.
- Run the Composer-setup.exe file. You will get a window with an option Developer mode, which you need to ignore and continue with the installer.
- On the next step it will ask you to locate the command-line PHP that you want to use. Once the location is selected, click Next.
- On the next window, you will encounter Proxy Settings, which you need to leave unchecked and click Next.
- On the last window, you will encounter the Ready to Install window. Click Install and wait for the installation to complete.
After the installation is completed, you need to check if the installation is successful. You can do that by opening Command Prompt and type the following command:
composer
The output you should get is the following:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.0.8 2020-12-03 17:20:38
This means that we have successfully installed Composer on your Windows machine.
Conclusion
In this tutorial, you got to learn about Composer and how to install it and configure it successfully on your machine.