Installing Composer on Debian, Ubuntu, and Derivatives
Composer is a dependency manager for PHP that allows you to install and manage packages easily. Below are the steps to install Composer on Debian, Ubuntu, and derived distributions.
1. Update the system
Before installing Composer, it is recommended to update the system:
sudo apt updateCopied!
sudo apt upgradeCopied!
2. Install necessary dependencies
Composer requires PHP and some additional modules. Install them with:
sudo apt install php-cli php-zip php-curlCopied!
3. Download the Composer installer
Navigate to the user's home directory and download the installer:
cd ~Copied!
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.phpCopied!
4. Verify the installer's integrity
To ensure that the installer has not been altered, we obtain the official hash and compare it with the downloaded file:
HASH=`curl -sS https://composer.github.io/installer.sig`Copied!
Run the following command to obtain the hash:
echo $HASHCopied!
With the following PHP command, we verify the integrity of the installation script by matching the hash of the downloaded file with the obtained hash. If the output indicates "Installer verified," the file is safe, and we can proceed with the installation:
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('/tmp/composer-setup.php'); } echo PHP_EOL;"Copied!
5. Install Composer
Run the following command to install Composer in /usr/local/bin/ and make it globally accessible:
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composerCopied!
If the installation is successful, you will see a message similar to:
All settings correct for using Composer Downloading... Composer (version x.x.x) successfully installed to: /usr/local/bin/composer
6. Verify the installation
To check that Composer is installed correctly, run:
composerCopied!
Composer is an essential tool for PHP developers. By following these steps, you can easily install it on Debian, Ubuntu, and their derivatives. Now you are ready to manage dependencies and develop applications efficiently.