美文网首页
docker安装php环境

docker安装php环境

作者: 响呼雷 | 来源:发表于2023-10-31 09:18 被阅读0次

一、安装nginx
1.拉去nginx镜像

docker pull nginx //或者指定版本,docker pull nginx:1.21.5

2.准备default.conf和nginx.conf

这个随便安装一个nginx都是自带的,或者自己网上搜一下,不再贴代码了。

3.启动容器

docker run -d --name nginx -p 8888:80 -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/conf.d:/etc/nginx/conf.d -v /docker/nginx/html:/usr/share/nginx/html -v /docker/nginx/logs:/var/log/nginx nginx
说明
第一个nginx:可自定义,你想怎么起就怎么起,方便自己记忆就行
8888:80:主机8888端口映射容器80端口
-v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf:宿主机/docker/nginx/nginx.conf挂载到容器中/etc/nginx/nginx.conf中(后面的也是一样,不再一一说明)

主机目录结构

4.测试

[root@centos72 html]# cd /data/docker/nginx/html/
[root@centos72 html]# echo "this is test" > index.html
[root@centos72 html]# curl 127.0.0.1:80/index.html
this is test
//或者“主机ip:8888”浏览器访问测试

二、安装mysql
1.拉去mysql镜像

docker pull mysql:5.7.36

2.启动容器

docker run -d -p 3307:3306 -v /docker/mysql/logs:/var/log/mysql/ -v /docker/mysql/conf:/etc/mysql/conf.d -v /docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root123456 --name mysql mysql:5.7.36


主机目录结构

3.测试

[root@VM-8-2-centos html]# mysql -uroot -proot123456 -h127.0.0.1 -P3307
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>

三、安装php
1.拉去php镜像

docker pull php:7.4-fpm

2.启动容器

docker run -d --name php-fpm -p 9001:9000 -v /docker/nginx/html:/var/www/html php:7.4-fpm

3.修改nginx配置

location ~ \.php$ {
        #修改成PHP容器内的工作目录  
        root           html;
        #使php容器网络连接docker
        #inspect 容器ID | grep "IPAddress"
        fastcgi_pass   172.17.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

说明:下面两个报错分别“修改nginx配置”root参数和fastcgi_pass参数配置错误导致

image.png
image.png

相关文章

网友评论

      本文标题:docker安装php环境

      本文链接:https://www.haomeiwen.com/subject/aijbidtx.html