如果没有包含PHP扩展ext-gd,该如何处理?
简述
有时我会在一个项目中使用EC-CUBE2系,尝试在我的电脑上搭建开发环境时遇到了一个没有安装PHP扩展模块的错误,下面是我采取的解决措施。
环境建设
请参考以下的GitHub链接进行构建:
https://github.com/honjou/docker-eccube2
未安装Composer的消息被显示
在执行docker-compose up -d之后,访问localhost时显示未安装Composer,因此尝试访问容器并安装Composer。
# コンテナ名確認(ここではlaravel_appを使う)
[xxx@MacBook-xxx docker-eccube2 (main %=)]$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------------------------------------
docker-eccube2_mailcatcher_1 mailcatcher --no-quit --fo ... Up 1025/tcp, 0.0.0.0:1080->1080/tcp
eccube2_db docker-entrypoint.sh mysql ... Up 0.0.0.0:3306->3306/tcp, 33060/tcp
laravel_app docker-php-entrypoint apac ... Up 0.0.0.0:80->80/tcp
phpmyadmin /docker-entrypoint.sh apac ... Up 0.0.0.0:8080->80/tcp
# コンテナ内にアクセス
[xxx@MacBook-xxx docker-eccube2 (main %=)]$ docker exec -it laravel_app /bin/bash
root@7cd72c0ea344:/var/www/html#
# composerをダウンロード
root@7cd72c0ea344:/var/www/html# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 2.6.2) successfully installed to: /var/www/html/composer.phar
Use it: php composer.phar
# composerを移動
root@7cd72c0ea344:/var/www/html# mv composer.phar /usr/local/bin/composer
# composer.jsonがあるディレクトリに移動
root@7cd72c0ea344:/var/www/html# cd eccube2/
# install
root@7cd72c0ea344:/var/www/html/eccube2# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- Root composer.json requires PHP extension ext-gd * but 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:
- /usr/local/etc/php/php.ini
- /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-gd` to temporarily ignore these required extensions.
由于根composer.json文件需要PHP扩展ext-gd*,但该扩展在您的系统中缺失。请安装或启用PHP的gd扩展以解决此错误。因此,需要检查gd的情况。
没有包含GD
经过使用 `php -m` 命令检查,发现无法加载 `gd`。
root@7cd72c0ea344:/var/www/html# php -m | grep gd
{何も表示されない}
因为确认没有被显示出来,所以我先退出容器再结束。
root@7cd72c0ea344:/var/www/html/eccube2# exit
exit
[xxx@MacBook-xxx docker-eccube2 (main %=)]$ docker-compose down
Stopping phpmyadmin ... done
Stopping laravel_app ... done
Stopping eccube2_db ... done
Stopping docker-eccube2_mailcatcher_1 ... done
Removing phpmyadmin ... done
Removing laravel_app ... done
Removing eccube2_db ... done
Removing docker-eccube2_mailcatcher_1 ... done
Removing network docker-eccube2_default
在Dockerfile中包含gd库
请根据以下文章参考,修改Dockerfile:
https://tt-computing.com/docker-php-gd
:
:
&& docker-php-ext-install pdo_mysql mysqli gd
在docker-php-ext-install命令中添加gd。
再建设和发展
从这里开始执行最初采取的应对措施。
[xxx@MacBook-xxx docker-eccube2 (main %=)]$ docker-compose build
:
(省略)
:
[xxx@MacBook-xxx docker-eccube2 (main %=)]$ docker-compose up -d
Creating network "docker-eccube2_default" with the default driver
Creating docker-eccube2_mailcatcher_1 ... done
Creating eccube2_db ... done
Creating laravel_app ... done
Creating phpmyadmin ... done
访问容器并确认gd
[xxx@MacBook-xxx docker-eccube2 (main *%=)]$ docker exec -it laravel_app /bin/bash
# gdが入っているのを確認
root@77e347ed4520:/var/www/html# php -m | grep gd
gd
重新安装composer
# composerをダウンロード
root@77e347ed4520:/var/www/html# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 2.6.2) successfully installed to: /var/www/html/composer.phar
Use it: php composer.phar
# composerを移動
root@77e347ed4520:/var/www/html# mv composer.phar /usr/local/bin/composer
# install
root@77e347ed4520:/var/www/html# cd eccube2/
root@77e347ed4520:/var/www/html/eccube2# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 40 installs, 0 updates, 0 removals
- Downloading fzaninotto/faker (v1.9.2)
- Downloading react/promise (v2.8.0)
:
(省略)
:
Generating optimized autoload files
:
(省略)
:
Class MDB2_PEARProxy located in ./data/vendor/silverorange/mdb2/MDB2/Wrapper/peardb.php does not comply with psr-0 autoloading standard. Skipping.
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
当您访问localhost并且看到EC-CUBE安装页面显示时,说明一切OK。
只需一种选择:我根据参考文章完成了启动的所有步骤。