docker 安装 php +nginx 记录

我的环境CentOS 7.5

首先安装 nginx

docker pull nginx
docker pull php:7.1.30-fpm

安装完成之后进行配置,首先要确定网站目录、nginx配置文件目录

mkdir /var/www
mkdir /etc/conf
cd /var/conf
vim test.conf

输入以下内容

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    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  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }

其中root   /usr/share/nginx/html 这个地方是指网站目录,要记住,挂载nginx目录时要用。fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name; 这个目录也很重要,挂载PHP目录的时候会用

启动php,挂载本地目录,注意,启动nginx也必须挂载这个目录:/var/www

docker run --name  myphp7 -v /var/www:/www -d php:7.1.30-fpm
docker run --name php-nginx -p 8800:80 -v /var/www:/usr/share/nginx/html -v /var/conf:/etc/nginx/conf.d -d --link myphp7:php nginx

启后后新建一个PHP测试一下:

cd /var/www
vim info.php

输入

<?php
    phpinfo();
?>

看看能否打开

curl localhost:8000/info.php

结果返回403 Forbidden

因为是CentOS7,尝试关闭SeLinux

vim /etc/selinux/config

SELINUX=disabled

保存重试,仍然返回403 Forbidden。尝试修改权限

chmod -R 777 /var/www/

OK!

猜你喜欢

转载自www.cnblogs.com/yesok/p/12892826.html