How to install Composer programmatically?#

As noted on the download page, the installer script contains a signature which changes when the installer code changes and as such it should not be relied upon long term.

An alternative is to use this script which only works with unix utils:


php -r "copy('', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")

    >&2 echo 'ERROR: Invalid installer signature'
    rm composer-setup.php
    exit 1

php composer-setup.php --quiet
rm composer-setup.php
exit $RESULT

The script will exit with 1 in case of failure, or 0 on success, and is quiet if no error occurs.

Alternatively if you want to rely on an exact copy of the installer you can fetch a specific version from github's history. The commit hash should be enough to give it uniqueness and authenticity as long as you can trust the GitHub servers. For example:

wget -O - -q | php -- --quiet

You may replace the commit hash by whatever the last commit hash is on

Found a typo? Something is wrong in this documentation? Just fork and edit it!