composer使用记录
centos 7 下安装composer
[root@VM_0_8_centos ~]# curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading... Composer (version 1.8.6) successfully installed to: /root/composer.phar Use it: php composer.phar |
mv composer.phar /usr/local/bin/composer |
注意: 如果上诉命令因为权限执行失败, 请使用 sudo 再次尝试运行 mv 那行命令。
现在只需要运行 composer 命令就可以使用 Composer 而不需要输入 php composer.phar。
composer的install和require和update指令的区别
注意:对于 require 和 install 是不相同的,require 会把包的信息添加到 composer.json 文件中并进行 install 。而 install 是直接从 composer.json 或 composer.lock 文件中提取依赖信息,然后进行安装。
安装composer时出现 Failed to decode zlib stream 这个错误
打开这个目录里的php.ini文件,修改zlib.output_compression = Off 修改为 On
查看composer全局配置
C:\Users\Dell>composer config -gl [repositories.packagist.org.type] composer [repositories.packagist.org.url] https://packagist.phpcomposer.com [process-timeout] 300 [use-include-path] false [preferred-install] auto [notify-on-install] true [github-protocols] [https, ssh] [vendor-dir] vendor (C:\Users\Dell/vendor) [bin-dir] {$vendor-dir}/bin (C:\Users\Dell/vendor/bin) [cache-dir] C:/Users/Dell/AppData/Local/Composer [data-dir] C:/Users/Dell/AppData/Roaming/Composer [cache-files-dir] {$cache-dir}/files (C:/Users/Dell/AppData/Local/Composer/files) [cache-repo-dir] {$cache-dir}/repo (C:/Users/Dell/AppData/Local/Composer/repo) [cache-vcs-dir] {$cache-dir}/vcs (C:/Users/Dell/AppData/Local/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] C:/Users/Dell/AppData/Roaming/Composer |
修改设置镜像地址,加速安装
①composer config -g repo.packagist composer https://packagist.phpcomposer.com ①composer config -g repo.packagist composer https://packagist.laravel-china.org |
composer软件更新到最新的版本
composer self-update |
composer回滚到上次安装的版本
composer self-update --rollback |
安装指定版本的composer
composer self-update 2.0.10 |
composer require topthink/think-queue v2.0.4
要求
topthink/think-helper: >=1.0.4 topthink/think-installer: ^2.0 topthink/framework: 5.1.* |
当前版本 “topthink/framework”: “~5.0.24”,所以安装时,会报错.
安装指定版本的扩展包
composer require package $version composer require topthink/think-queue v1.1.6 |
创建一个thinkphp项目并且指定路径
composer create-project topthink/think $path composer create-project topthink/think v5.1.36 |
执行命令composer require topthink/think-queue v2.0.4如下:
D:\phpStudy1\WWW\tp5.1.36\v5.1.36>composer require topthink/think-queue v2.0.4
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
– Installing topthink/think-helper (v3.0.0): Loading from cache
– Installing topthink/think-queue (v2.0.4): Loading from cache
Writing lock file
Generating autoload files
执行命令后会在D:\phpStudy1\WWW\tp5.1.36\v5.1.36\vendor\topthink\think-queue创建think-queue扩展包.
阿里云镜像
全局使用
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# 取消全局配置
composer config -g –unset repos.packagist
报错:
Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info
[root@iZm5ee1mp8u5k7ze0hbzzjZ attr.wuxinzhe.top]# composer self-update
Updating to version 2.0.6 (stable channel).
Downloading (100%)
Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info
解决方案:
换http源,更改配置不要使用https加密连接
composer config -g repo.packagist composer http://packagist.phpcomposer.com composer config -g secure-http false |
composer require安装报错 No driver found to handle VCS repository
解决方案 将版本切换到 2.0.10 安装依赖包成功
The “topthink/think-installer” plugin was skipped because it requires a Plugin API version (“^1.0”) that does not match your Composer installation (“2.0.0”). You may need to run composer update with the “–no-plugins” option.
解决方案 回滚到composer版本1,只需执行以下命令:
composer self-update –1
当您想回到版本2时(在更新或删除不兼容的插件之后,您应该这样做):
composer self-update –2
指定php版本安装包
[fengguowuhen@iZm5ee1mp8u5k7ze0hbzzjZ wechatpayservice]$ /www/server/php/73/bin/php /usr/bin/composer require wechatpay/wechatpay
Using version ^1.4 for wechatpay/wechatpay
./composer.json has been updated
Running composer update wechatpay/wechatpay
Loading composer repositories with package information Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
– Root composer.json requires phpoffice/phpspreadsheet 1.12 -> satisfiable by phpoffice/phpspreadsheet[1.12.0].
– phpoffice/phpspreadsheet 1.12.0 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP’s fileinfo extension.
Problem 2
– Root composer.json requires overtrue/wechat 4.2.11 -> satisfiable by overtrue/wechat[4.2.11].
– overtrue/wechat 4.2.11 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP’s fileinfo extension.
需要安装php fileinfo 扩展
composer本地安装后上传not found
composer update xxx(包名) |
composer install过程中卡在了Loading composer repositories with package information
[root@iZbp1g7hke7h03txh5cupaZ hedaozongdu.wanhedashuju.com]# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 设置镜像 [root@iZbp1g7hke7h03txh5cupaZ hedaozongdu.wanhedashuju.com]# composer install #重新安装 |
* composer install安装包时报错 Root composer.json requires topthink/think-installer, it could not be found in any version, there may be a typo in the package name
[root@iZbp17mt6vfi6lugx4hl53Z localstore.wanhedashuju.com]# composer install No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information. Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires topthink/think-installer, it could not be found in any version, there may be a typo in the package name. Problem 2 - Root composer.json requires topthink/think-queue, it could not be found in any version, there may be a typo in the package name. Problem 3 - Root composer.json requires topthink/think-helper, it could not be found in any version, there may be a typo in the package name. Problem 4 - Root composer.json requires karsonzhang/fastadmin-addons, it could not be found in any version, there may be a typo in the package name. Problem 5 - Root composer.json requires overtrue/pinyin, it could not be found in any version, there may be a typo in the package name. Problem 6 - Root composer.json requires phpoffice/phpspreadsheet, it could not be found in any version, there may be a typo in the package name. Problem 7 - Root composer.json requires overtrue/wechat, it could not be found in any version, there may be a typo in the package name. Problem 8 - Root composer.json requires txthinking/mailer, it could not be found in any version, there may be a typo in the package name. Problem 9 - Root composer.json requires topthink/framework dev-master -> satisfiable by topthink/framework[dev-master]. - topthink/framework dev-master requires topthink/think-installer ~1.0 -> could not be found in any version, there may be a typo in the package name. Problem 10 - Root composer.json requires topthink/think-captcha ^1.0.9 -> satisfiable by topthink/think-captcha[v1.0.9]. - topthink/think-captcha v1.0.9 requires topthink/think-installer >=1.0.10 -> could not be found in any version, there may be a typo in the package name. Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details. - It's a private package and you forgot to add a custom repository to find it |
composer版本2.0.14 重新设置镜像网站后解决了
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ |
使用报错 it could not be found in any version, there may be a typo in the package name,修改下镜像源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ |