php5-fpm.sock 未在 /var/run 中找到/创建

php5-fpm.sock not found / created in /var/run

我无法连接到 php5-fpm.sock。我尝试了很多解决方案,但仍然出现此错误:

2017/11/20 11:17:21 [crit] 9670#9670: *1 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.224.8, server: babylon, request: "GET /webmail/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "babylon"

我的配置是这样的:

location /webmail {
        alias /srv/roundcubemail;
        index index.php index.html;
        # Favicon
        location ~ ^/webmail/favicon.ico$ {
                root /srv/roundcubemail/skins/classic/images;
                log_not_found off;
                access_log off;
                expires max;
        }
        # Robots file
        location ~ ^/webmail/robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
        # Deny Protected directories 
        location ~ ^/webmail/(config|temp|logs)/ {
                 deny all;
        }
        location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
                deny all;
        }
        location ~ ^/webmail/(bin|SQL)/ {
                deny all;
        }
        # Hide .md files
        location ~ ^/webmail/(.+\.md)$ {
                deny all;
        }
        # Hide all dot files
        location ~ ^/webmail/\. {
                deny all;
                access_log off;
                log_not_found off;
        }
        #Roundcube fastcgi config
        location ~ /webmail(/.*\.php)$ {
                error_log /var/log/nginx/x.log error;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_split_path_info ^/webmail/(.+\.php)(/.*)$;
                fastcgi_index index.php;
                #fastcgi_param SCRIPT_FILENAME /srv/roundcubemail/$fastcgi_script_name;
                fastcgi_param SCRIPT_FILENAME /srv/roundcubemail/index.php;
                fastcgi_param PATH_INFO $fastcgi_path_info;
        }
}

可能是目录权限问题?我不这么认为。 我所做的尝试是:

有什么办法可以解决这个问题吗?

首先,确保安装了php-fpm,如果有的话你可以用它来检查当前版本:

php-fpm -v

其次检查 php-fpm.conf 配置,并搜索这一行:

listen = /tmp/php-fpm.socket

如果它不存在就添加它,它也可以是这样的:

listen = /var/run/php5-fpm.sock

在某些 Linux 发行版中通常使用:

listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

如果您想使用 TCP 套接字:

Listen 127.0.0.1:9000

重新启动php-fpm并检查套接字是否已在使用Unix domain socket的情况下创建,这可以通过这样做来完成:

$ file /var/run/php5-fpm.sock

如果套接字存在,应该打印出如下内容:

/var/run/php5-fpm.sock: socket

能否请您确保 PHP-fpm/www.conf 文件中的这些设置

.....
user = www-data
group = www-data

listen.owner = www-data
listen.group = www-data
......

然后在root用户下重启PHP-fpm。

listen.owner = nginx
listen.group = nginx