PHP镜像安装模块

Wanjiongming 于 2021-09-01 发布

默认的 php:7.0.33-fpm 镜像少了好多模块,直接使用 Dockerfile 构建会比较麻烦,而且体积也比较大。于是直接进入到容器里面安装,最后根据容器生成一个属于自己的镜像tmaize/php7-fpm。在这里记录下步骤,说不定以后还会用到

说明

原始镜像已经内置了如下的源码,为了减小体积只是压缩起来了,并未编译安装,使用docker-php-ext-install自行安装即可

bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp
hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl
pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix
pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard
sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip

安装

进入容器

docker run --name temp -d php:7.0.33-fpm
docker exec -it temp /bin/bash

安装模块

docker-php-ext-install bcmath

apt-get update
apt-get install -y libbz2-dev
docker-php-ext-install bz2

docker-php-ext-install calendar

docker-php-ext-install exif

apt-get install -y libjpeg-dev libjpeg62-turbo-dev libwebp-dev libpng-dev libfreetype6-dev libxpm-dev
docker-php-ext-configure gd --with-webp-dir=/usr/include --with-png-dir=/usr/include \
--with-jpeg-dir=/usr/include --with-freetype-dir=/usr/include --with-xpm-dir=/usr/include
docker-php-ext-install gd
# php -r "var_dump(gd_info());"

docker-php-ext-install gettext

curl -O https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
xz -d gmp-6.2.1.tar.xz
tar -xvf gmp-6.2.1.tar
cd gmp-6.2.1
./configure
make
make install
docker-php-ext-install gmp

docker-php-ext-install mysqli

docker-php-ext-install pcntl

docker-php-ext-install pdo_mysql

docker-php-ext-install shmop

docker-php-ext-install sockets

docker-php-ext-install zip

docker-php-ext-install opcache

cd ..
rm -rf ./*
apt-get clean
apt-get autoclean

# 使用生产配置
cd $PHP_INI_DIR
cp php.ini-production php.ini
history -c
exit

推送镜像

docker container stop temp
docker commit -m "install modules" temp docker.io/tmaize/php7-fpm:1.0.0
docker login -u tmaize # 生成新的Access Tokens登录,不要使用密码
docker push docker.io/tmaize/php7-fpm:1.0.0
docker rm temp

php -m

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

参考

Php - Official Image