This tutorial helps you to install and configure PHP composer on Debian 10 Buster, Debian 9 Stretch, and Debian 8 Jessie systems.

1. Prerequsities

Shell access to a running Debian system with sudo privilege. PHP must be installed and configured, version 5.3 or higher.

2. Install Composer on Debian

You can download the composer script from the getcomposer.org website by running the following command. It will create a composer.phar file in the current directory. curl -sS https://getcomposer.org/installer | php Copy composer.phar file under bin directory to make available anywhere in the system. Also, set the execute permission on file. I have changed the filename from composer.phar to the composer for easy use. Type composer at the command prompt. This will provide you composer version details along with options available with the composer command.

3. Upgrade PHP Composer

The composer has the ability to upgrade itself without downloading again. Simply run the below command from the terminal to upgrade compose on Debian.

Working with PHP Composer

Assuming you have been successfully configured PHP composer on your system. That will help you to manage modules for your application. For example, to install a new module for your application. Switch to the PHP application. Run the following command to install psr/log module in the application. Composer will automatically create or update composer.json file at application root directory. Now, the application can use the functionality provided by the module. The above command will install the latest version of the module. You can also define the module version you want to install for your application. If the module is already installed, it will automatically downgrade/upgrade the package to the specified version. The module no longer required can be removed with the following command. All the above commands also update composer.json file accordingly.

Conclusion

In this tutorial, you have found instructions to install composer on a Debian Linux system. You can install composer globally to allow access to all users and applications. Also, you can install composer for a specific directory.