介绍
在这个快速启动指南中,我们将安装 Composer在Ubuntu 20.04服务器上。
对于本教程的更详细版本,以及每个步骤的更多解释,请参阅 如何在Ubuntu 20.04上安装和使用作曲家。
前提条件
要遵循本指南,您需要作为sudo
用户访问 Ubuntu 20.04 服务器。
步骤 1 - 安装依赖性
首先,更新您的包管理器缓存并安装所需的依赖,包括php-cli
:
1sudo apt update
2sudo apt install php-cli unzip
步骤 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
的整个系统命令,在/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.2.9) 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.2.9 2022-03-15 22:13:37
9
10Usage:
11 command [options] [arguments]
12
13Options:
14 -h, --help Display this help message
15 -q, --quiet Do not output any message
16 -V, --version Display this application version
17 --ansi Force ANSI output
18 --no-ansi Disable ANSI output
19 -n, --no-interaction Do not ask any interactive question
20 --profile Display timing and memory usage information
21 --no-plugins Whether to disable plugins.
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 已成功安装在您的系统上,并且在整个系统中可用。
相关教程
以下是有关本教程的更多详细指南的链接:
- Initial Server Setup on Ubuntu 20.04
- How To Install and Use Composer on Ubuntu 20.04
- How To Install Linux, Nginx, MySQL, PHP (LEMP Stack) on Ubuntu 20.04
- How To Install Linux, Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04
https://andsky.com/tech/tutorials/如何安装-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04)