Docker nginx + php7.3 + mysql 环境搭建笔记

【下载nginx镜像】

docker pull nginx

【下载 PHP 镜像】

docker pull php:7.3.5-fpm

linux创建目录:

mkdir -p ~/nginx/www ~/nginx/conf/conf.d  ~/data/mysql

【创建并运行 php 容器】

docker run --name myphp -v ~/nginx/www:/www -d php:7.3-fpm

【Nginx配置文件】
在该目录下添加 ~/nginx/conf/conf.d/test.conf 文件,内容如下:

sudo vi ~/nginx/conf/conf.d/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;
    }
}

配置文件说明:
php:9000: 表示 php-fpm 服务的 URL,下面我们会具体说明。
/www/: 是 myphp-fpm 中 php 文件的存储路径,映射到本地的 ~/nginx/www 目录。


【创建并运行 nginx 容器】

docker run --name mynginx -p 80:80 -d \
-v ~/nginx/www:/user/share/nginx/html:ro \
-v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
--link myphp:php \
nginx

【下载 mariadb 镜像】

docker pull mariadb

【创建并运行 mysql 容器】

docker run -v ~/data/mysql/:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 \
--privileged=true --restart unless-stopped   --name mariadbs -d mariadb:latest

注:MYSQL_ROOT_PASSWORD=123456  设置数据库用户root的初始密码为123456

【tp5 网站配置】

server {
    listen       80;
    server_name  test.com;
    #/tp/ 为thinkphp站点
    #/usr/share/nginx/html/tp/public 为网站根目录
    location / {
        root   /usr/share/nginx/html/tp/public;
        index  index.php index.html index.htm;
    if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
    }
    }

    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;
        #/www/tp/public/ 为网站根目录
        fastcgi_param  SCRIPT_FILENAME  /www/tp/public/$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值