composer常用命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了composer常用命令相关的知识,希望对你有一定的参考价值。

参考技术A 1、composer list:获取帮助信息;

2、composer init:以交互方式填写composer.json文件信息;

3、composer install:从当前目录读取composer.json文件,处理依赖关系,并安装到vendor目录下;

4、composer update:获取依赖的最新版本,升级composer.lock文件;

5、composer require:添加新的依赖包到composer.json文件中并执行更新;

6、composer search:在当前项目中搜索依赖包;

7、composer show:列举所有可用的资源包;

8、composer validate:检测composer.json文件是否有效;

9、composer self-update:将composer工具更新到最新版本;

10、composer create-project:基于composer创建一个新的项目;

11、composer dump-autoload:在添加新的类和目录映射是更新autoloader

php composer 常用命令

composer 常用命令

注意在工程目录下面执行(composer.json 所在的文件夹)

1、查看composer配置

composer config -l

composer config -l
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [https, ssh]
[vendor-dir] ../LieBitComposer (/huayong/app/php/liebite/../LieBitComposer)
[bin-dir] {$vendor-dir}/bin (/huayong/app/php/liebite/../LieBitComposer/bin)
[cache-dir] /home/yw/.cache/composer
[data-dir] /home/yw/.local/share/composer
[cache-files-dir] {$cache-dir}/files (/home/yw/.cache/composer/files)
[cache-repo-dir] {$cache-dir}/repo (/home/yw/.cache/composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/home/yw/.cache/composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] false
[prepend-autoloader] true
[github-domains] [github.com]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] true
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [gitlab.com]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[htaccess-protect] 1
[home] /home/yw/.config/composer

2、修改为阿里云的源

composer config repo.packagist composer https://mirrors.aliyun.com/composer/
composer config repo.packagist composer https://packagist.phpcomposer.com

取消配置:

composer config -g --unset repos.packagist

项目配置
仅修改当前工程配置,仅当前工程可使用该镜像地址:

composer config repo.packagist composer https://mirrors.aliyun.com/composer/

取消配置:

composer config --unset repos.packagist

3、执行安装命令

composer require phpoffice/phpspreadsheet 1.15

composer require phpoffice/phpspreadsheet
指定命令运行的用户
 sudo -u nginx bash -c ‘/usr/local/bin/composer require phpoffice/phpspreadsheet‘  

4、composer安装

下载composer.phar文件

官网下载
https://getcomposer.org/download/1.8.0/composer.phar

sudo mv composer.phar /usr/local/bin/composer
chmod a+x /usr/local/bin/composer
参考

5、保持最新版

更新composer

经常执行 composer selfupdate 以保持 Composer 一直是最新版本

6、调试

composer 命令增加 -vvv 可输出详细的信息,命令如下:

composer -vvv require alibabacloud/sdk

7、安装成功

技术图片

以上是关于composer常用命令的主要内容,如果未能解决你的问题,请参考以下文章

php composer 常用命令

docker compose 常用命令

Docker-compose常用命令

常用的 composer 命令

docker-compose 常用命令参数解释

composer常用命令(部分摘抄)