Run the command below to download PHP composer installer script:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
To confirm that you are installing the actual composer, you need to verify the integrity of the installer script downloaded above. This can be done by downloading the hash and comparing and validating as follows:
php -r "if (hash_file('sha384', 'composer-setup.php') === '$(wget -qO - https://composer.github.io/installer.sig)') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
You should see an output like:
Installer verified
php composer-setup.php --install-dir=/usr/bin --filename=composer
If you see this error:
All settings correct for using Composer
The installation directory "/usr/bin" is not writable
Then try to execute again with sudo:
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
Remove the installer once Composer is installed:
php -r "unlink('composer-setup.php');"
composer -v
You will see something like this:
Great job!