How To Install Composer on Debian 12
In this tutorial, we will show you how to install Composer on Debian 12. For those of you who didn’t know, Composer has become an essential tool for PHP developers, enabling efficient management of package dependencies in their projects. With Composer, you can easily add, update, and remove PHP packages, libraries, and frameworks, simplifying the development process and ensuring code integrity.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you step-by-step install Composer on a Debian 12 (Bookworm).
Prerequisites
- A server running one of the following operating systems: Debian 12 (Bookworm).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Composer.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Composer on Debian 12 Bookworm
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt install build-essential curl php-cli php-mbstring git unzip
This command will refresh the repository, allowing you to install the latest versions of software packages.
Step 2. Installing Composer on Debian 12.
Now, it’s time to download the Composer installation script and verify its integrity. Execute the following commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Now that we have the Composer installation script, we can move the executable file to a globally accessible location on our system. Run the following command:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
To verify that Composer is successfully installed on your Debian system, run the following command:
composer --version
If the installation was successful, you will see the Composer version information displayed on the screen, indicating that Composer is ready for use.
Step 3. Testing Composer.
To ensure that Composer is working correctly, let’s create a sample project using Composer and run a simple command to manage dependencies.
mkdir myproject cd myproject
Initialize a new Composer project:
composer init
This command will interactively guide you through the process of setting up a new Composer project, including specifying the package name, description, author details, and more.
Step 4. Troubleshooting.
While installing Composer on Debian 12 is generally straightforward, you may encounter some common issues. Here are a few troubleshooting tips:
- Proxy configuration: If you are behind a proxy, make sure to configure the proxy settings for both your system and Composer. Refer to the official Composer documentation for detailed instructions.
- Outdated dependencies: If you encounter dependency conflicts or errors during the installation process, update your system packages and try again. Run
sudo apt update
to update the package lists andsudo apt upgrade
to upgrade installed packages. -
Hash verification failure: If the Composer installation script fails the hash verification, it could indicate a corrupted file. Delete the
composer-setup.php
file and repeat the download and verification process.
Congratulations! You have successfully installed Composer. Thanks for using this tutorial to install Composer on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Composer website.