Debian 11安装Composer:超详细教程与快速入门指南
引言
在这份快速入门指南中,您将在Debian 11服务器上安装Composer。
请参考《在Debian 11 上安装和使用Composer的详细教程》,其中包含每个步骤的更详细解释。
先决条件
要按照本指南进行操作,您需要准备以下物品:
- 一台安装了Debian 11系统并配置了sudo非root用户的服务器。如需设置,您可以参考我们的《Debian 11初始服务器设置教程》。
步骤1 — 安装依赖
除了Debian 11系统可能已包含的依赖项之外,Composer还需要php-cli
来在命令行中执行PHP脚本,以及unzip
来解压缩压缩档案。
首先更新软件包管理器的缓存。
sudo apt update
接下来,安装依赖项。您需要使用curl
下载Composer,使用php-cli
进行安装和运行。php-mbstring
软件包是必需的,以提供本教程中所使用的库的函数。Composer使用git
下载项目依赖项,而unzip
用于解压缩压缩包。您可以使用以下命令安装所有内容:
sudo apt install curl php-cli php-mbstring git unzip
所有依赖项安装完成后,现在您可以安装Composer了。
步骤2 — 下载并安装Composer
确保您在您的主目录中,然后使用curl
获取Composer安装程序。
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
接下来,您将核实已下载的安装程序与Composer公钥/签名页面上的最新安装程序的SHA-384哈希值是否匹配。
使用curl
命令,获取最新的签名并将其存储在一个shell变量中。
HASH=$(curl -sS https://composer.github.io/installer.sig)
现在执行以下的PHP代码来验证安装脚本是否可以安全运行。
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
您将收到以下输出:
Installer verified
注意
下面的命令将下载并安装Composer作为一个系统范围的命令(您可以了解更多如何将Composer添加到您的PATH中的工作方式),命名为composer
,安装路径为/usr/local/bin
。
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
您会看到类似这样的输出结果:
All settings correct for using Composer
Downloading…
Composer (version 2.3.5) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
为了测试您的安装情况,请运行:
composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.3.5 2022-04-13 16:43:00
Usage:
command [options] [arguments]
Options:
-h, –help Display help for the given command. When no command is given display help for the list command
-q, –quiet Do not output any message
-V, –version Display this application version
–ansi|–no-ansi Force (or disable –no-ansi) ANSI output
-n, –no-interaction Do not ask any interactive question
–profile Display timing and memory usage information
–no-plugins Whether to disable plugins.
–no-scripts Skips the execution of all scripts defined in composer.json file.
-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
…
这表明Composer已成功安装在您的系统上,并且可以在整个系统中使用。
结论
以下是与本教程相关的更详细指南的链接。
在本教程中,您可以迅速在Debian 11服务器上安装Composer。您可以在我们的《如何在Debian 11上安装和使用Composer》教程中找到更详细的说明。