Linux和Windows安装PHP依赖管理工具Composer

Composer 是 PHP 的一个依赖管理工具。它允许申明项目所依赖的代码库,会在项目中安装它们。 Composer 不是一个包管理器。是的,它涉及 "packages" 和 "libraries",但它在每个项目的基础上进行管理,在你项目的某个目录中(例如 vendor)进行安装。默认情况下它不会在全局安装任何东西。因此,这仅仅是一个依赖管理。Composer 受到了 node's npm 和 ruby's bundler 的强烈启发。Composer 可以解决一下问题:

a) 你有一个项目依赖于若干个库。

b) 其中一些库依赖于其他库。

c) 你声明你所依赖的东西。

d) Composer 会找出哪个版本的包需要安装,并安装它们(将它们下载到你的项目中)。

Composer的中文网站:

Composer中文网 / Packagist中国全量镜像

Linux系统使用以下命令安装

bash 复制代码
curl -sS https://getcomposer.org/installer | php

如果安装失败也可以使用以下PHP命令安装

bash 复制代码
php -r "readfile('https://getcomposer.org/installer');" | php

显示以下信息表示安装成功,已经下载了 Composer的2.7.2 版本,并将其保存为了一个 PHAR 文件(PHP 归档文件)。

bash 复制代码
[root@GGboy ~]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 2.7.2) successfully installed to: /root/composer.phar
Use it: php composer.phar

安装完成后输入命令查看是否安装成功

bash 复制代码
php composer.phar
bash 复制代码
[root@GGboy ~]# php composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.7.2 2024-03-11 17:12:18

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

Windows系统安装Composer

需要在浏览器地址搜索栏中输入 **https://getcomposer.org/Composer-Setup.exe**下载Composer的.exe安装文件

安装完成后在cmd命令窗口输入以下命令即可查看是否安装成功

bash 复制代码
composer

完成安装后即可输入命令将需要的包添加到程序中

bash 复制代码
php composer.phar require swiftmailer/swiftmailer // 安装swiftmailer包
相关推荐
睡美人的小仙女1273 小时前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
rayufo4 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk4 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
缺点内向5 小时前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net
一起养小猫5 小时前
Flutter for OpenHarmony 实战:记账应用数据统计与可视化
开发语言·jvm·数据库·flutter·信息可视化·harmonyos
zhougl9965 小时前
Java 所有关键字及规范分类
java·开发语言
java1234_小锋5 小时前
Java高频面试题:MyISAM索引与InnoDB索引的区别?
java·开发语言
2501_944525545 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
qq_417129256 小时前
C++中的桥接模式变体
开发语言·c++·算法
开源技术6 小时前
如何将本地LLM模型与Ollama和Python集成
开发语言·python