前言
- 在前一篇文章中, 我们已经搭建LAMP环境, 但php没有安装扩展, 这篇文章将安装PHP扩展, 实现正常的PHP项目部署
- 我在git中查找到一个简易安装PHP扩展的方法(GitHub - mlocati/docker-php-extension-installer: Easily install PHP extensions in Docker containers).
- 通过这个方法, 安装PHP扩展, 优点是编辑Dockerfile文件时简单快捷, 填写要用的扩展名即可. 缺点是安装的时间较长, 需耐心等待. 另说明下, 这种方法构建完镜像后, 会自动清除镜像中无用的文件, 这个很赞.
支持的PHP扩展列表
Extension | PHP 5.5 | PHP 5.6 | PHP 7.0 | PHP 7.1 | PHP 7.2 | PHP 7.3 | PHP 7.4 | PHP 8.0 | PHP 8.1 | PHP 8.2 | PHP 8.3 |
---|---|---|---|---|---|---|---|---|---|---|---|
amqp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
apcu | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
apcu_bc | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
ast | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
bcmath | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
bitset | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
blackfire | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
bz2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
calendar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
cassandra* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
cmark | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
csv | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
dba | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ddtrace* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
decimal | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
ds | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
ecma_intl* | ✓ | ✓ | |||||||||
enchant | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ev | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
event | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
excimer | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
exif | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ffi | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
ftp | ✓ | ✓ | |||||||||
gd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gearman | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
geoip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
geos* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
geospatial | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gettext | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gmagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gnupg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
grpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
http | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
igbinary | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
imagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
imap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
inotify | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
interbase | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
intl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ion | ✓ | ✓ | ✓ | ||||||||
ioncube_loader | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
jsmin | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
json_post | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
jsonpath | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
ldap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
luasandbox | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
lz4* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
lzf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
mailparse | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
maxminddb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
mcrypt | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
memcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
memcached | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
memprof* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
mongo | ✓ | ✓ | |||||||||
mongodb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
mosquitto | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
msgpack | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
mssql | ✓ | ✓ | |||||||||
mysql | ✓ | ✓ | |||||||||
mysqli | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
newrelic | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
oauth | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
oci8 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
opcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
opencensus | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
openswoole | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
opentelemetry | ✓ | ✓ | ✓ | ✓ | |||||||
parallel* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
parle* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
pcntl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pcov | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
pdo_dblib | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pdo_firebird | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pdo_mysql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pdo_oci | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
pdo_odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pdo_pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pdo_sqlsrv* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
php_trie | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
pkcs11 | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
pq | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
propro | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
protobuf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pspell | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
pthreads* | ✓ | ✓ | ✓ | ||||||||
raphf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
rdkafka | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
recode | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
redis | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
relay | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
saxon* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
seasclick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
seaslog | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
shmop | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
simdjson* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
smbclient | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
snappy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
snmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
snuffleupagus | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
soap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sockets | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sodium* | ✓ | ✓ | ✓ | ||||||||
solr | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sourceguardian | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
spx | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sqlsrv* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
ssh2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
stomp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
swoole | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sybase_ct | ✓ | ✓ | |||||||||
sync | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sysvmsg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sysvsem | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
sysvshm | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
tensor | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
tideways | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
tidy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
timezonedb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
uopz | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
uploadprogress | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
uuid | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
uv | ✓ | ✓ | ✓ | ✓ | |||||||
vips* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
vld | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
wddx | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
wikidiff2* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
xdebug | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
xdiff | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
xhprof | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
xlswriter | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
xmldiff | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
xmlrpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
xsl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
yac | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
yaml | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
yar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
zephir_parser | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
zip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
zmq | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
zookeeper | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
zstd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
目录结构
web/ /web/目录
|
├─ mysql/ mysql目录
| ├─ conf/ 配置文件目录
| | └─ my.cnf 配置文件
| ├─ log/ 日志目录
| └─ data/ 数据目录
|
├─ redis/ redis目录
| ├─ conf/ 配置文件目录
| | └─ my.cnf 配置文件
| ├─ log/ 日志目录
| └─ data/ 数据目录
|
├─ laoliu_pro/ 项目目录
| ├─ conf/ nginx配置文件目录
| | ├─ php.ini php.ini
| | └─ 000-default.conf apache配置文件
| ├─ html/ 项目目录
| | └─ index.html 项目文件, 这里是一个文件, 正常情况下可能会有多个文件
| ├─ log/ 日志目录
| └─ Dockerfile Dockerfile文件
|
└─ docker-compose.yaml docker-composer的配置文件
docker-compose.yaml配置文件说明
对照上一篇文章, 只是修改了build字段. 如果有已经构建好的镜像, 可以使用image字段直接指定镜像.
version: '3'services: laoliu_pro:build:# dockerfile所在的目录context: ./laoliu_pro# dockerfile的文件名dockerfile: Dockerfileports:- "80:80"- "443:443"volumes:- /etc/localtime:/etc/localtime:ro- ./laoliu_pro/log:/var/log/apache2:rw - ./laoliu_pro/html:/var/www/html:rw # apache配置目录- ./laoliu_pro/conf/000-default.conf:/etc/apache2/sites-available/000-default.conf:ro# php.ini- ./laoliu_pro/conf/php.ini:/usr/local/etc/php/php.inicontainer_name: laoliu_pro# 服务名mysql:restart: always# mysql镜像, 可选5.7或8image: mysql:5.7environment:# root密码MYSQL_ROOT_PASSWORD: 1234@5678# 允许远程连接MYSQL_ROOT_HOST: '%'# 挂载卷 <宿主机路径>:<容器路径>volumes:# docker时间同步- /etc/localtime:/etc/localtime:ro# 映射日志目录- ./mysql/log:/var/log/mysql# 映射配置目录- ./mysql/conf:/etc/mysql/mysql.conf.d:rw# 映射数据目录- ./mysql/data:/var/lib/mysql:rw# 容器名称container_name: mysql# 端口映射 <宿主机端口>:<容器端口>ports:- 3306:3306# 服务名redis:restart: always# redis镜像image: redis:5-alpine# 挂载卷 <宿主机路径>:<容器路径>volumes:# docker时间同步- /etc/localtime:/etc/localtime:ro# 映射配置目录- ./redis/conf:/etc/redis:ro# 映射数据目录- ./redis/data:/data:rw# 容器名称container_name: redis# 端口映射 <宿主机端口>:<容器端口>ports:- 6379:6379hostname: redis# 在容器启动后执行的命令command: redis-server /etc/redis/redis.conf
Dockerfile说明
# 这里使用的是php:5.6-apache镜像
FROM php:5.6-apacheADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/# apache开启伪静态
RUN a2enmod rewrite# 安装扩展
RUN install-php-extensions gd \&& install-php-extensions iconv \&& install-php-extensions opcache \&& install-php-extensions zip \&& install-php-extensions pdo_mysql \&& install-php-extensions bcmath pcntl \&& install-php-extensions sockets \&& install-php-extensions sysvmsg \&& install-php-extensions mysqli \&& install-php-extensions redis \&& install-php-extensions gettext \&& install-php-extensions intl \&& install-php-extensions mcrypt \&& install-php-extensions mysql \&& install-php-extensions shmop \&& install-php-extensions soap \&& install-php-extensions xmlrpc
启动容器
# 启动容器
docker-compose up -d
构建镜像
# 构建镜像
docker build -t laoliu_pro/php56_apache:v1 /web/laoliu_pro
apache配置文件(同上一篇文章)
文件路径: /web/laoliu_pro/conf/000-default.conf
<VirtualHost *:80>ServerName laoliu.proServerAlias laoliu.proDocumentRoot /var/www/html/public<Directory /var/www/html/public>DirectoryIndex index.php index.html index.htmOptions Indexes FollowSymLinksAllowOverride AllOrder allow,denyallow from allRequire all granted</Directory>ErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
PHP项目(同上一篇文章)
PHP项目直接部署到/web/laoliu_pro/html中即可. 记得修改数据库配置文件
php.ini(同上一篇文章)
如果需要修改运行内存, 上传设置, 超时时间等, 则需要补充/web/laoliu_pro/conf/php.ini文件. 若只是使用默认设置, 则可以在docker-compose.yaml中去掉php.ini的映射.