docker 容器安装php-fpm和nginx
拉取 7.2-fpm-alpine官方镜像
docker pull php:7.2-fpm-alpine
启动php-fpm
docker run --name test-php -d \
-v /home/mynginx/html:/var/www/html \
-v /home/myphpini:/usr/local/etc/php \
php:7.2-fpm-alpine
从docker容器中将/php.ini-production复制并重命名为php.ini到宿主机上。
docker cp test-php:/usr/local/etc/php/php.ini-production /home/myphpini/php.ini
nginx:1.13.0-alpine
docker pull nginx:1.13.0-alpine
编辑 nginx 配置文件 /home/mynginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
启动nginx
docker run --name test-nginx -p 80:80 -d \
-v /home/mynginx/html:/usr/share/nginx/html \
-v /home/mynginx/conf.d:/etc/nginx/conf.d \
--link test-php:php \
nginx:1.13.0-alpine
测试结果
在 /home/mynginx/html 新建 index.php 文件
<?php phpinfo();