Dockerfile
情人节更新一波,因为平常等保总要更新基于LAP的各种镜像,备份下我的LAP(Linux、Apache、PHP) Dockerfile文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
FROM rockylinux:9
LABEL os-version=AlmaLinux-release-9.1-(Lime-Lynx)
LABEL apache-version=2.4.55
LABEL php-version=7.4.33
LABEL apr-version=apr-1.7.2
LABEL apr-util-version=apr-util-1.6.3
LABEL expat-version=expat-2.5.0
LABEL pcre-version=pcre-8.45
LABEL build-date=20230208
LABEL builder="huhuicheng huhuicheng@geostar.com.cn"
# 这里有个坑,变量名不能用中横线"-", 会报错:
# failed to process "https://dlcdn.apache.org/apr/${apr-name}.tar.gz": missing ':' in substitution
ARG apr_name=apr-1.7.2
ARG apr_util_name=apr-util-1.6.3
ARG expat_name=expat-2.5.0
ARG pcre_verison=8.45
ARG prce_name=pcre-${pcre_verison}
ARG httpd_name=httpd-2.4.55
ARG apr_source_list=https://dlcdn.apache.org/apr/${apr_name}.tar.gz
ARG apr_util_source_list=https://dlcdn.apache.org/apr/${apr_util_name}.tar.gz
ARG expat_source_list=https://github.com/libexpat/libexpat/releases/download/R_2_5_0/${expat_name}.tar.gz
ARG prce_source_list=https://sourceforge.net/projects/pcre/files/pcre/${pcre_verison}/${prce_name}.tar.gz/download
ARG httpd_source_list=https://dlcdn.apache.org/httpd/${httpd_name}.tar.gz
ARG libmcrypt_version=2.5.8-3.4
ARG libmcrypt_name=libmcrypt-${libmcrypt_version}
ARG libmcrypt_unpack_name=libmcrypt-libmcrypt-${libmcrypt_version}
ARG mhash_version=0.9.9.9
ARG mhash_name=mhash-${mhash_version}
ARG mcrypt_name=mcrypt-2.6.8
ARG libiconv_name=libiconv-1.17
ARG oniguruma_version=6.9.8
ARG oniguruma_name=onig-${oniguruma_version}
ARG php_name=php-7.4.33
ARG libmcrypt_source_list=https://github.com/winlibs/libmcrypt/archive/refs/tags/${libmcrypt_name}.tar.gz
ARG mhash_source_list=https://sourceforge.net/projects/mhash/files/mhash/${mhash_version}/${mhash_name}.tar.gz/download
ARG mcrypt_source_list=https://github.com/swenson/mcrypt/archive/refs/tags/v2.6.8.tar.gz
ARG libiconv_source_list=https://ftp.gnu.org/pub/gnu/libiconv/${libiconv_name}.tar.gz
ARG oniguruma_source_list=https://github.com/kkos/oniguruma/releases/download/v${oniguruma_version}/${oniguruma_name}.tar.gz
ARG php_source_list=https://www.php.net/distributions/${php_name}.tar.gz
ENV PATH=$PATH:/srv/lamp/apache2/bin:/srv/lamp/base/apr/bin:/srv/lamp/base/apr-util:/srv/lamp/base/pcre/bin:/srv/lamp/php/bin:/srv/lamp/base/libmcrypt/bin:/srv/lamp/base/mcrypt/bin:/srv/lamp/base/onig/bin
WORKDIR /srv/lamp/build
RUN mkdir -p /srv/lamp/build && \
mkdir -p /srv/lamp/base && \
cd /srv/lamp/build && \
# 这里有个坑,如果不安装libxml2-devel,apache make的时候会报一堆apr_util的错,类似下面:
# /usr/bin/ld: /srv/lamp/apr-util-1.63/lib/libaprutil-1.so:
# undefined reference to `XML_SetElementHandler' collect2: error: ld returned 1 exit status
yum install -y gcc \
gcc-c++ \
make wget \
openssl-devel \
libxml2-devel && \
# 下载包
wget ${expat_source_list} -O ${expat_name}.tar.gz && \
wget ${apr_source_list} -O ${apr_name}.tar.gz && \
wget ${apr_util_source_list} -O ${apr_util_name}.tar.gz && \
wget ${prce_source_list} -O ${prce_name}.tar.gz && \
wget ${httpd_source_list} -O ${httpd_name}.tar.gz && \
# 解压源码包
ls *.tar.gz | xargs -n1 tar xzvf && \
# 编译apache依赖和Apache
cd ${expat_name} && \
./configure --prefix=/srv/lamp/base/${expat_name} && \
make -j$(nproc) && \
make install && \
cd ../${apr_name} && \
./configure --prefix=/srv/lamp/base/${apr_name} && \
make -j$(nproc) && \
make install && \
# 软连接方便后期升级
ln -s /srv/lamp/base/${apr_name} /srv/lamp/base/apr && \
cd ../${apr_util_name} && \
./configure --prefix=/srv/lamp/base/${apr_util_name}/ --with-apr=/srv/lamp/base/${apr_name} --with-expat=/srv/lamp/base/${expat_name} && \
make -j$(nproc) && \
make install && \
# 软连接方便后期升级
ln -s /srv/lamp/base/${apr_util_name} /srv/lamp/base/apr-util && \
cd ../${prce_name}/ && \
./configure --prefix=/srv/lamp/base/${prce_name} && \
make -j$(nproc) && \
make install && \
# 软连接方便后期升级
ln -s /srv/lamp/base/${prce_name} /srv/lamp/base/pcre && \
cd ../${httpd_name}/ && \
./configure --prefix=/srv/lamp/${httpd_name} \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-rewrite \
--enable-ssl \
--with-pcre=/srv/lamp/base/${prce_name} \
--with-apr=/srv/lamp/base/${apr_name} \
--with-apr-util=/srv/lamp/base/${apr_util_name} \
--with-expat=builtin && \
make -j$(nproc) && \
make install && \
# 软连接方便后期升级
ln -s /srv/lamp/${httpd_name} /srv/lamp/apache2 && \
cd /srv/lamp/build/ && \
rm -fr /srv/lamp/build/* && \
# 开始编译php
yum install -y libxml2 \
libxml2-devel \
bzip2-devel \
perl \
perl-devel \
sqlite-devel \
# 安装zip组件需要的
libcurl-devel \
libzip-devel \
# 安装intl模组需要的
libicu-devel \
autoconf \
# 这个是安装gd模组依赖的
freetype-devel \
libpng-devel \
libjpeg-devel && \
# 下载包
wget ${libmcrypt_source_list} -O ${libmcrypt_name}.tar.gz && \
wget ${mhash_source_list} -O ${mhash_name}.tar.gz && \
wget ${mcrypt_source_list} -O ${mcrypt_name}.tar.gz && \
wget ${libiconv_source_list} -O ${libiconv_name}.tar.gz && \
wget ${oniguruma_source_list} -O ${oniguruma_name}.tar.gz && \
wget ${php_source_list} -O ${php_name}.tar.gz && \
# 解压源码包
ls *.tar.gz | xargs -n1 tar xzvf && \
# 编译
# 编译libmcrypt
cd ${libmcrypt_unpack_name} && \
chmod +x -R ./ && \
./configure --prefix=/srv/lamp/base/${libmcrypt_name} && \
make -j$(nproc) && \
make install && \
ln -s /srv/lamp/base/${libmcrypt_name} /srv/lamp/base/libmcrypt && \
# 编译mhash
cd ../${mhash_name} && \
./configure --prefix=/srv/lamp/base/${mhash_name} && \
make -j$(nproc) && \
make install && \
ln -s /srv/lamp/base/${mhash_name} /srv/lamp/base/mhash && \
# 编译mcrypt
cd ../${mcrypt_name} && \
export LD_LIBRARY_PATH=/srv/lamp/base/${libmcrypt_name}/lib:/srv/lamp/base/${mhash_name}/lib && \
export LDFLAGS="-L/srv/lamp/base/${mhash_name}/lib/ -I/srv/lamp/base/${mhash_name}/include/" && \
export CFLAGS="-I/srv/lamp/base/${mhash_name}/include/" && \
./configure --prefix=/srv/lamp/base/${mcrypt_name} --with-libmcrypt-prefix=/srv/lamp/base/${libmcrypt_name} && \
make -j$(nproc) && \
make install && \
ln -s /srv/lamp/base/${mcrypt_name} /srv/lamp/base/mcrypt && \
# 编译libconv
cd ../${libiconv_name} && \
./configure --prefix=/srv/lamp/base/${libiconv_name} && \
make -j$(nproc) && \
make install && \
# 编译onig
cd ../${oniguruma_name} && \
./configure --prefix=/srv/lamp/base/${oniguruma_name} && \
make -j$(nproc) && \
make install && \
ln -s /srv/lamp/base/${oniguruma_name} /srv/lamp/base/onig && \
# 编译php
cd ../${php_name} && \
ln -s /srv/lamp/base/onig/lib/pkgconfig/oniguruma.pc /usr/lib64/pkgconfig/ && \
sed -i 's#\#!/replace/with/path/to/perl/interpreter -w#\#!/usr/bin/perl -w#' /srv/lamp/apache2/bin/apxs && \
./configure --prefix=/srv/lamp/${php_name} \
--with-openssl \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-mcrypt \
--with-zlib \
# 下面四个不带,如果应用是owncloud,会报错
--with-zip \
--with-intl \
--with-gd \
--with-curl \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/srv/lamp/apache2/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--enable-maintainer-zts \
--with-iconv=/srv/lamp/base/${libiconv_name} && \
make -j$(nproc) && \
make install && \
ln -s /srv/lamp/${php_name} /srv/lamp/php && \
EXTLIB_PATH=$(ls -l /srv/lamp/php/lib/php/extensions/ |awk '/^d/ {print "/srv/lamp/php/lib/php/extensions/"$NF}') && \
# 编译php的intl模组
cd /srv/lamp/build/${php_name}/ext/intl && \
phpize && \
./configure --enable-intl --with-php-config=/srv/lamp/${php_name}/bin/php-config && \
make -j$(nproc) && \
make install && \
# 默认不生成配置文件,咱们拷贝一个过去
cp modules/intl.so $EXTLIB_PATH && \
cd /srv/lamp/build/${php_name} && \
mv php.ini-production /etc/php.ini && \
# 写一下配置文件指定动态库地址
echo "[intl]" >> /etc/php.ini && \
echo "extension_dir = \"$EXTLIB_PATH\"" >> /etc/php.ini && \
echo "extension=intl.so" >> /etc/php.ini && \
# 编译php的gd模组
cd /srv/lamp/build/${php_name}/ext/gd && \
phpize && \
./configure --with-php-config=/srv/lamp/${php_name}/bin/php-config && \
make -j$(nproc) && \
make install && \
cp modules/gd.so $EXTLIB_PATH && \
echo "[gd]" >> /etc/php.ini && \
echo "extension_dir = \"$EXTLIB_PATH\"" >> /etc/php.ini && \
echo "extension=gd.so" >> /etc/php.ini && \
# 清理下环境
yum remove -y gcc \
gcc-c++ \
make \
wget \
openssl-devel \
libxml2-devel \
bzip2-devel \
perl-devel \
sqlite-devel \
libcurl-devel \
libicu-devel \
freetype-devel \
libpng-devel \
libjpeg-devel && \
rm -rf /srv/lamp/build
WORKDIR /srv/lamp
EXPOSE 80
ENTRYPOINT [ "/bin/bash" ]
|