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

我尝试通过unix socket设置Apache2和PHP-FPM但结果是</ p>

(111)连接被拒绝:AH02454:FCGI:尝试连接到Unix域套接字/run/php/php7.2-fpm.sock(*)失败</ p>

docker-compose .yml </ p>

  version:“2”
services:
php:
build:“php:7.2-rc-alpine”
container_name:“php”
卷:
  • “./ code:/usr/local/apache2/htdocs"
  • ”./php7.2-fpm.sock:/run/php/php7.2-fpm.sock" apache2:
    build:“httpd:2.4-alpine” container_name:“apache2” 卷:
  • “./ code:/usr/local/apache2/htdocs"
  • ”./php7.2-fpm .sock:/run/php/php7.2-fpm.sock“ ports:
  • 80:80 links:
  • php
    </ code> </ pre>

    www.conf p>

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

    httpd -vhosts.conf p>

     &lt; FilesMatch \ .php $&gt; 
    SetHandler“proxy:unix:/ run  /php/php7.2-fpm.sock|fcgi://localhost/"
    </FilesMatch>
    
    nn

    但是通过TCP连接时它可以正常工作。 nn

    www.conf

    nn

    listen = 127.0.0.1:9000

    nn

    httpd-vhosts.conf </ p>

     &lt; FilesMatch \ .php $&gt; 
    SetHandler“proxy:fcgi:// php:9000”
    &lt; / FilesMatch&gt; \ n </ code> </ pre>
    </ div>

展开原文

原文

我尝试通过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>

dongpai6567
dongpai6567 github.com/overbid/apache2-php.git
接近 3 年之前 回复
douhui9631
douhui9631 能否请您提供我可以测试的样品回购
大约 3 年之前 回复
douhuai2861
douhuai2861 是的和所有的apache,php使用uid和gid500来处理。与php7.2-fpm.sock的所有者相同
大约 3 年之前 回复
dongquweng5152
dongquweng5152 你看到在主机上创建的套接字文件了吗?
大约 3 年之前 回复

1个回答

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

dongxun2089
dongxun2089 是的,实际上socket上不需要x权限。 它应该只有0666,这对我来说很糟糕
接近 3 年之前 回复
douqiang1910
douqiang1910 谢谢答案,我只是将zz-docker.conf添加到php,一切正常。 PS。 我的listen.mode是0666
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问