Playbook
Install Composer
The current stable Composer from getcomposer.org, checksum-verified.
Category
Runtimes
Time limit per server
10 minutes
Temporary failures
Retried automatically, up to 2 times
Version
1.0
Supported systems
Ubuntu 22.04+, Debian 12+, RHEL-compatible 8+ (AlmaLinux, Rocky Linux, RHEL, CentOS Stream, Oracle Linux), Amazon Linux 2023+. Still runs on Ubuntu 20.04 and Debian 11, which are past the end of standard support.
When to use it
Before installing a PHP application's dependencies with composer install. Run Install PHP first: Composer needs a php command.
This playbook has no options.
What it does on the server
- Checks that a
phpcommand exists. - Installs
unzip, which Composer uses to unpack packages quickly. - Downloads the current stable
composer.pharfrom getcomposer.org and checks it against the SHA-256 checksum published beside it. A mismatch stops the run before anything is installed. - Confirms the download runs with the server's PHP, then installs it at
/usr/local/bin/composer.
A Composer already installed at /usr/local/bin/composer keeps its version. Update it later with composer self-update.
After the run
In your application's directory, run composer install --no-dev --optimize-autoloader as the account that owns the code, not as root.
Common problems
"Composer needs PHP, and there is no php command on this server." — Run Install PHP first. If PHP is installed but php is not on the PATH, run Install PHP again with Make this the version php runs on.
"The downloaded Composer does not run with this server's PHP" — The server's default PHP is older than the current Composer supports. Install a newer PHP and make it the version php runs.
"The Composer download did not match the checksum getcomposer.org publishes for it." — The download was corrupted or altered. Nothing was installed; run the playbook again.