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包
相关推荐
郝学胜-神的一滴5 小时前
Python 高级编程 026:内置数据结构之骈文纵论
开发语言·数据结构·python·程序人生·软件工程
隐积13 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
名字还没想好☜15 小时前
Next.js ‘use client‘ 到底加在哪:Server/Client Components 边界与常见报错
开发语言·前端·javascript·react·next.js
初级代码游戏16 小时前
iOS开发 Swift 速记1:变量和基本数据类型
开发语言·ios·swift
凡尘——雨落凡尘17 小时前
PHP 线上十大隐形故障复盘:90% 的网站卡顿、502、雪崩,都是这些细节导致的
redis·nginx·php·session
酷在前行17 小时前
【R生态】PERMANOVA 进阶实战:距离选择、PERMDISP、两两比较与受限置换(保姆级教程)
开发语言·r语言
cxr82817 小时前
Graphify vs GitNexus vs CodeGraph — 三工具架构深度对比
开发语言·架构·知识图谱
废弃的小码农19 小时前
功能测试--Day07--Python编程基础
开发语言·python
fengci.19 小时前
Microweber CMS 未授权路径穿越漏洞(CVE-2026-65694)
android·开发语言·前端·学习·php
程序员zgh19 小时前
C++ 拷贝赋值运算符 详解
c语言·开发语言·c++