You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7下PHP-FPM 503错误:套接字存在但权限修改无效求助

Troubleshooting "Socket Exists" Error with PHP-FPM 5.6 & Apache on CentOS 7

Hey Pavel, let's work through this frustrating socket issue you're facing. I've debugged dozens of these on CentOS 7, so let's break down the most likely fixes step by step:

1. Stop manually setting socket permissions (they get overwritten!)

When you restart PHP-FPM, it recreates the socket file from scratch—so any manual chmod or chown changes get wiped out. You need to set the permissions directly in your PHP-FPM www.conf:

  • Open your www.conf file and add/locate these three lines:
    listen.owner = apache
    listen.group = apache
    listen.mode = 0660
    
  • This ensures every time PHP-FPM starts, it creates the socket with the exact permissions Apache needs (no need for risky 777 permissions).

2. Kill stale PHP-FPM processes

The "Socket Exists" error often pops up when a crashed PHP-FPM process is still holding onto the socket. Let's clean that up:

  • List all running PHP-FPM processes:
    ps aux | grep php-fpm
    
  • Kill any orphaned processes (look for entries that don't match your current running service):
    kill -9 <PID>
    
  • Restart PHP-FPM properly:
    systemctl restart php56-fpm
    

3. Verify Apache's ProxyPassMatch configuration

Double-check that your Apache virtual host is pointing to the exact same socket path as PHP-FPM:

  • In your httpd.conf virtual host block, confirm the ProxyPassMatch line looks like this (adjust the document root to match your setup):
    ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/tmp/php56-fpm.sock|fcgi://localhost/var/www/your-document-root
    
  • Typos here (like missing 56 in the socket name) are a super common culprit.

4. Check SELinux (the silent CentOS 7 troublemaker)

CentOS 7 enables SELinux by default, and it often blocks Apache from accessing PHP-FPM sockets even if file permissions are correct:

  • Test if SELinux is the issue by temporarily disabling it:
    setenforce 0
    
  • If the error goes away, don't leave SELinux disabled—fix it properly with these commands:
    # Allow Apache to connect to FPM sockets
    setsebool -P httpd_can_network_connect 1
    # Apply correct SELinux context to your socket
    semanage fcontext -a -t httpd_sys_rw_content_t "/tmp/php56-fpm.sock"
    restorecon -v /tmp/php56-fpm.sock
    

5. If all else fails: Move the socket out of /tmp

The /tmp directory has special cleanup rules on CentOS 7 that can sometimes delete or mess with sockets. Try moving it to a dedicated directory:

  • Create a directory for PHP-FPM sockets:
    mkdir -p /var/run/php-fpm
    chown apache:apache /var/run/php-fpm
    
  • Update www.conf to use the new path:
    listen = /var/run/php-fpm/php56-fpm.sock
    
  • Update your Apache ProxyPassMatch line to match the new path, then restart both Apache and PHP-FPM.

内容的提问来源于stack exchange,提问作者Pavel Novák

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:05:00