Back to blog

Nginx downloading PHP files in aaPanel? Fixing “Address already in use” and orphan sockets

7/16/2025 · 2 min · Infrastructure

Share

If your browser starts downloading index.php instead of rendering the page, the issue is usually a broken integration between Nginx and PHP-FPM.

This guide covers root causes and a recovery sequence for Address already in use, orphan processes, and mixed-content side effects.

1. Symptom: PHP gets downloaded instead of executed

This happens when Nginx cannot forward PHP requests to PHP-FPM. Typical causes:

2. Critical error: Address already in use

You may see this even after restart:

[emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)

This usually means orphaned Nginx workers still hold ports 80/443.

Forced cleanup

killall -9 nginx
netstat -tulpn | grep -E ':80|:443'
systemctl start nginx

3. PHP-FPM shows active (exited) in aaPanel

This status often means systemd lost track of the real worker PID.

If socket path (e.g. /tmp/php-cgi-80.sock) is missing or inaccessible, Nginx cannot execute PHP and may return the file as download.

Recommended fixes

chown -R www:www /home/usuario/public_html
/etc/init.d/php-fpm-80 reload

If immutable file blocks ownership changes:

chattr -i .user.ini

4. Modal/AJAX breakage: Mixed Content (HTTPS vs HTTP)

If direct access works but modal/AJAX requests fail, mixed content is likely.

http:// requests from an HTTPS page can be blocked and trigger odd fallback behavior, including file download responses.

Fixes

  1. Enforce HTTPS with 301 redirect.
  2. Use relative JS URLs (/script.php) instead of hardcoded http://.
  3. Add CSP upgrade header.
add_header Content-Security-Policy "upgrade-insecure-requests";

5. Recovery command sequence

# Clean orphan nginx workers and start clean service
killall -9 nginx && systemctl start nginx

# Restart active php-fpm pool
pkill -9 php-fpm && systemctl restart php-fpm-80

# Validate socket and ownership
ls -la /tmp/php-cgi-80.sock

In most incidents, root cause is a combination of:

After process cleanup, permission alignment, and HTTPS standardization, Nginx and PHP-FPM return to normal behavior.

CC BY-NC

This post is licensed under CC BY-NC.

Comments

Join the discussion below.