使用docker搭建适合thinkphp6的lnmp+redis开发环境

143 篇文章 1 订阅

nginx版本为最新版本
php版本为7.3
mysql版本为5.7
redis版本为5.0

docker-compose.yml文件配置如下:

version: '3'

services:
  nginx:
    build: nginx/
    container_name: nginx
    ports: 
    - 80:80
    volumes: 
    - ./html:/var/www/html
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/conf/conf.d:/etc/nginx/conf.d
    networks: 
      nw:
        ipv4_address: 192.168.0.2
  php:
    build: php/
    container_name: php
    volumes: 
    - ./html:/var/www/html
    networks:
      nw:
        ipv4_address: 192.168.0.3
  mysql:
    image: "mysql:5.7"
    container_name: mysql
    volumes:
    - ./mysql/data:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=root
    networks:
      nw:
        ipv4_address: 192.168.0.4
  redis:
    image: "redis:5"
    container_name: redis
    ports:
    - 6379:6379
    volumes:
    - ./redis5/conf:/usr/local/etc/redis
    - ./redis5/data:/data
    environment:
    - TZ=Asia/shanghai
    networks:
      nw:
        ipv4_address: 192.168.0.5
networks:
  nw:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 192.168.0.0/16

thinkphp6的代码放到html目录下面
执行docker-compose up -d ,启动容器

[root@localhost lnmp]# docker-compose up -d
Creating network "lnmp_nw" with driver "bridge"
Creating redis ... done
Creating mysql ... done
Creating nginx ... done
Creating php   ... done


代码下载

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
使用Docker搭建一套简单的PHP+Nginx环境可以按照以下步骤进行: 1. 安装DockerDocker Compose。 2. 创建一个新的目录,用于存放Docker Compose文件和相关配置文件。 3. 在该目录下创建一个名为docker-compose.yml的文件,并添加以下内容: ``` version: '3' services: web: image: nginx:latest ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf - ./html:/usr/share/nginx/html depends_on: - php php: image: php:7.4-fpm volumes: - ./html:/var/www/html ``` 4. 在该目录下创建一个名为nginx.conf的文件,并添加以下内容: ``` worker_processes 1; events { worker_connections 1024; } http { sendfile on; server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php:900; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } } } ``` 5. 在该目录下创建一个名为html的目录,并在该目录下创建一个名为index.php的文件,并添加以下内容: ``` <?php phpinfo(); ?> ``` 6. 在终端中进入该目录,并运行以下命令: ``` docker-compose up -d ``` 7. 打开浏览器,访问http://localhost,即可看到PHP信息页面。 以上就是使用Docker搭建一套简单的PHP+Nginx环境的步骤。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

reg183

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值