2017-05-18 19:15:27 +00:00
|
|
|
# How do I install Composer programmatically?
|
2016-06-28 10:41:34 +00:00
|
|
|
|
|
|
|
As noted on the download page, the installer script contains a
|
2020-02-11 08:11:45 +00:00
|
|
|
checksum which changes when the installer code changes and as such
|
2018-04-24 15:45:51 +00:00
|
|
|
it should not be relied upon in the long term.
|
2016-06-28 10:41:34 +00:00
|
|
|
|
2018-04-24 15:45:51 +00:00
|
|
|
An alternative is to use this script which only works with UNIX utilities:
|
2016-06-28 10:41:34 +00:00
|
|
|
|
2022-08-20 10:23:00 +00:00
|
|
|
```shell
|
2016-06-28 10:41:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-01-21 13:33:49 +00:00
|
|
|
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
|
2016-06-28 10:41:34 +00:00
|
|
|
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
2020-02-11 08:11:45 +00:00
|
|
|
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
|
2016-06-28 10:41:34 +00:00
|
|
|
|
2020-02-11 08:11:45 +00:00
|
|
|
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
|
2016-06-28 10:41:34 +00:00
|
|
|
then
|
2020-02-11 08:11:45 +00:00
|
|
|
>&2 echo 'ERROR: Invalid installer checksum'
|
2016-06-28 10:41:34 +00:00
|
|
|
rm composer-setup.php
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-11-04 22:25:21 +00:00
|
|
|
|
|
|
|
php composer-setup.php --quiet
|
|
|
|
RESULT=$?
|
|
|
|
rm composer-setup.php
|
|
|
|
exit $RESULT
|
2016-06-28 10:41:34 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The script will exit with 1 in case of failure, or 0 on success, and is quiet
|
|
|
|
if no error occurs.
|
2016-06-28 15:35:32 +00:00
|
|
|
|
2018-04-24 15:45:51 +00:00
|
|
|
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
|
2016-06-28 15:35:32 +00:00
|
|
|
give it uniqueness and authenticity as long as you can trust the GitHub servers.
|
|
|
|
For example:
|
|
|
|
|
2022-08-20 10:23:00 +00:00
|
|
|
```shell
|
2019-01-29 18:03:03 +00:00
|
|
|
wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet
|
2016-06-28 15:35:32 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
You may replace the commit hash by whatever the last commit hash is on
|
2021-10-17 11:51:25 +00:00
|
|
|
https://github.com/composer/getcomposer.org/commits/main
|