1、在 CentOS 7.5 64 位、PHP 7.4 中报错:PHP Core Warning ‘yii/base/ErrorException’ with message ‘Module ‘zip’ already loaded’,如图1
2020/6/12 下午1:15:12PHP Core Warning 'yii/base/ErrorException' with message 'Module 'zip' already loaded' 2020/6/12 下午1:15:12 2020/6/12 下午1:15:12in ./Unknown:0 2020/6/12 下午1:15:12 2020/6/12 下午1:15:12Stack trace: 2020/6/12 下午1:15:12#0 [internal function]: yii/base/ErrorHandler->handleFatalError() 2020/6/12 下午1:15:12#1 {main}
2、查看 phpinfo() 的信息,确认 zip 扩展已经安装。如图2
3、检查 /usr/local/php/etc/php.ini 中是否存在 zip。存在。
;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 = "zip.so" extension = "gd.so"
4、查看 phpinfo() 的 extension_dir,其值:/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ ,如图3
5、进入目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/,查看扩展包,zip、gd 扩展已存在。如图4
[root@5e4d278fdede /]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ [root@5e4d278fdede no-debug-non-zts-20190902]# ls -l total 32032 -rwxr-xr-x 1 root root 234763 Apr 16 22:48 exif.so -rwxr-xr-x 1 root root 1300761 Apr 16 22:48 gd.so -rwxr-xr-x 1 root root 2791555 Apr 16 23:39 intl.so -rwxr-xr-x 1 root root 279018 Apr 16 22:48 ldap.so -rwxr-xr-x 1 root root 4764219 Apr 16 23:40 mongodb.so -rwxr-xr-x 1 root root 4677222 Apr 16 22:14 opcache.a -rwxr-xr-x 1 root root 2490202 Apr 16 22:14 opcache.so -rwxr-xr-x 1 root root 452180 Apr 16 23:38 rdkafka.so -rwxr-xr-x 1 root root 2485341 Apr 16 23:38 redis.so -rwxr-xr-x 1 root root 255240 Apr 16 23:42 skywalking.so -rwxr-xr-x 1 root root 391892 Apr 16 22:14 sockets.so -rwxr-xr-x 1 root root 12372105 Apr 16 23:41 swoole.so -rwxr-xr-x 1 root root 226843 Apr 16 22:48 zip.so
6、决定先还原至上一个基础镜像,在上一个基础镜像中,未安装 zip、gd 扩展,也未报错。检查 /usr/local/php/etc/php.ini 中是否存在 zip。不存在。
;extension = "memcached.so" extension = "redis.so" ;extension = "mongo.so" extension = "sockets.so" extension = "swoole.so" extension = "mongodb.so" extension = "rdkafka.so" extension = "exif.so"
7、进入目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/,查看扩展包,zip、gd 扩展不存在。如图5
[root@0bb790b2627f /]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ [root@0bb790b2627f no-debug-non-zts-20190902]# ls -l total 30484 -rwxr-xr-x 1 root root 234763 Mar 29 22:56 exif.so -rwxr-xr-x 1 root root 2791843 Mar 29 23:23 intl.so -rwxr-xr-x 1 root root 279018 Mar 29 22:56 ldap.so -rwxr-xr-x 1 root root 4764227 Mar 29 23:24 mongodb.so -rwxr-xr-x 1 root root 4677222 Mar 29 22:56 opcache.a -rwxr-xr-x 1 root root 2490202 Mar 29 22:56 opcache.so -rwxr-xr-x 1 root root 452180 Mar 29 23:23 rdkafka.so -rwxr-xr-x 1 root root 2485341 Mar 29 23:22 redis.so -rwxr-xr-x 1 root root 255240 Mar 29 23:26 skywalking.so -rwxr-xr-x 1 root root 391892 Mar 29 22:56 sockets.so -rwxr-xr-x 1 root root 12372105 Mar 29 23:26 swoole.so
8、最终通过在 Dockerfile 中新增:sed -i ‘/zip.so/d’ /usr/local/php/etc/php.ini && / 以解决此问题。
RUN sed -i 's/open_basedir = .//://sobey://tmp://data://webtv/;open_basedir = .//://sobey://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/max_execution_time = 60/max_execution_time = 300/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 '/zip.so/d' /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
9、检查 /usr/local/php/etc/php.ini 中是否存在 zip。不存在。已经被删除。如图6
10、查看 phpinfo() 的信息,确认 zip 扩展仍然是已经安装。查看 Configure Command,原因在于:’–with-gd’ ‘、’–enable-zip’,zip 扩展默认已经启用。因此,无需要在 php.ini 重新启用。如图7
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250536.html