构建php5.3.29+phalcon2的docker环境
1、拉取centos7镜像
# arm64架构CPU
docker pull arm64v8/centos:7.9.2009
# amd64架构cpu
docker pull centos:7.6.1810
2、新建一个基础容器
# arm64架构CPU
docker run --privileged=true -it arm64v8/centos:7.9.2009 /bin/bash
# amd64架构cpu
docker run --privileged=true -it arm64v8/centos:7.9.2009 /bin/bash
3、进行构建php5.3.29和phalcon2基础环境
yum install epel-release
yum groupinstall "Development Tools" -y
yum install gcc gcc-c++ make autoconf libxml2-devel bzip2-devel curl-devel \
libjpeg-devel libpng-devel freetype-devel libmcrypt-devel \
mysql-devel openssl-devel libmcrypt-devel libicu-devel -y
- 如果是amd64 架构不要安装
mysql-devel
, 用一下方式安装mysql依赖包
yum remove mariadb-devel
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.62-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-shared-5.5.62-1.el7.x86_64.rpm
yum install MySQL-devel-5.5.62-1.el7.x86_64.rpm MySQL-shared-5.5.62-1.el7.x86_64.rpm
4、开始编译
# 下载php源码包
wget https://www.php.net/distributions/php-5.3.29.tar.gz
# 解压
tar -zxf php-5.3.29.tar.gz
# 进入目录
cd php-5.3.29
# 执行配置检查
./configure \
--prefix=/usr/local/php/5.3 \
--with-config-file-path=/usr/local/php/5.3/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-curl \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--enable-mbstring \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--enable-calendar \
--enable-ftp \
--with-mcrypt \
--with-gd \
--with-xmlrpc \
--enable-intl \
--enable-fpm \
--disable-opcache \
--with-libdir=lib64 \
LIBS="-lstdc++ -lpthread"
# 配置通过后开始编译
make -j$(nproc)
# make通过后直接安装
make install
# 将源码包下的php.ini-development 文件复制到/usr/local/php/5.3/etc目录
cp php.ini-development /usr/local/php/5.3/etc/php.ini
# 将/usr/local/php/5.3/etc目录下的php-fpm.conf.default文件重命名为php-fpm.conf
mv /usr/local/php/5.3/etc/php-fpm.conf.default /usr/local/php/5.3/etc/php-fpm.conf
5、编译phalcon2.0.1扩展
# 下载phalcon源码
https://github.com/phalcon/cphalcon/archive/refs/tags/phalcon-v2.0.1.tar.gz
# 解压源码
tar -zxf phalcon-v2.0.1.tar.gz
cd cphalcon-phalcon-v2.0.1
# 进入到源码build/64bits 目录下执行 phpize命令
phpize
# 执行配置检查configure(arm64架构)
./configure --build=aarch64-unknown-linux-gnu --with-php-config=/usr/local/php/5.3/bin/php-config
# 执行配置检查configure(amd64架构)
./configure --with-php-config=/usr/local/php/5.3/bin/php-config
# 执行编译构建
make -j$(nproc)
# 执行安装
make install
# 在php.ini文件最后添加phalcon配置项
[phalcon]
extension=phalcon.so
6、编译nginx1.8.1
wget https://nginx.org/download/nginx-1.8.1.tar.gz
# 执行配置
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_addition_module \
--with-pcre
# 执行编译构建
make -j$(nproc)
# 执行安装
make install
# 新建conf.d 目录,用于用户映射自定义配置文件
mkdir -p /usr/local/nginx/conf/conf.d
# 配置nginx.conf,在localhost 配置项下添加php解析服务
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
# 在文件最后添加引入用户自定义配置文件
include conf.d/*.conf;
7、构建php-fpm+nginx启动脚本
vim /start.sh
#!/bin/bash
/usr/local/php/5.3/sbin/php-fpm &
exec /usr/local/nginx/sbin/nginx -g "daemon off;"
- 设置环境变量
echo 'export PATH=/usr/local/php/5.3/sbin:$PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/php/5.3/bin:$PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> ~/.bashrc
8、提交当前docker容器为docker 镜像
docker commit [容器ID] 镜像名:版本
docker commit 4d47739c75e5 harbor.dev.10t.link:8443/library/php5.3_http_arm64v8:0.1
9、通过新打包的镜像进行创建容器服务
- 创建docker-compose.yml 文件
services:
php5.3_web:
image: harbor.dev.10t.link:8443/library/php5.3_http_arm64v8:0.1
container_name: php5.3_web2
environment:
- TZ=Asia/Shanghai
ports:
- "18380:80"
privileged: true
command: ["/bin/bash", "/start.sh"]
volumes:
- /User/code/demo/html:/usr/local/nginx/html
- /User/code/demo/conf:/usr/local/nginx/conf.d
restart: unless-stopped
10、以下是一个简单的nginx配置代码
server {
listen 80;
server_name demo.test.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}