一、在做谷歌SEO api提交的时候,计划使用php来做
-
在php中安装相应的依赖包,composer require google/apiclient:^2.12.1
-
在安装的时候报错,一共是两个
`①$ composer require google/apiclient:^2.12.1
./composer.json has been updated Running composer update google/apiclient Loading composer repositories with package information Info from repo.packagist.org: #StandWithUkraine Updating dependencies Your requirements could not be resolved to an installable set of packages.Problem 1
- Root composer.json requires mytoken/sdk 2.3.13, found mytoken/sdk[2.3.13] but the package is fixed to 2.3.12 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command. Problem 2
- google/apiclient v2.12.1 requires guzzlehttp/psr7 ^1.7||^2.0.0 -> found guzzlehttp/psr7[1.7.0, ..., 1.9.0, 2.0.0, ..., 2.4.0] but the package is fixed to 1.5.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- google/apiclient[v2.12.2, ..., v2.12.6] require guzzlehttp/psr7 ^1.8.4||^2.2.1 -> found guzzlehttp/psr7[1.8.4, 1.8.5, 1.9.0, 2.2.1, 2.2.2, 2.3.0, 2.4.0] but the package is fixed to 1.5.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- Root composer.json requires google/apiclient ^2.12.1 -> satisfiable by google/apiclient[v2.12.1, ..., v2.12.6].
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content. `
解决一:第一个错是composer.json 和 lock的版本对不上 需要更新成一样的才不会报错,直接只用命令composer require 包 进行更新 切记不要使用composer update 解决二、提示的是各种包之前的错误,需要解决的时候包依赖的关系,目前知道的方法就是减低版本就可以解决这个问题
解决完这两个问题 直接就可以装谷歌的依赖了
第二天在写接口的时候,提示
问题的原因:在装谷歌的依赖时,曾提示要让我更新composer的版本,所以我原来是1.x开头的,通过命令: composer selfupdate 更新成了2.x开头的了,然后2.x 他会检测你php的版本,结果发现不一直,所以报错了
Composer 使用 升级至2.0后增加了PHP版本检测,导致页面报错
问题的解决:
第一步先查看一下composer的版本信息
第二步将platform-check 改成false
第三部:从新加载一下:composer dump-autoload
然后问题就解决了。
扩展阅读:查看的这篇文章解决的问题: 原文链接:commandnotfound.cn/php/2/624/C…
Composer 禁用 platform-check 检查
项目部署的时候,升级等 composer dump-autoload 操作后会遇到:Your Composer dependencies require a PHP version >= 7.4.0。
用 composer check-platform-reqs 检查
composer check-platform-reqs Checking platform requirements for packages in the vendor dirext-ctype 7.4.7 successext-dom 20031129 successext-fileinfo 7.4.7 successext-gd 7.4.7 successext-iconv 7.4.7 successext-json 7.4.7 successext-libxml 7.4.7 successext-mbstring * success provided by symfony/polyfill-mbstringext-simplexml 7.4.7 successext-xml 7.4.7 successext-xmlreader 7.4.7 successext-xmlwriter 7.4.7 successext-zip 1.15.6 successext-zlib 7.4.7 successphp 7.4.7 success
composer 将依赖项更新到最新版本
composer.lock 文件会阻止您自动获取最新版本的依赖项。要更新到最新版本,请使用 update 命令。这将获取最新的匹配版本(根据 composer.json 文件)并使用新版本更新锁定文件。
php composer.phar update
注意: Composer 将在执行
install命令时显示警告,如果由于更改可能会影响依赖关系解析composer.lock而尚未更新composer.json
composer.json 禁用 platform-check
composer 默认 php-only 只检查 PHP 版本。设置为 true 也检查扩展的存在。如果设置为 false,Composer 将不会创建并需要 platform_check.php 文件作为自动加载程序引导程序的一部分。
"config": { "platform-check": false },
composer 单独项目配置:
composer config platform-check false
composer 全局配置:
composer global config platform-check false
指定 php 版本:
{ "require": { "phpoffice/phpspreadsheet": "^1.23" }, "config": { "platform": { "php": "7.3" } }}
之后,重新运行 composer dump-autoload。