zoukankan      html  css  js  c++  java
  • fpm + nginx alpine docker 运行

    就是一个简单的php docker 环境

    环境准备

    • 项目结构
    ├── Dockerfile
    ├── README.md
    ├── app
    │   ├── app.php
    │   ├── composer.json
    │   ├── composer.lock
    │   ├── index-xhprof.php
    │   ├── index.php
    │   ├── perf
    │   └── vendor
    ├── docker-compose.yaml
    ├── nginx.conf
    ├── php.conf
    ├── php.ini
    └── supervisor.conf
    • Dockerfile
      集成了perf,可以进行perf 分析
     
    FROM alpine
    ENV TZ Asia/Shanghai
    # first add mirror for alpine repos
    RUN set -x 
        && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
    RUN apk update && apk add  --no-cache nginx nginx-debug php7-fpm  php7-json  perf  tzdata  && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
    CMD ["/usr/local/bin/supervisord","-c","/etc/supervisor.conf"]
    • docker-compose 文件
    version: "3"
    services:
      web: 
         build: ./
         volumes:
         - "./php.conf:/etc/nginx/conf.d/default.conf"
         - "./nginx.conf:/etc/nginx/nginx.conf"
         - "./app:/opt/app"
         - "./supervisor.conf:/etc/supervisor.conf"
         privileged: true
         cap_add:
           - ALL
         ports:
         - "80:80"
         - "8080:8080"
         - "9001:9001"
    • supervisor.conf
      使用了一个golang 版本的supervisord,简单方便
     
    [program:nginx]
    command = nginx -g  "daemon off;"
    autorestart = true
    user = root
    depends_on = mkdir-nginx
    [program:fpm]
    command = php-fpm7 -F
    autorestart = true
    [inet_http_server]
    port = :9001
    [program:mkdir-nginx]
    command = mkdir -p /run/nginx
    • nginx 配置
      主要是php-fpm 配置
     
    server {
           listen 80;
           charset utf-8;
           default_type text/html;
           location / {
                root /opt/app; 
                index index.php;
            }
           location ~ .php$ {
               fastcgi_pass 127.0.0.1:9000;
               root           /opt/app; 
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
               include        fastcgi_params; 
            }
            location ~ /.ht {
                    deny all;
            }
            error_page 404 /404.html;
    }
    • php 代码
      index.php
     
    <!DOCTYPE html>
    <html>
    <body>
    <?php
    include "app.php";
    echo "<div>Hello World!</div>"
    ?>
    </body>
    </html>

    app.php
    集成shortid 基于composer 管理

     
    <?php
    require_once 'vendor/autoload.php';
    use PUGXShortidShortid;
    $id = Shortid::generate();
    echo $id;
    ?>
     

    composer.json

    {
        "name": "dalong/app",
        "type": "project",
        "require": {
            "pugx/shortid-php": "^0.7.0"
        },
        "authors": [
            {
                "name": "rong",
                "email": "1141591465@qq.com"
            }
        ]
    }

    参考资料

    https://github.com/rongfengliang/php-nginx-docker

  • 相关阅读:
    python通过帐号和密码访问mysql
    pyqt5简单登陆界面
    PyQt5点击按钮产生新窗体
    ubuntu访问win10下的磁盘
    python平均值和加权平均值
    牛顿迭代法求高次方程的根
    运用模逆运算(同余方程)来解决Matlab课上的一道思考题
    线程实现方式与临界区保护
    线程调度的问题:Lock Convoy(锁封护)与Priority Inversion(优先级反转)
    C++ lvalue,prvalue,xvalue,glvalue和rvalue详解(from cppreference)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14213225.html
Copyright © 2011-2022 走看看