$ php -v
// 例如:
dengzemiaodeMacBook-Pro:~ dengzemiao$ php -v
PHP 7.1.23 (cli) (built: Feb 22 2019 22:08:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
$ php -m
...
openssl
...
$ brew install composer
$ composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.0.9 2021-01-27 16:09:27
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
阿里云镜像源(推荐)
$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
$ composer config -g --unset repos.packagist
$ composer config repo.packagist composer https://mirrors.aliyun.com/composer/
$ composer config --unset repos.packagist
{
"require": {
"monolog/monolog": "1.2.*"
}
}
以上文件说明我们需要下载从1.2开始的任何版本的monolog。
$ composer install
$ composer remove monolog/monolog
$ composer require monolog/monolog
Composer会先找到合适的版本,然后更新composer.json文件,在require那添加monolog/monolog包的相关信息,再把相关的依赖下载下来进行安装,最后更新composer.lock文件并生成php的自动加载文件。
$ composer -v
$ composer create-project topthink/think test
$ composer search monolog
该命令会输出包及其描述信息,如果只想输出包名可以使用--only-name参数:
$ composer search --only-name monolog
// 列出所有已经安装的包
$ composer show
// 可以通过通配符进行筛选
$ composer show monolog/*
// 显示具体某个包的信息
$ composer show monolog/monolog
$ composer install
// 更新所有依赖
$ composer update
// 更新指定的包
$ composer update monolog/monolog
// 更新指定的多个包
$ composer update monolog/monolog symfony/dependency-injection
// 还可以通过通配符匹配包
$ composer update monolog/monolog symfony/*
$ composer selfupdate
$ composer diagnose
$ composer clear
$ composer update --lock
$ composer autoload-dump
// 可简写
$ composer dump