Tutorial

Comment installer Composer sur Ubuntu 20.04 [Démarrage rapide]

Published on June 11, 2020

Developer Advocate

Français
Comment installer Composer sur Ubuntu 20.04 [Démarrage rapide]

Introduction

Dans ce guide de démarrage rapide, nous allons installer Composer sur un serveur Ubuntu 20.04.

Pour obtenir une version plus détaillée de ce tutoriel, avec plus d’explications sur chaque étape, veuillez vous référer à Comment installer et utiliser Composer sur Ubuntu 20.04.

Conditions préalables

Pour suivre ce guide, vous devrez avoir accès à un serveur Ubuntu 20.04 en tant qu’utilisateur sudo.

Étape 1 — Installer les dépendances

Commencez par mettre à jour le cache de votre gestionnaire de paquets et installez les dépendances nécessaires, y compris php-cli

  1. sudo apt update
  2. sudo apt install php-cli unzip

Étape 2 — Téléchargement et installation de Composer

Assurez-vous que vous êtes dans votre répertoire d’origine, puis récupérez l’installateur de Composer en utilisant curl :

  1. cd ~
  2. curl -sS https://getcomposer.org/installer -o composer-setup.php

Ensuite, nous allons vérifier que l’installateur téléchargé correspond au hachage SHA-384 pour le dernier installateur trouvé sur la page des clés publiques/signatures de Composer.

À l’aide de curl, récupérez la dernière signature et stockez-la dans une variable shell :

  1. HASH=`curl -sS https://composer.github.io/installer.sig`

Exécutez maintenant le code PHP suivant pour vérifier que le script d’installation peut être exécuté en toute sécurité :

  1. php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Vous verrez la sortie suivante :

Output
Installer verified

Remarque : Si la sortie indique Installer corrupt, vous devrez répéter le processus de téléchargement et de vérification jusqu’à ce que vous ayez un installateur vérifié.

La commande suivante va télécharger et installer Composer en tant que commande système nommée composer, sous /usr/local/bin :

  1. sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Vous verrez une sortie semblable à celle-ci :

Output
All settings correct for using Composer Downloading... Composer (version 1.10.5) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Pour tester votre installation, exécutez :

  1. composer
Output
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.10.5 2020-04-10 11:44:22 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. --no-cache Prevent use of the cache -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug ...

Cela permet de vérifier que Composer a été installé avec succès sur votre système et qu’il est disponible dans tout le système.

Tutoriels connexes

Voici des liens vers des guides plus détaillés relatifs à ce tutoriel :

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel