Steps for Installing PHP Composer on Debian 12 Bookworm Linux

Learn how to install PHP Composer on Debian 12 Linux to fulfill the various dependencies required for the development of PHP projects or while installing some applications written in PHP language.

To efficiently manage the dependencies for PHP projects there is a dependency manager called Composer. It offers various libraries and packages that a developer can use to speed up the process of creating PHP-based software. Composer allows PHP developers to declare the libraries their projects depend on and manages the installation and updating of these dependencies.

Key features of Composer include:

  • Dependency Management:
  • Autoloading
  • Version Control
  • Centralized Repository for PHP packages.
  • Composer allows developers to define scripts in their composer.json file
  • Global Installation:
  • Providing a convenient command-line interface
  • Community-Driven:

Step 1: Update the Package repository

To install packages on Debian, first access your command terminal. After that, run the system update command that will not only install the updates for your system packages but also refresh the APT cache as well.

sudo apt update

Step 2: Install Dependencies

If you have not installed PHP on your system already then get that using the below command along with other dependencies required for Composer to function properly.

sudo apt install curl php php-cli php-mbstring unzip

In the above-given command, we are getting curl – used for downloading files, php-cli for the command-line interface, php-mbstring for multibyte string support, and unzip for extracting compressed files.

Step 3: Download Composer:

The developers of Composer offer a simple and easy-to-use script for setting up Composer on Linux systems including Debian. So, in this step, we use the CURL to download that script.

curl -sS https://getcomposer.org/installer -o composer-setup.php

Step 4: Verify the Installer (optional)

Well, it is not necessary but a good idea to confirm the integrity of the script before using it to install the Composer. Just execute the given command.  The output of the below command must be “Installer verified“.

HASH="$(curl -sS https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Download php composer script

Step 5: Install PHP Composer on Debian 12

Now, that we have the verified script for installing Composer on our Debian 11, let’s run it. Also, while running the script using PHP we are declaring the location that tells the system where it must create a directory to save the files of Composer.

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Install PHP Composer on Debian 12

Step 6: Verify the Installation by checking the composer version

Although we already got the message showing the installation is completed successfully, yet to confirm we can check the Composer version, we have on our system.

composer --version

Step 7: Updating PHP Composer

The composer regularly receives updates, so in the future while working on your PHP project you can ensure that you have its latest version on your Debian 12 system, by running the given command.

sudo composer self-update

Conclusion:

These were the quick steps we needed to follow to get PHP Composer not only on Debian 12 but even for Linux distros based on it such as Ubuntu. Composer is an open-source dependency manager with extensive features to enhance your PHP development workflow. You can learn more about it from the official Composer documentation.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.