How do I install Composer using a script?

藏色散人
Release: 2019-08-21 14:51:38
Original
2763 people have browsed it

The following column composer usage tutorial will explain how to use scripts to install Composer. I hope it will be helpful to friends in need!

How do I install Composer using a script?

How do we programmatically install Composer?

As noted on the download page, this installer contains a signature, It changes when the installer code changes and should not be relied upon long-term.

There is another way, which is to use a script that only works for UNIX utilities:

#!/bin/sh
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
    >&2 echo 'ERROR: Invalid installer signature'
    rm composer-setup.php
    exit 1
fi
php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
Copy after login

The script will exit and return 1 on failure, or 0 on success, if nothing is returned There is no error.

Alternatively, if you want to install using a copy of this installer, you can fetch a specific version from the GitHub history. If you trust the GitHub servers enough, committing the hash is enough to make it unique and authentic. For example:

wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet
Copy after login

You can submit a hash that replaces any content based on the last commit:

https://github.com/composer/getcomposer.or...

The above is the detailed content of How do I install Composer using a script?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template