dongyongmin5711 2017-09-18 06:26 采纳率: 100%
浏览 765
已采纳

如何通过unix socket设置Apache2和PHP-FPM?

我尝试通过unix套接字设置Apache2和PHP-FPM,但结果是 (111)连接被拒绝:AH02454:FCGI:尝试连接到Unix域套接字/run/php/php7.2-fpm.sock(*)失败 docker-compose.yml

version: "2"
services:
    php:
        build: "php:7.2-rc-alpine"
        container_name: "php"
        volumes:
            - "./code:/usr/local/apache2/htdocs"
            - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock"
    apache2:
        build: "httpd:2.4-alpine"
        container_name: "apache2"
        volumes:
            - "./code:/usr/local/apache2/htdocs"
            - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock"
        ports:
            - 80:80
        links:
            - php

www.conf

listen = /run/php/php7.2-fpm.sock

httpd-vhosts.conf

<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>

但是通过TCP连接时可以使用。

www.conf

listen = 127.0.0.1:9000

httpd-vhosts.conf

<FilesMatch \.php$>
    SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
  • 写回答

1条回答 默认 最新

  • dongsu3664 2017-09-20 15:33
    关注

    Okie, so have the repo helped to fix the issue.

    Issue #1 - www.conf being copied in apache container

    You had below statement in your apache container Dockerfile

    COPY ./www.conf /usr/local/etc/php-fpm.d/www.conf
    

    This is actually intended for the php container which will be running php-fpm and not the apache container

    Issue #2 - Socket was never being created

    Your volume bind - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock" was creating the socket and they were not being created by php-fpm as such. So you created a blank file and trying to connect to it won't do anything

    Issue #3 - No config in php to create socket

    The docker container by default create listen to 0.0.0.0:9000 inside the fpm container. You needed to override the zz-docker.conf file inside the container to fix the issue.

    zz-docker.conf

    [global]
    daemonize = no
    
    [www]
    listen = /run/php/php7.2-fpm.sock
    listen.mode = 0666
    
    Updated docker file
    FROM php:7.2-rc-fpm-alpine
    
    LABEL maintainer="Eakkapat Pattarathamrong (overbid@gmail.com)"
    RUN docker-php-ext-install \
            sockets
    
    RUN set -x \
            && deluser www-data \
            && addgroup -g 500 -S www-data \
            && adduser -u 500 -D -S -G www-data www-data
    
    COPY php-fpm.d /usr/local/etc/php-fpm.d/
    

    Issue #4 - Sockets being shared as volumes to host

    You should be sharing sockets using a named volume, so the socket should not be on host at all.

    Updated docker-compose.yml
    version: "2"
    services:
        php:
            build: "./php"
            container_name: "php"
            volumes:
                - "./code:/usr/local/apache2/htdocs"
                - "phpsocket:/run/php"
        apache2:
            build: "./apache2"
            container_name: "apache2"
            volumes:
                - "./code:/usr/local/apache2/htdocs"
                - "phpsocket:/run/php"
            ports:
                - 7080:80
            links:
                - php
    volumes:
      phpsocket:
    

    After fixing all the issues I was able to get the php page working

    PHP-FPM

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器