composer install php 安装依赖包的命令

composer 是基于项目进行管理的,进行依赖安装的时候。要设置好一个配置文件。 composer.json 通过这个配置文件compsoser 就知道需要安装什么。

比如需要安装一个日志工具

# Author: www.phpjiaocheng.com

cat composer.json
{
"require" : {
"monolog/monolog": "1.*"
}

看到的安装信息

composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing psr/log (1.1.3): Downloading (100%)
- Installing monolog/monolog (1.25.5): Downloading (100%)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)
monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing sentry/sentry (Allow sending log messages to a Sentry server)
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!

如果想查看详细的安装信息,可以通过 composer install -vvv

 

安装的过程都发生了什么

首先查看一个当前的目录多了什么文件

[phpjiaocheng.com@localhost test]$ tree -L 1
.
├── composer.json
├── composer.lock
└── vendor

多了一个文件 vender , 一个文件 composer.lock 。 其中vender是用来存放下载的包和依赖的。 通过composer下载的文件都存储在里面。

composer.lock 则是锁定文件。就是里面有一些确定的信息。 具体可以查看  composer.lock的作用是什么 

另外下的文件还会进行缓存。可能的目录是 ~/.cache/composer/files/

 

 

 

留言

您的电子邮箱地址不会被公开。 必填项已用 * 标注