php基于docker的环境安装

前言

本文主要参考:https://www.zhihao1.cn/91.html

主要介绍docker搭建php,docker安装使用请自查

docker拉取nginx和php镜像

docker pull nginx:latest
docker pull php:7.4-fpm


 创建容器

1.先创建ngix文件夹存放等会php文件要挂载的目录,我创建在/docker/nginx/www/myphp目录的

mkdir -p /docker/nginx/www/myphp

2.创建容器

docker run --name myphp -v /docker/nginx/www/myphp:/www/myphp -d c5fdabeef32a

3.创建conf、conf.d目录

mkdir -p /docker/nginx/conf/conf.d

创建自己的conf文件,可以自己命名

vim myphp.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/myphp/$fastcgi_script_name;
        include        fastcgi_params;
    }
}

4.创建运行nginx的容器,打通nginx与php容器之间的关联

docker run --name nginx1 -p 8088:80 -d \
-v /docker/nginx/www:/usr/share/nginx/html \
-v /docker/nginx/conf/conf.d:/etc/nginx/conf.d \
--link myphp:php nginx

5.测试

在我们之前创建的/docker/nginx/www/myphp文件夹中创建一个index.php

cd /docker/nginx/www/myphp
vim index.php
<?php
echo phpinfo();
?>

访问输入你的IP地址xxx.xxx.xx.xx:8088/index.php

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值