Skip to content

PHP Tutorial Composer

Installing Composer

Lesson 248 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

Composer is a command-line program, so you install it once on your computer.

Check that PHP works first

Composer needs PHP on your command line.

terminal
BASH
php -v

If this prints a version number starting with PHP 8, you are ready. If not, see Installing PHP.

Windows

The easiest way is the Composer-Setup.exe installer from getcomposer.org. It finds your PHP, adds Composer to your PATH and installs it. Open a new terminal window afterwards.

macOS

With Homebrew:

terminal
BASH
brew install composer

Linux

Many distributions have a package (sudo apt install composer), but it can be an older version. The official instructions on getcomposer.org/download install the latest version with a short script that checks a signature. Follow those, because the exact hash changes with each release.

Afterwards, move the file to a folder on your PATH:

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

Check the installation

terminal
BASH
composer --version

You should see something like Composer version 2.x.x.

A local composer.phar

You can also keep a composer.phar file inside a project and run it with php composer.phar. This is useful on servers where you cannot install programs system-wide. Everything in this chapter works the same way, with php composer.phar in place of composer.

Update Composer itself

terminal
BASH
composer self-update

Docker

If you use Docker, the official composer image has it ready:

terminal
BASH
docker run --rm -v "$PWD":/app composer require league/commonmark

Common problems

ProblemLikely reason
composer: command not foundComposer is not on your PATH. Open a new terminal, or fix PATH
Your PHP version (...) does not satisfy requirementThe package needs a newer PHP than the one Composer uses
SSL or “could not resolve host” errorsNetwork, proxy or certificate issue. Check your internet connection
Out of memoryRun COMPOSER_MEMORY_LIMIT=-1 composer update once
A needed extension is missing (ext-mbstring, ext-curl)Enable it in php.ini

Which PHP does Composer use?

Composer uses the PHP found on your PATH. If you have several versions installed (for example through XAMPP or Laragon), check which one you get with php -v, and make sure it is the one you want.

dangerous
Do not run Composer as root
Running sudo composer install can leave files owned by root and can run package scripts with full permissions. Run Composer as your normal user.