美文网首页
Mysql+PHP+Nginx 部署ecshop #docker

Mysql+PHP+Nginx 部署ecshop #docker

作者: 钾肥尔德 | 来源:发表于2020-02-22 11:04 被阅读0次

准备

  • ecshop源码
/var/www/ecshop    # ecshop h5代码
/var/www/apiserver # app代码
  • images
docker pull mysql:5.6.47  // mysql
docker pull php:7.2.28-fpm  // php
docker pull nginx:1.17.8  // nginx
  • 权限
chmod -R 777 /var/www/ecshop
chmod -R 777 /var/www/apiserver
# 不设为777的话容器内映射到容器后容器无法写文件
  • nginx.conf
# ~/nginx/conf/conf.d/test-vhost.conf
server
    {
        listen 80;
        server_name www.ecshop-test.com;
        index index.php;
        root  /usr/share/nginx/html/ecshop/;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires   30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires   12h;
        }

        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        location ~ \.php$ {
            fastcgi_pass   php:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; # root文件夹设为其他用户允许
            include        fastcgi_params;
        }
    }

部署容器

  • Mysql

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6.47
# extra flag
-v /usr/local/mysql:/etc/mysql/sqlinit  # 将宿主机的sql数据库数据文件映射到docker mysql容器

打开mysql远程访问

docker exec -it mysql /bin/bash # 进入mysql容器
mysql -u root -p  # 然后输入root的password
create database ecshop;  # 先建个库,待会安装ecshop时会用到
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '112233AbC' WITH GRANT OPTION;
flush privileges;
exit;
  • PHP

docker run --name myphp-fpm -v /var/www:/usr/share/nginx/html --link  mysql:mysql -d php:7.2.28-fpm
# /usr/share/nginx/html: 是 myphp-fpm 中 php 文件的存储路径,映射到本地的 ~/nginx/www 目录
# --link  mysql:mysql 将mysql容器链接到php容器所在的网桥上
  • Nginx

docker run --name php-nginx -p 80:80 -d \
    -v /var/www:/usr/share/nginx/html \
    -v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
    --link myphp-fpm:php \
    nginx:1.17.8
# /var/www: 是本地 html 文件的存储目录,/usr/share/nginx/html 是容器内 html 文件的存储目录
# ~/nginx/conf/conf.d: 是本地 nginx 配置文件的存储目录,/etc/nginx/conf.d 是容器内 nginx 配置文件的存储目录
# --link myphp-fpm:php: 把 myphp-fpm 的网络并入 nginx,并通过修改 nginx 的 /etc/hosts,把域名 php 映射成 127.0.0.1,让 nginx 通过 php:9000 访问 php-fpm
  • 安装php扩展

docker exec -it myphp-fpm /bin/bash
apt update
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2
docker-php-ext-install gd             # 安装GD库
docker-php-ext-install pdo pdo_mysql  # 安装mysql扩展
docker-php-ext-install mysqli
安装环境检测通过
  • #备注

安装时hostname需要填mysql,而不是localhost

相关文章

网友评论

      本文标题:Mysql+PHP+Nginx 部署ecshop #docker

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