How to install and use PHP Composer on Debian 11
Composer is a dependency manager for PHP with support for dependencies to libraries and frameworks. It helps you manage your project's dependencies, whether they come from Packagist, Github or anywhere else.
In this article, TipsMake will share you how to install and use PHP Composer on a Debian 11 server.
System update
The Linux system is constantly updated every day with new security fixes, kernel patches, and performance improvements. Some updates simply change the version number (such as from 3.2.0-4 to 3.2.0-5), while others may provide bug fixes or improvements security. The best way is to keep your system up to date to take advantage of the latest features, maintain stability, and keep your computer safe from vulnerabilities that can be exploited by attackers.
Run the following command to update the system.
sudo apt-get update && sudo apt-get upgrade -y
Once the upgrade is complete, run the following command to install the required dependencies.
sudo apt-get install curl unzip git php-cli php-zip php-mbstring -y
After the system is fully updated, restart the server. Run the following command to reboot the system. When making changes to the system, such as hardware configuration, kernel, or package updates, it is important to restart the computer for the changes to take effect.
sudo reboot -r now
Once the reboot is complete, log back in as the non-root user yourself and continue to the next step.
Install PHP Composer
Now that your system is up to date and all the necessary dependencies are installed, it's time to download and install the latest version of PHP Composer.
The PHP Composer developer provides an installation script written in PHP, to make the installation process easy. Download the script, check the script's signature to make sure it's not corrupted, and run the installer.
First, download the latest version of the PHP Composer installation script from the official website using the curl command.
curl -o composer-setup.php https://getcomposer.org/installer
Now, run the command below to check the signature of the PHP script. This step is to ensure that the installer has not been tampered with (i.e. corrupted or modified) during the download.
HASH=906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8 php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
The output will look like the image below. This output verifies that the installer is not corrupted. HASH may change in the future, you can find the latest hash on this page https://composer.github.io/pubkeys.html
If the file has been tampered with, the command will get rid of the Installer corrupt export and unlink. In that case, you will need to download the installer and verify the hash again until you get the installer verified message.
The output verifies that the installer is not corrupted
To summarize, there are two ways to install Composer on a Debian 11 system: locally or system-wide.
The system-wide Composer installation allows you to use the composer command from any directory. You can easily update your dependencies from any project folder from the same Terminal as Composer, without having to move back and forth between folders. To install Composer overall, run the following command.
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
This command will install Composer as a system-wide command called composer in the /usr/local/bin directory and make it available to all users.
You will see the following result.
To check if Composer has been installed properly, run the following command to invoke the Composer executable.
composer
The output will be like this.
A local install is to install Composer in your home directory or somewhere else inside the directory you specify, since you won't need to access the composer command from outside that directory, unless using symbolic link.
To install Composer locally, run the following command. Replace path/to/directory in the command below with the directory where you want to install Compose.
sudo php composer-setup.php --install-dir=path/to/directory --filename=composer
In this tutorial, you learned how to install PHP Composer on Debian 11. Now you can use it for local or system-wide installation if you want to access composer command from anywhere on the system mine.
- Notable changes and additions in Debian 11 'Bullseye'
- How to Install and Use Ansible on Debian 10
- How to Install Gradle on Debian 10
- Configure mouse settings on a Debian system
- Use Speedtest CLI to test Internet speed on Debian 10
- How to set JAVA_HOME path in Debian 10
You should read it
May be interested
- How to install NVM on Debiannvm stands for node version manager. with nvm, you can manage multiple node.js instances of nodejs and switch between them without uninstalling and reinstalling the node.
- Notable changes and additions in Debian 11 'Bullseye'debian is one of the oldest, most stable and flexible linux distributions in the free and open source world.
- Do not destroy the Debian system!debian is a powerful and reliable system, but new users are still very easy to ruin the system, by not doing everything the way debian does.
- Debian 10 Buster, New features in Debian 10 Busterdebian 10 buster has been released. let's explore the new features in debian 10 buster through the following article!
- How to Restart Debian Using the Command Linethe linux operating system can run without a reboot not only for a few weeks but for years. but sometimes there's a good reason to reboot your linux system after a week or two, depending on the situation.
- 9 best Debian-based Linux distributionsfortunately, debian's flexibility has made it a good base for other distributions, providing a more pleasant experience for those new to linux.
- Configure mouse settings on the Debian systemdebian allows you to create as many configurations as possible in the system modules. in this article, tipsmake.com will describe how to configure mouse settings on a debian system.
- How to install and configure Samba on Debiansamba is a powerful open source tool that allows windows-like file and printer sharing on the network in linux systems.
- How to reset the password for sudo in Debianthe user password is changed in debian using the passwd command. in this article, tipsmake.com will explain how root users can change their own passwords on debian servers.
- How to upgrade from Debian 11 'Bullseye' to Debian 12 'Bookworm'if you are already using debian 11 bullseye, you can directly upgrade to debian 12 bookworm from the terminal.