Composer 安装、换源及测试
写作时间:2022-04-13 作者:田辛
文章目录
1 下载Composer
官方地址: Composer (getcomposer.org))
点击“Download”
2 安装步骤
2.1 为所有用户安装还是仅为自己安装
2.2 不安装开发模式
2.3 指定PHP版本
我这里用的7.4.3,之前用的7.3.4在下一步总是报错
2.4 设置代理服务器
不设置
2.5 确认要做的事情
PHP命令版本
不安装任何代理设置
增加php7.4.3的全局变量
删除php7.3.4的全局变量(本地情况,如果是干净系统应该没有这个内容)
2.6 安装中
2.7 提示页面
命令行窗口(cmd)等只有重新打开才会加载新的path系统设置
2.8 完成页面
3 测试成果
4 检查并加速
4.1 查看现有的Composer设定
C:\Users\mike_>composer config -gl
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
[process-timeout] 300
[use-include-path] false
[allow-plugins]
[use-parent-dir] prompt
[preferred-install] dist
[notify-on-install] true
[github-protocols] [https, ssh]
[gitlab-protocol]
[vendor-dir] vendor (C:\Users\mike_/vendor)
[bin-dir] {$vendor-dir}/bin (C:\Users\mike_/vendor/bin)
[cache-dir] C:/Users/mike_/AppData/Local/Composer
[data-dir] C:/Users/mike_/AppData/Roaming/Composer
[cache-files-dir] {$cache-dir}/files (C:/Users/mike_/AppData/Local/Composer/files)
[cache-repo-dir] {$cache-dir}/repo (C:/Users/mike_/AppData/Local/Composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (C:/Users/mike_/AppData/Local/Composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[cache-read-only] false
[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] true
[use-github-api] true
[lock] true
[platform-check] php-only
[home] C:/Users/mike_/AppData/Roaming/Composer
C:\Users\mike_>
C:\Users\mike_>
根据上边执行块第3行,目前的Composer源已经是国内的阿里云了。 可以不修改。 如果安装的时候,不是阿里云/腾讯云的仓库地址,可以通过如下命令执行:
阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
腾讯云
composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
4.2 升级到最新版本
C:\Users\mike_>composer self-update
You are already using the latest available Composer version 2.3.4 (stable channel).
C:\Users\mike_>
4.3 清除缓存
C:\Users\mike_>composer clear
Clearing cache (cache-vcs-dir): C:\Users\mike_\AppData\Local\Composer\vcs
Clearing cache (cache-repo-dir): C:\Users\mike_\AppData\Local\Composer\repo
Clearing cache (cache-files-dir): C:\Users\mike_\AppData\Local\Composer\files
Clearing cache (cache-dir): C:\Users\mike_\AppData\Local\Composer
All caches cleared.
C:\Users\mike_>
4.4 安装源管理器
C:\Users\mike_>composer global require slince/composer-registry-manager
Changed current directory to C:/Users/mike_/AppData/Roaming/Composer
Using version ^2.3 for slince/composer-registry-manager
./composer.json has been created
Running composer update slince/composer-registry-manager
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking slince/composer-registry-manager (2.3.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading slince/composer-registry-manager (2.3.1)
- Installing slince/composer-registry-manager (2.3.1): Extracting archive
slince/composer-registry-manager contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "slince/composer-registry-manager" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
C:\Users\mike_>
5 安装ThinkPHP5.0框架测试
5.1 命令
composer create-project topthink/think=5.0.* 04-tp50.thinkphp.co.jp --prefer-dist
5.2 执行
D:\S10-PHPStudy>composer create-project topthink/think=5.0.* 04-tp50.thinkphp.co.jp --prefer-dist
Creating a "topthink/think=5.0.*" project at "./04-tp50.thinkphp.co.jp"
Installing topthink/think (v5.0.24)
- Installing topthink/think (v5.0.24): Extracting archive
Created project in D:\S10-PHPStudy\04-tp50.thinkphp.co.jp
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
- Locking topthink/framework (v5.0.24)
- Locking topthink/think-installer (v1.0.14)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing topthink/think-installer (v1.0.14): Extracting archive
topthink/think-installer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "topthink/think-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
- Installing topthink/framework (v5.0.24): Extracting archive
Generating autoload files
D:\S10-PHPStudy>cd 04*
D:\S10-PHPStudy\04-tp50.thinkphp.co.jp>dir
驱动器 D 中的卷是 Data
卷的序列号是 5A84-487D
D:\S10-PHPStudy\04-tp50.thinkphp.co.jp 的目录
2022/04/13 11:31 <DIR> .
2022/04/13 11:31 <DIR> ..
2019/01/11 16:11 35 .gitignore
2019/01/11 16:11 2,038 .travis.yml
2019/01/11 16:11 <DIR> application
2019/01/11 16:11 1,099 build.php
2019/01/11 16:11 48,648 CHANGELOG.md
2022/04/13 11:31 743 composer.json
2022/04/13 11:31 4,703 composer.lock
2019/01/11 16:11 <DIR> extend
2019/01/11 16:11 1,822 LICENSE.txt
2019/01/11 16:11 <DIR> public
2019/01/11 16:11 5,779 README.md
2019/01/11 16:11 <DIR> runtime
2019/01/11 16:11 753 think
2022/04/13 11:31 <DIR> thinkphp
2022/04/13 11:31 <DIR> vendor
9 个文件 65,620 字节
8 个目录 269,341,859,840 可用字节
D:\S10-PHPStudy\04-tp50.thinkphp.co.jp>
6 未解决事项
- [[Composer多线程扩展]]未安装成功。
composer glob