Nginx+PHP7.3.9 Docker鏡像製作
- 2019 年 10 月 6 日
- 筆記
最近因項目需要製作了多個版本的php docker鏡像,製作過程可謂是一波三折,因基於yum的方式安裝php的方式在安裝擴展插件時很不方便,不容易找到插件對應的yum源,所以PHP在docker鏡像中的安裝改成了源碼編譯安裝的方式。
主要有一下幾個步驟:
- 編譯php所需yum包安裝,注意epel-release
和libmcryt-devel 需要分成2條yum命令按照epel-release在前的命令安裝,不然會報找不到安裝包錯誤
yum -y install patch openssl openssl-devel pcre pcre-devel gd gd-devel gcc gcc-c++ make automake autoconf install libxml2 libxml2-devel curl-devel libjpeg-devel unzip mysql-server mysql-devel && yum -y install epel-release && yum -y install libmcrypt-devel && yum -y install libmhash-devel && yum -y install postgresql-devel && yum -y install bzip2-devel && yum -y install bzip2
- php源碼包下載
php源碼包有兩個地方提供,http://www.php.net/releases , https://github.com/php/php-src/建議從http://www.php.net/releases 選擇需要的版本,github上的源碼沒有configure文件,無法直接進行編譯;這裡選擇了 https://www.php.net/distributions/php-7.3.9.tar.gz這個版本
- 鏈接庫路徑設置
ln -s /usr/lib64/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so && ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so && ln -s /usr/lib64/libpng.so /usr/lib/libpng.so && ln -s /usr/lib64/mysql /usr/lib/mysql
- cmake安裝及設置 編譯 php7.3.9 因插件libzip需要 使用cmake3編譯,否則版本不支援,此處libzip原始的編譯腳本,libzip源碼包路徑 https://libzip.org/download/libzip-1.5.2.tar.gz
yum install -y cmake3 && ln -s /usr/bin/cmake3 /usr/bin/cmake && tar -zxvf libzip-1.5.1.tar.gz && cd libzip-1.5.1 && mkdir build && cd build && cmake .. && make && make install
- 源碼編譯開關配置及編譯命令
#環境變數
export ver=php-7.3.9 &&
export folder=php739 &&
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig ./configure --prefix=/usr/local/${folder} --enable-zip --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --with-iconv --with-mhash --enable-zip --with-bz2 --enable-gd-native-ttf --with-config-file-path=/usr/local/${folder}/etc --with-config-file-scan-dir=/usr/local/${folder}/etc/php.d --with-curl --with-libxml-dir=/usr/lib64 --with-gd --with-jpeg-dir --with-freetype-dir=/usr/lib64 --with-png-dir --with-mcrypt --with-mhash --enable-mbstring --with-kerberos --with-gettext --enable-bcmath --with-mysql --with-mysqli --with-sqlite --enable-pdo --with-pdo-mysql --with-openssl --enable-ftp --with-pear --with-zlib --enable-inline-optimization --with-pdo-pgsql --with-pgsql --enable-calendar --enable-magic-quotes --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --disable-debug && make && make instal - 開啟服務,service start nginx && /usr/local/${folder}/sbin/php-fpm
完整可直接build的dockerfile 請參考
http://3xcn.com/forum.php?mod=viewthread&tid=60&extra=page%3D1
