How to Install PHP Composer on Debian 11 or 10

PHP Composer is a powerful tool that helps manage dependencies in PHP projects. It works by specifying the dependencies in a file called composer.json and then running the composer command to install or update them. Incorporating PHP Composer into your Debian system can bring numerous advantages to your development process. The following are some of the key features of PHP Composer:

  • Dependency management: Composer allows you to specify your project’s dependencies and automatically installs and updates them.
  • Autoloading: Composer automatically generates the autoloader for your project, making it easy to include the needed classes without manually requiring them.
  • Version constraints: Composer allows you to specify version constraints for your dependencies, ensuring that your project always uses compatible versions of the packages it depends on.
  • Package discovery: Composer makes it easy to discover new packages by searching through a central repository.
  • Community standards: Composer follows the PSR-4 standard for autoloading, which is widely used in the PHP community, making it easy to integrate with other projects and libraries.

This tutorial guides you through downloading and installing PHP Composer on Debian 11 Bullseye or Debian 10 Buster. Additionally, you will learn about the dependencies required for PHP Composer and examples of how to use it.

Step 1: Update Debian

Before we begin, we must ensure that our package list is up-to-date. To do this, open up a terminal and run the following command.

sudo apt update

The following command can be used to view available updates for review or knowledge purposes.

apt list --upgradable

The below command can update any packages that are no longer current on your system.

sudo apt upgrade

Step 2: Install PHP

To use PHP Composer, we must first have PHP installed on our system. To install PHP on Debian, run the following command.

sudo apt install php

The command given will install the standard Debian repository version of PHP. If you want to install a different version of PHP or the latest stable release, check out my guide on installing the latest version of PHP on Debian.

Step 3: Install PHP Composer

Installing PHP Composer globally on Linux is a great way to make the tool available to all users on your system. Here are the steps to install PHP Composer globally on Linux.

Open a terminal and run the following command to download the Composer installer:

curl -sS -o composer-setup.php

In case the curl command fails, you may need to install the package.

sudo apt install curl -y

For users that desire the Global installation of Composer, run the following command.

sudo php composer-setup.php --install-dir=bin --filename=composer

Example output:

Once Composer is installed globally, all users on the system can use it.

Alternatively, if you want to install Composer in a specific directory, you can specify the directory in the –filename= option, for example.

sudo php composer-setup.php --install-dir=/usr/local/composer --filename=phpcomposer

You can also add the directory to your PATH by editing the .bashrc or .bash_profile file, for example:

echo 'export PATH="$PATH:/usr/local/composer"' >> ~/.bashrc

This way, you can use the Composer command from any directory.

Step 4: Verify installation

To verify that PHP Composer has been installed correctly, run the following command.


You should see the version of the Composer along with the usage instructions.


Once PHP Composer is installed, you can use it to manage the dependencies of your PHP projects. For example, you can run the following command to create a new project with PHP Composer.

composer create-project --prefer-dist laravel/laravel myproject

This command will create a new Laravel project in a directory called “myproject.” You can also use the composer command to install and update dependencies in an existing project. For example, you can run the following command to add a new package to your project.

composer require <package-name>

And to update a current package, you can run the following command.

composer update <package-name>


In conclusion, PHP Composer is a powerful tool that makes managing dependencies in PHP projects easy. Following the steps outlined in this article, you can easily install PHP Composer on Debian and start using it to improve your development workflow. It’s also worth noting that Composer is an essential tool for modern PHP development, and it’s widely used by developers worldwide, so it’s a good idea to have it installed on your system. Additionally, if you are working on a team, having a common dependency management tool like Composer can help ensure that everyone is using identical versions of the packages, which can prevent compatibility issues.

See also
How to Install Nvidia Drivers on Debian Linux 11 or 10

Leave a Comment

Share to...