如何在 Debian 11 上安装 PHP Composer
Composer 是 PHP 编程的项目依赖管理器。Composer 提供了一种标准格式,用于通过下载项目所需的所有 PHP 包并为您管理它们来管理 PHP 软件的所有依赖项和所需的库。大多数现代 PHP 框架都使用它,例如Laravel、Drupal、Magento 和 Symfony。
在 Debian 11 Bullseye 上安装 PHP Composer
步骤 1. 在我们安装任何软件之前,通过apt在终端中运行以下命令来确保您的系统是最新的很重要:
sudo apt update sudo apt upgrade sudo apt install curl wget php-common php-cli php-gd php-mysql php-curl php-intl php-mbstring php-bcmath php-imap php-xml php-zip git unzip
步骤 2. 在 Debian 11 上安装 PHP Composer。
现在我们在 Debian 系统上安装 Composer,你必须运行这个命令:
wget -O composer-setup.php https://getcomposer.org/installer
通过运行以下命令在目录中全局安装 Composer :/usr/local/bin
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
验证安装的版本:
composer --version
然后,使用以下命令测试您的 Composer 安装:
composer
输出:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
/_/
Composer version 2.1.8 2021-09-18 14:22:11
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
步骤 3. 使用 PHP Composer。
首先,创建您的 Composer 项目目录:
mkdir ~/my-composer-project cd ~/my-composer-project
接下来,运行以下命令来初始化一个新的 composer.json 文件并安装 carbon 包:
composer require nesbot/carbon
安装完成后,您可以看到 Composer 创建了两个文件和一个目录:composer.jsoncomposer.lockvendor
ls -l
输出:
root@idroot.us:~/my-composer-project# ls -l total 28 -rw-r--r-- 1 root root 60 Sep 6 08:21 composer.json -rw-r--r-- 1 root root 18210 Sep 6 08:21 composer.lock drwxr-xr-x 6 root root 4096 Sep 6 08:21 vendor
之后,现在创建一个名为的新文件并粘贴以下文件:testing.php