How to Fix 503 Service Unavailable Error
If you're seeing 503 Service Unavailable errors, this means PHP processes are crashing while executing a script. As a result, the Webserver is not getting a valid response from PHP and considers the PHP-FPM service to be unavailable.
The most common cause of this problem is buggy PHP code, such as buggy WordPress plugins or slow scripts. The best solution is to disable all WordPress plugins and check your app's PHP error log and PHP slow log.
This problem can also be caused by buggy third-party PHP extensions or your server running out of memory.
Diagnosing Buggy PHP CodeThe most common cause of these errors is buggy PHP code in your app.
The best solution is to disable all WordPress plugins, custom themes, and other custom code until you identify which code is causing the problem.
You may find more information in the app's PHP error log or PHP slow log. You can find these log files at:
If you see errors in these files, it likely means you have a bug in your app's PHP code, such as in a WordPress plugin.
For example, if you have slow scripts, a cascade of problems caused by the slow scripts can ultimately result in PHP not able to respond to requests anymore. In this case, the solution is to fix the slow PHP code.Diagnosing Buggy PHP Extensions
If you have added custom PHP extensions, such as New Relic or any PECL extension, one of them may be buggy.Running Out of Memory (vServers & dServers)
If your server runs out of memory when handling a PHP request and the PHP process was using a lot of memory, the PHP process handling the request will crash.
If you see errors like Out of memory: Kill process ... (php-fpm) in your server's /var/log/syslog file, this is the cause of the errors you're seeing.
The best solution in this case is to upgrade your server to one with more memory.
You may also want to reduce PHP and WordPress memory usage.Restarting PHP
Even if you haven't identified the cause of the problem, you may be able to get your app working again by restarting PHP.
To restart PHP, SSH into your server as root and run the following command as root for your app's PHP version (replace "X" with the PHP version, for example "5").
Note that if you haven't identified and fixed the underlying cause of the problem, such as the buggy PHP code or PHP extension, the problem may happen again.