没有不值得去解决的问题,也没有不值得去学习的技术!

PHP Core Warning: Module ‘gd’ Already Loaded After Changing the Container Base Image

容器的基础镜像更换后,当 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=true 时,容器启动失败。报错:PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'。

1. After changing the container’s base image, the container fails to start when the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=true is set. Error: PHP Core Warning ‘yii\base\ErrorException’ with message ‘Module ‘gd’ already loaded’. See Figure 1.

After changing the container's base image, the container fails to start when the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=true is set. Error: PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'.
Figure 1
Plaintext

      chmod 0755 yii

      chmod 0755 yii_test

  ... initialization completed.

CHANNEL_PUB_API_CFG_MIGRATE=true

Yii Migration Tool (based on Yii v2.0.41.1)

No new migrations found. Your system is up-to-date.

PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'

in ./Unknown:0

Stack trace:

#0 [internal function]: yii\base\ErrorHandler->handleFatalError()

#1 {main}

2. When the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=false is set, the container starts successfully. See Figure 2.

When the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=false is set, the container starts successfully.
Figure 2
Plaintext

      chmod 0755 yii

      chmod 0755 yii_test

  ... initialization completed.

CHANNEL_PUB_API_CFG_MIGRATE=false

running without db migrate

CHANNEL_PUB_API_CFG_CONSOLE=false

copy without console

CHANNEL_PUB_API_CFG_CRONTAB_VTT=false

crontab.php not running

POD_NAMESPACE=ccp

test fail

get environment fail

ENVIRONMENT:default

POD_NAMESPACE=ccp

POD_HOSTIP=192.168.1.46

POD_IP=10.42.2.200

3. When the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=true is set, it essentially executes a series of command-line commands.

ShellScript

env | grep CHANNEL_PUB_API_CFG_MIGRATE || export CHANNEL_PUB_API_CFG_MIGRATE="false"
if [[ $CHANNEL_PUB_API_CFG_MIGRATE == "true" ]]
then
    php /mcloud/www/ccp_api/yii migrate --migrationPath=@yii/log/migrations/ --interactive=0
    php /mcloud/www/ccp_api/yii migrate --interactive=0
    php /mcloud/www/ccp_api/yii cache/flush-schema db --interactive=0
    php /mcloud/www/ccp_api/yii douyin-web-app/init-sync
    php /mcloud/www/ccp_api/yii qq-tp-app/init-sync
    php /mcloud/www/ccp_api/yii qq-cw-app/init-sync
    php /mcloud/www/ccp_api/yii weibo-weibo-connect-web-app/init-sync
    php /mcloud/www/ccp_api/yii wx-bizplugin-app/init-sync
    php /mcloud/www/ccp_api/yii netease-tp-app/init-sync
elif [[ $CHANNEL_PUB_API_CFG_MIGRATE == "false" ]]
then
    echo "running without db migrate"
else
    echo "please set environment variable CHANNEL_PUB_API_CFG_MIGRATE true or false"
fi

4. I decided to manually execute the above commands in the successfully started container first to determine exactly which command caused the error. I set the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=false. I executed the first 3 commands in sequence, and all of them threw errors. See Figure 3.

I decided to manually execute the above commands in the successfully started container first to determine exactly which command caused the error. I set the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=false. I executed the first 3 commands in sequence, and all of them threw errors.
Figure 3
Plaintext

[root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii migrate --migrationPath=@yii/log/migrations/ --interactive=0
Yii Migration Tool (based on Yii v2.0.41.1)

No new migrations found. Your system is up-to-date.
PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'

in ./Unknown:0

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
[root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii migrate --interactive=0
Yii Migration Tool (based on Yii v2.0.41.1)

No new migrations found. Your system is up-to-date.
PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'

in ./Unknown:0

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
[root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii cache/flush-schema db --interactive=0
Schema cache for component "db", was flushed.

PHP Core Warning 'yii\base\ErrorException' with message 'Module 'gd' already loaded'

in ./Unknown:0

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
[root@api-console-migrate-5788cbf65c-qkjv2 /]# 

5. I searched my tech blog for: Module ‘gd’ already loaded. I had solved a similar issue before. Reference URL: https://www.shuijingwanwq.com/2020/06/15/4240/

6. I checked if gd exists in /usr/local/php/etc/php.ini. It does. See Figure 4.

I checked if gd exists in /usr/local/php/etc/php.ini. It does.
Figure 4
Plaintext

;extension = "memcached.so"
extension = "redis.so"
;extension = "mongo.so"
extension = "sockets.so"
extension = "swoole.so"
extension = "mongodb.so"
extension = "rdkafka.so"
extension = "exif.so"
extension = "imagick.so"
extension = "gd.so"
extension=mcrypt.so

7. I ultimately resolved this issue by adding the following to the Dockerfile: sed -i ‘/gd.so/d’ /usr/local/php/etc/php.ini && \.

Dockerfile

RUN sed -i 's/open_basedir = .\/:\/tmp:\/data:\/webtv/;open_basedir = .\/:\/tmp:\/data:\/webtv:\/usr\/local\/php/g' /usr/local/php/etc/php.ini && \
    sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && \
    sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini && \
    sed -i 's/;realpath_cache_ttl = 120/realpath_cache_ttl = 1200/g' /usr/local/php/etc/php.ini && \
    sed -i  '/gd.so/d' /usr/local/php/etc/php.ini && \
    sed -i 's/memory_limit = 2048M/memory_limit = 6144M/g' /usr/local/php/etc/php.ini && \
    sed -i 's/pm.max_children = 20/pm.max_children = 40/g' /usr/local/php/etc/php-fpm.conf


8. After the upgrade, I ran the relevant commands again. Error: PHP Core Warning ‘yii\base\ErrorException’ with message ‘Module ‘exif’ already loaded’. I applied the same fix by adding the following to the Dockerfile: sed -i ‘/exif.so/d’ /usr/local/php/etc/php.ini && \.

9. The next extension to throw an error in sequence was sockets. I handled it the same way. A total of 3 lines of configuration were ultimately added to the Dockerfile. See Figure 5.

The next extension to throw an error in sequence was sockets. I handled it the same way. A total of 3 lines of configuration were ultimately added to the Dockerfile.
Figure 5

10. When the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=true is set, the container starts successfully. See Figure 6.

When the Rancher environment variable CHANNEL_PUB_API_CFG_MIGRATE=true is set, the container starts successfully.
Figure 6
Plaintext
      chmod 0755 yii

      chmod 0755 yii_test

  ... initialization completed.

CHANNEL_PUB_API_CFG_MIGRATE=true

Yii Migration Tool (based on Yii v2.0.41.1)

No new migrations found. Your system is up-to-date.

Yii Migration Tool (based on Yii v2.0.41.1)

Total 1 new migration to be applied:

	m211104_075052_alter_ccp_tables

*** applying m211104_075052_alter_ccp_tables

    > insert into {{%ccp_platform}} ... done (time: 0.025s)

    > insert into {{%channel_type}} ... done (time: 0.059s)

    > alter column publish_task_id in table {{%ccp_task_log}} to integer(11) NOT NULL DEFAULT 0 COMMENT '关联任务id' ... done (time: 0.116s)

    > alter column account_token in table {{%ccp_platform_account}} to string(500) NOT NULL DEFAULT '' COMMENT '平台账号访问令牌' ... done (time: 0.029s)

    > alter column refresh_token in table {{%ccp_platform_account}} to string(500) NOT NULL DEFAULT '' COMMENT '刷新令牌' ... done (time: 0.023s)

*** applied m211104_075052_alter_ccp_tables (time: 0.264s)

1 migration was applied.

Migrated up successfully.

Schema cache for component "db", was flushed.

抖音的网站应用模型的初始化(同步)成功

模型(企鹅号的第三方服务平台应用)创建成功

模型(企鹅号的内容网站应用)创建成功

模型(微博的微连接的网页应用)创建成功

微信的第三方平台应用模型的初始化(同步)成功

模型(网易号的第三方内容平台应用)创建成功

CHANNEL_PUB_API_CFG_CONSOLE=false

copy without console

CHANNEL_PUB_API_CFG_CRONTAB_VTT=false

crontab.php not running

POD_NAMESPACE=ccp

test fail

get environment fail

ENVIRONMENT:default

POD_NAMESPACE=ccp

POD_HOSTIP=192.168.1.48

POD_IP=10.42.3.235

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系