PHP-FPM Docker 使用示例

php-fpm docker简单示例,基本结构nginx宿主机,php-fpm使用docker

运行php-fpm docker

下载php-fpm镜像,这里使用alpine版本,php版本7.0(也可以选择最新7.4)

docker pull php:7.0-fpm-alpine

运行,php-fpm默认端口9000,这里宿主机19000映射。

docker run --name php-fpm-alpine -d -p 19000:9000 php:7.0-fpm-alpine

进入docker

docker exec -it php-fpm-alpine sh
cd /var/www/html

新建test.php

<?php

echo "php-fpm-alpine";

查看默认扩展

php -m

[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

nginx 配置

server {
    listen 18080;
    server_name  _;
    charset utf-8;
    root  /var/www/html;
    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:19000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }
}

查看效果:

curl localhost:18080/test.php
php-fpm-alpine
updatedupdated2020-04-292020-04-29
Load Comments?