Docker 安装 PHP+Mysql+Nginx

Docker Setup

yum install -y yum-utils device-mapper-persistent-data
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce

配置

systemctl start docker
systemctl enable docker

Mysql

创建容器

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name m_mysql mysql:5.7

进入容器:

docker exec -it m_mysql /bin/bash

  1. 进入mysql

mysql -uroot -proot

  1. 选择数据库
use mysql

  1. 开启远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

  1. 重启

docker restart m_mysql

PHP

创建容器

docker run -d -p 9000:9000 -v /data/wwwroot:/usr/share/nginx/html --link m_mysql:mysql --name m_phpfpm bitnami/php-fpm:7.0

进入容器

docker exec -it m_phpfpm /bin/bash

Nginx

创建容器

docker run -d -p 80:80 -v /data/wwwroot:/usr/share/nginx/html -v /data/nginx:/etc/nginx -v /data/wwwlogs:/var/log/nginx --link m_phpfpm:phpfpm --name m_nginx nginx:latest

修改/data/nginx/conf/default.conf,配置如下:

server {
    listen       80;
    server_name  _;
    #charset koi8-r;
    access_log  /var/log/nginx/default_nginx.log  main;
    location / {
        root   /usr/share/nginx/html/default;
        index  index.php index.html index.htm;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html/default;
        fastcgi_pass   phpfpm:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


参考链接:https://notemi.cn/docker-quickly-set-up-php-nginx-mysql-environment.html

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、准备工作: 使用工具: 1.主流版本的docker,本人使用的是 docker 1.91 版本 2.cento...
    dreamer_lk阅读 7,643评论 1 8
  • 一、Docker简介 1、Docker是什么? 是一个开源的容器引擎,基于go语言开发 2、特点 轻量级,可移植的...
    chuckielove阅读 5,612评论 0 2
  • 在同一个坑里摔过一次,大不了再爬起,告诉自己下次别再摔了,这次是不小心!如果你被同一个人伤害两次,那就是你自...
    爱秀晶的丫丫阅读 2,325评论 0 0
  • 多空双方力量较量, 当多方力量大时,入场做多;当空方力量大时, 入场做空。 在市场里, 你我都弱小如尘埃,顺势而为...
    老孙2018阅读 1,067评论 0 0
  • 又到开学季,虽然也是热热闹闹,却总觉得空气里少了点什么。意外地接到儿时姐妹的电话,见到那个依然梳着黑黝黝的大长辫子...
    濯明月于涟漪阅读 3,034评论 3 1

友情链接更多精彩内容