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、安装成功