What is “503 Service Unavailable error” and how to fix it??

503 Service Unavailable Troubleshooting

What is 503 Error?

A 503 Service Unavailable Error is an HTTP response status code that indicates the server cannot handle the request temporarily because it is overloaded or down for maintenance.

One of the latest PHP handler available is PHP-FPM. While tweaking php configuration, we will be setting maximum and minimum spare servers. If the number of connections go beyond the configuration, it will not be able to handle the request and PHP process will crash thereby throwing the error 503 Service Unavailable error. We will also receive the error when the web server is not able to get a  proper response from PHP script thereby it considers PHP-FPM service as unavailable.

503 error signifies that your website is online and running, but can’t be reached at the present moment. A refresh of the same page may load the site if the web server is able to handle the request.

Main causes of a 503 error

HTTP 503 errors can occur due to many reasons.

** One of the most common issues behind a 503 error is inability to handle request which cause improper communication between the server and the website. It may be either due to the server overload or the server might be down for some maintenance work.

** Another possible reason for 503 error is insufficient capacity to support the number of users attempting to access a website. Situation can occur where a normal site may experience sudden traffic due to a popular page thereby cannot handle the number of users. Also there can be DDoS attack to the site which can’t handle the number of users by the web server.

** 503 Service Unavailable error in WordPress sites can occur due to plugin conflicts thereby the connections to the site can increase.

Thus the reason can vary depending on the actual server setup.

Troubleshooting and Fixing

1) Check whether the server is overloaded

The first step to check a 503 error is to check if there is too much traffic to the server which can overload a server. For example, millions of people access a shopping website such as Amazon, Flipkart, etc. when a sale is going on. The server can also become overloaded if the site’s content has exceed its resources. Another possibility for server overload is malware or spam attacks.

You can check the number of IPs connected to port 80 using the below command:

netstat -plant | grep :80 | awk {‘print $5’}| cut -d: -f1 | sort |uniq -c |sort -nr | head

If the server overload is due to malware attack, then run an antivirus software like maldet to scan the home directory of a particular user in the server.

2) Check the Logs

Second step to be performed to check 503 error is as the error is related to web server, we need to check the webserver log files. Web servers can be Apache/Nginx and normally the log file will be located in /var/log folder under httpd or nginx folder.In a cpanel server, the web server log will be located at /usr/local/apache/logs. Search the apache access and error logs with the problem domain name and check the detailed errors related to the website in the logs.

3) Check if your web server is going through maintenance.

Most of the servers will shutdown when they are going through maintenance. Many CMS like WordPress, will automatically download and install updates without your intervention. The website will be issuing 503 Error during this period, particularly if your website is hosted on a slower server or a shared host.

4) If a CMS is used in a website, then 503 error can occur when the web server is unable to get a proper response from the PHP script like plugin or theme or custom code added to the CMS.

Suppose that we are having a wordpress site which throws 503 error. In order to fix this error, we can follow the below mentioned steps.

-> Deactivate all wordpress plugins

Deactivate all wordpress plugins by renaming the plugin folder as plugin_bkp. Now, check whether the site is loading or not. If yes, then a plugin installed on the website was causing the error. Then try to activate the plugin one by one and identify which plugin is causing the error.

-> Switch to a Default WordPress Theme

If deactivating plugins didn’t resolve the issue, then the next step would be to switch to a default WordPress theme. This will deactivate your current WordPress theme.

We can change wordpress theme by editing a table in the database used by wordpress site. For that, we need to connect to mysql database and run the following commands:

# mysql

This will help us to enter into the mysql command prompt.

mysql> use db_name;

To switch to the database connected to the website.
mysql> select * from wp_options where option_name = ‘template’ or option_name = ‘stylesheet’ or option_name = ‘current_theme’;
To find the current theme used by the website

mysql> update wp_options set option_value = ‘themename’ where option_name = ‘template’;
mysql> update wp_options set option_value = ‘themename’ where option_name = ‘stylesheet’;
mysql> update wp_options set option_value = ‘themename’ where option_name = ‘current_theme’;
To update/change the wp-theme

→Enable Debug option

In the home folder of the domain(ie, in public_html folder in a cpanel server), open the wp_config.php file and add the following entries to enable debug mode.

define (‘WP_DEBUG’, true);

define (‘WP_DEBUG_LOG’, true);

define (‘WP_DEBUG_DISPLAY’, false);

@ini_set (‘display_errors’, 0);

5) In a PHP based website, if the PHP parameters such as memory_limit, max_execution_time, etc are exceeded, then the website will show 503 error. So identify the PHP parameter which causes the issue from the website logs and increase the value for the same.


Leave a Reply

Your email address will not be published.

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code
 

Contact
close slider