Tutorial

Installieren von Composer unter Ubuntu 20.04 [Schnellstart]

Published on June 11, 2020
Default avatar

By Erika Heidi

Developer Advocate

Deutsch
Installieren von Composer unter Ubuntu 20.04 [Schnellstart]

Einführung

In diesem Schnellstartleitfaden installieren wir Composer auf einem Ubuntu 20.04-Server.

Eine ausführlichere Version dieses Tutorials mit genaueren Erklärungen zu den einzelnen Schritten finden Sie unter Installieren und Verwenden von Composer unter Ubuntu 20.04.

Voraussetzungen

Um diesem Leitfaden zu folgen, müssen Sie auf einen Ubunto 20.04-Server als sudo-Benutzer zugreifen.

Schritt 1 — Installieren von Abhängigkeiten

Aktualisieren Sie den Cache Ihres Paketmanagers und installieren Sie die erforderlichen Abhängigkeiten, einschließlich php-cli:

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

Schritt 2 — Herunterladen und Installieren von Composer

Stellen Sie sicher, dass Sie sich in Ihrem Startverzeichnis befinden, und rufen Sie das Composer Installationsprogramm mit curl auf:

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

Als nächstes überprüfen wir, ob das heruntergeladene Installationsprogramm mit dem SHA-384-Hash für das neueste Installationsprogramm übereinstimmt, das auf der Seite Öffentliche Schlüssel/Signaturen von Composer zu finden ist.

Mithilfe von curl können Sie die neueste Signatur abrufen und sie in einer Shell-Variable speichern:

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

Führen Sie nun den folgenden PHP-Code aus, um zu überprüfen, ob das Installationsskript sicher ausgeführt werden kann:

  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;"

Sie sehen die folgende Ausgabe:

Output
Installer verified

Anmerkung: Wenn die Ausgabe Installer corrupt meldet, müssen Sie den Download- und Verifizierungsprozess wiederholen, bis Sie ein verifiziertes Installationsprogramm haben.

Über folgenden Befehl wird Composer als systemweiter Befehl namens composer unter /usr/local/bin heruntergeladen und installiert:

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

Sie sehen eine Ausgabe, die dieser ähnelt:

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

Um Ihre Installation zu testen, führen Sie Folgendes aus:

  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 ...

Damit wird überprüft, dass Composer erfolgreich auf Ihrem System installiert und systemweit verfügbar ist.

Relevante Tutorials

Hier sehen Sie Links zu detaillierteren Leitfäden, die in Verbindung mit diesem Tutorial stehen:

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

Learn more about us


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!

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