📌  相关文章
📜  meyfa phpunit-assert-gd[v2.0.0, ..., v2.x-dev, v3.0.0] 需要 ext-gd * -> 您的系统中缺少它.安装或启用 PHP 的 gd 扩展 - PHP (1)

📅  最后修改于: 2023-12-03 14:44:16.034000             🧑  作者: Mango

缺少 GD 扩展

如果您使用的是 meyfa/phpunit-assert-gd,则可能会遇到以下错误:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - meyfa/phpunit-assert-gd[v2.0.0, ..., v2.x-dev, v3.0.0] require ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini
    - /etc/php/7.4/cli/conf.d/10-opcache.ini
    - /etc/php/7.4/cli/conf.d/10-pdo.ini
    - /etc/php/7.4/cli/conf.d/15-xml.ini
    - /etc/php/7.4/cli/conf.d/20-bcmath.ini
    - /etc/php/7.4/cli/conf.d/20-calendar.ini
    - /etc/php/7.4/cli/conf.d/20-ctype.ini
    - /etc/php/7.4/cli/conf.d/20-curl.ini
    - /etc/php/7.4/cli/conf.d/20-dom.ini
    - /etc/php/7.4/cli/conf.d/20-exif.ini
    - /etc/php/7.4/cli/conf.d/20-ffi.ini
    - /etc/php/7.4/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.4/cli/conf.d/20-ftp.ini
    - /etc/php/7.4/cli/conf.d/20-gd.ini
    - /etc/php/7.4/cli/conf.d/20-gettext.ini
    - /etc/php/7.4/cli/conf.d/20-iconv.ini
    - /etc/php/7.4/cli/conf.d/20-imap.ini
    - /etc/php/7.4/cli/conf.d/20-intl.ini
    - /etc/php/7.4/cli/conf.d/20-json.ini
    - /etc/php/7.4/cli/conf.d/20-mbstring.ini
    - /etc/php/7.4/cli/conf.d/20-mysqli.ini
    - /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/7.4/cli/conf.d/20-phar.ini
    - /etc/php/7.4/cli/conf.d/20-posix.ini
    - /etc/php/7.4/cli/conf.d/20-readline.ini
    - /etc/php/7.4/cli/conf.d/20-shmop.ini
    - /etc/php/7.4/cli/conf.d/20-simplexml.ini
    - /etc/php/7.4/cli/conf.d/20-sockets.ini
    - /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.4/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.4/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.4/cli/conf.d/20-tokenizer.ini
    - /etc/php/7.4/cli/conf.d/20-xmlreader.ini
    - /etc/php/7.4/cli/conf.d/20-xmlwriter.ini
    - /etc/php/7.4/cli/conf.d/20-xsl.ini
    - /etc/php/7.4/cli/conf.d/20-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

这是因为您的 PHP 环境没有安装 GD 扩展。

安装 GD 扩展

请按照您的操作系统和 PHP 版本,选择以下方法之一安装 GD 扩展:

Ubuntu
sudo apt-get update
sudo apt-get install php7.4-gd # 这里根据您的 PHP 版本来安装相应的包
CentOS
sudo yum install php-gd
macOS

使用 Homebrew 安装:

brew install php-gd

启用 GD 扩展

安装 GD 扩展后,还需要在 PHP 配置文件中启用该扩展。您可以通过编辑 php.ini 文件来实现。

sudo vim /etc/php/7.4/cli/conf.d/20-gd.ini # 这里根据您的 PHP 版本和扩展名来编辑相应的文件

在文件中添加以下内容:

extension=gd.so

保存并退出编辑器。

结语

安装和启用 GD 扩展后,您的程序将能够正常使用 meyfa/phpunit-assert-gd