AdminsForum
Guide Fix Nginx 502 After Changing PHP in aaPanel Free Edition - Printable Version

+- AdminsForum (https://adminsforum.com)
+-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels)
+--- Forum: aaPanel (https://adminsforum.com/Forum-aapanel)
+---- Forum: aaPanel Guides & Tutorials (https://adminsforum.com/Forum-aapanel-guides-tutorials)
+----- Forum: aaPanel PHP & Extensions Guides (https://adminsforum.com/Forum-aapanel-php-extensions-guides)
+----- Thread: Guide Fix Nginx 502 After Changing PHP in aaPanel Free Edition (/Thread-guide-fix-nginx-502-after-changing-php-in-aapanel-free-edition)



Fix Nginx 502 After Changing PHP in aaPanel Free Edition - DEV - 10-11-2026

Quick answer
A 502 after a PHP change often means Nginx cannot reach the selected PHP-FPM service. Check the website’s PHP version, that version’s service status, and the Nginx error log before changing anything. A 502 can also come from another application upstream.

1. Check the selected PHP version
Open Website → your domain → PHP Version. Confirm the intended version is installed. Save the selection again if the switch did not complete. Back up the site configuration before editing it.

2. Check PHP-FPM
Open App Store → Installed → the matching PHP version → Settings → Service. If stopped, start it. If startup fails, inspect its log first. Restart only the affected service after resolving the reported problem.

3. Read the Nginx error log
Open the website settings and its error log. “No such file or directory” for a Unix socket usually means the configured socket does not exist. “Connection refused” means the upstream is not accepting connections. A timeout needs a different investigation: slow code, resource limits, or the upstream application. Do not fix these by opening database ports or applying 777 permissions.

4. Correct the mismatch
Prefer aaPanel’s PHP Version selector so it generates the appropriate configuration. If custom Nginx rules override PHP handling, back them up and inspect the conflicting fastcgi_pass setting. Use the actual socket of the installed version, not a copied path from another server. Test Nginx configuration before reloading.

Our controlled test
Tested 11 October 2026 on Ubuntu 22.04, aaPanel Free Edition 8.0.6, Nginx 1.30.5 and website PHP 8.5.11. We deliberately pointed one temporary PHP URL to a nonexistent socket. That URL returned HTTP 502 while the homepage and WordPress remained HTTP 200. The screenshot uses our original branded error page.

[Image: attachment.php?aid=28]

We restored the backed-up rewrite configuration, passed the Nginx configuration test and reloaded it. The same PHP URL then responded successfully. This demonstrates an upstream mismatch, not every possible cause of a 502.

5. Verify recovery
Reload the affected PHP page, check a normal website page and review the latest error log. If the problem began with an application upgrade, verify its PHP compatibility and required extensions too. Remove temporary diagnostic pages when finished.

Related guide
Change PHP 8.3 to 8.5 in aaPanel Free Edition