You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在XAMPP环境安装phpoffice/phpspreadsheet时遇GD扩展缺失问题

XAMPP环境安装phpoffice/phpspreadsheet提示ext-gd缺失的排查方案

问题描述

在XAMPP环境中为Laravel 8项目安装phpoffice/phpspreadsheet时,持续收到ext-gd扩展缺失的错误提示,但已确认php.ini中extension=gd、extension=zip、extension=fileinfo均已取消注释。此前该环境可正常运行其他PHP及Laravel项目,已尝试以下步骤未解决问题:

  • 检查php.ini确认GD扩展启用
  • 重启XAMPP及电脑
  • 重新执行composer require phpoffice/phpspreadsheet

预期:GD扩展已启用,可顺利安装phpoffice/phpspreadsheet
实际:安装时仍提示ext-gd缺失,无法完成安装

排查步骤

1. 确认修改的是CLI模式的php.ini

XAMPP中PHP存在Apache和CLI两个环境的配置文件,Composer通过CLI运行,需确保修改的是CLI对应的php.ini:
执行命令:

php --ini

查看输出中的Loaded Configuration File路径,确认该路径下的php.ini已启用extension=gd。

2. 验证GD扩展是否实际加载

执行命令:

php -m

查看输出列表中是否包含gd。若未找到,需排查:

  • 检查php.ini中extension_dir配置,确保指向正确的扩展目录(Windows下通常为ext/,如extension_dir = "ext")
  • 确认XAMPP的php/ext目录下存在php_gd.dll(Windows)或gd.so(Linux)文件,且文件未损坏

3. 确认Composer使用的PHP版本

若系统存在多个PHP版本,Composer可能调用了非XAMPP的PHP:
执行命令:

composer diagnose

查看输出中的PHP路径,确认其指向XAMPP的PHP目录。

4. 强制指定XAMPP的PHP执行Composer

若Composer使用的PHP不正确,直接指定XAMPP的PHP路径执行命令:

# Windows示例,替换为你的XAMPP PHP路径
C:\xampp\php\php.exe composer.phar require phpoffice/phpspreadsheet

5. 清除Composer缓存

缓存可能导致扩展检测异常,清除后重新安装:

composer clear-cache
composer require phpoffice/phpspreadsheet

附用户提供的php.ini配置片段

; Notes for Windows environments :
;
; - Many DLL files are located in the ext/
;   extension folders as well as the separate PECL DLL download.
;   Be sure to appropriately set the extension_dir directive.
;
;extension=bz2

; The ldap extension must be before curl if OpenSSL 1.0.2 and OpenLDAP is used
; otherwise it results in segfault when unloading after using SASL.
; See https://github.com/php/php-src/issues/8620 for more info.
;extension=ldap

;extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
extension=gd
;extension=gettext
;extension=gmp
extension=intl
;extension=imap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=oci8_19  ; Use with Oracle Database 19 Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop

; The MIBS data available in the PHP distribution must be installed.
; See https://www.php.net/manual/en/snmp.installation.php
;extension=snmp

;extension=soap
;extension=sockets
;extension=sodium
;extension=sqlite3
;extension=tidy
;extension=xsl
extension=zip

;zend_extension=opcache

内容的提问来源于stack exchange,提问作者yacine hamiane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:22:58