【PHP】检查和启用PHP扩展(ext-fileinfo、ext-gd版)
总结来说
当发生composer install错误时的解决方法备忘录
(原因是未启用PHP扩展模块)
在执行composer install时出错
因为要加入其他项目,所以按照惯例从克隆进行composer的安装。
然后出现了错误。
>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for league/flysystem 1.0.47 -> satisfiable by league/flysystem[1.0.47].
- league/flysystem 1.0.47 requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
Problem 2
- Installation request for phpoffice/phpspreadsheet 1.4.1 -> satisfiable by phpoffice/phpspreadsheet[1.4.1].
- phpoffice/phpspreadsheet 1.4.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.
Problem 3
- league/flysystem 1.0.47 requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
- laravel/framework v5.7.9 requires league/flysystem ^1.0.8 -> satisfiable by league/flysystem[1.0.47].
- Installation request for laravel/framework v5.7.9 -> satisfiable by laravel/framework[v5.7.9].
To enable extensions, verify that they are enabled in your .ini files:
- C:\tools\php71\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
根据错误内容来看,似乎缺少PHP扩展模块的错误。
确认PHP扩展
>php -i | grep ext-fileinfo
我确认了,但没有收到。
安装最新的PHP7.2版本。
先前使用的PHP版本是7.1系列,所以通过Chocolatey安装了最新的7.2系列。在这里,由于安装不同版本的PHP会引发错误,所以我们使用了–force选项。
>choco install php --version 7.2.15 --force
-f, –force
强制 – 强制执行操作。在正常操作过程中不使用强制命令,它会破坏一些命令的智能行为。
由于这是一个强制执行命令,请在执行时小心。
确认是否已安装
>choco list -lo
修改PHP的ini文件
找到并启用下面的内容(去除注释)
启用ext-fileinfo
extension=php_fileinfo.dll
启用ext-gd
extension=php_gd2.dll
登出一次后再次执行composer install
> composer install
没有事情发生了
请提供参考网址
- php – ext-fileinfoが必要です。それをcomposer.jsonファイルに追加する方法 – コードログ