如何在 Debian 11 上安装 Composer [快速入门]

介绍

在本快速启动指南中,您将在 Debian 11 服务器上安装 Composer

有关本教程的更详细版本,以及每个步骤的更多解释,请参阅 如何在 Debian 11 上安装和使用 Composer

前提条件

要遵循这个指南,你将需要:

步骤 1 - 安装依赖

除了可能已经包含在您的 Debian 11 系统中的依赖之外,Composer 还需要php-cli来执行命令行中的 PHP 脚本,以及unzip来提取 zip 档案。

首先,更新包管理器的缓存:

1sudo apt update

接下来,安装依赖程序. 你需要弯曲来下载Composer和php-cli来安装和运行它. php-mbstring包是必要的,以提供您将在本教程中使用的库的功能。 git是由Composer用于下载项目依赖程序,而unzip是用于提取包。

1sudo apt install curl php-cli php-mbstring git unzip

有了所有依赖程序的安装,您现在可以安装 Composer。

步骤 2:下载和安装 Composer

请确保您位于您的主目录中,然后使用curl获取 Composer installer:

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

接下来,您将检查下载的安装程序是否匹配在 Composer Public Keys / Signatures页面上找到的最新安装程序的 SHA-384 哈希。

使用弯曲,获取最新的签名并将其存储在壳变量中:

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

现在执行以下PHP代码来验证安装脚本是安全的运行:

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

您将收到以下输出:

1[label Output]
2Installer verified

<$>[注] :如果输出说安装程序破坏,你应该重复下载和验证过程,直到你有一个经过验证的安装程序。这就是为什么检查总数如此有用。如果你的文件副本有任何变化,你可以通过将检查总数与原始进行比较来快速地知道。

以下命令将下载并安装 Composer 作为一个 [系统范围内的命令](您可以了解更多有关如何将 Composer 添加到您的 PATH 工作)名为 composer,在 /usr/local/bin下:

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

你会看到类似于此的输出:

1[secondary_label Output]
2All settings correct for using Composer
3Downloading...
4
5Composer (version 2.3.5) successfully installed to: /usr/local/bin/composer
6Use it: php /usr/local/bin/composer

要测试您的安装,运行:

1composer
 1[secondary_label Output]
 2   ______
 3  / ____/___ ____ ___ ____ ____ ________ _____
 4 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
 5/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
 6\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
 7                    /_/
 8Composer version 2.3.5 2022-04-13 16:43:00
 9
10Usage:
11  command [options] [arguments]
12
13Options:
14  -h, --help Display help for the given command. When no command is given display help for the list command
15  -q, --quiet Do not output any message
16  -V, --version Display this application version
17      --ansi|--no-ansi Force (or disable --no-ansi) ANSI output
18  -n, --no-interaction Do not ask any interactive question
19      --profile Display timing and memory usage information
20      --no-plugins Whether to disable plugins.
21      --no-scripts Skips the execution of all scripts defined in composer.json file.
22  -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
23      --no-cache Prevent use of the cache
24  -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
25...

这验证了 Composer 已成功安装在您的系统上,并且在整个系统中可用。

结论

以下是有关本教程的更多详细指南的链接:

在本教程中,您可以在您的 Debian 11 服务器上快速安装 Composer. 您可以在我们的 如何在 Debian 11 上安装和使用 Composer 教程中找到这个过程的更详细的解释。

Published At
Categories with 技术
comments powered by Disqus