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
    spice-vdagent
    no ia32-libs
    git conflict
    wget mirror
    docker !veth
    libprotobuff8.so not found
    angular 列表渲染机制
    Java测试技巧
    react组件生命周期
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14213225.html
Copyright © 2011-2022 走看看