欢迎访问广西陌上网络科技有限责任公司官网 · 专注企业数字化管理软件定制开发 客服热线:黄生 15678982250

DOCKER部署PHP环境

更新时间:2023-10-05 浏览:3300 标签:DOCKER PHP 

DOCKER下PHP部署的几个步骤


1、下载PHP镜像

docker pull php

#其他版本

docker pull php:7.4

#其他大神整理好插件的PHP版本

docker pull mhzuhe/php-fpm:8.2
docker pull mhzuhe/php-fpm:7.4


2、建立映像目录

mkdir -p /home/www

docker run --name myphp --privileged=true -v /home/www:/www-d 38f2b691dcb8

#38f2b691dcb8是镜像ID

#--privileged=true 使DOCKER内具有权限

学习过程中碰到file not found的问题,困扰了很久,偶然在一个大佬的资料里看到PHP容器也有这个指令,加上来就能正常解析PHP文件。

重点:映像目录需和nginx的映像目录一致


3、新建一个NGINX容器,连接到PHP容器

docker run --name nginx8001 -p 8001:8001 -d \

-v /home/www:/usr/share/nginx/html \

-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \

--link myphp nginx


#参数 --link myphp中的myphp是PHP容器的名称


4、nginx的php站点配置

myphp.conf


server {

    listen 8001;

    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$ {

        #myphp是PHP容器的名称

        fastcgi_pass myphp:9000;

        fastcgi_index index.php;

        #/www是影响目录路径

        fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;

        include fastcgi_params;

    }

}