Troubleshooting 503 Service Unavailable
There are many reasons why your web server may return an HTTP response of “503 Service Unavailable,” and most of them are not actually a problem with the web server at all! Before you contact LiteSpeed support, let’s take a look at the possible causes of 503 errors, and see which ones you can easily solve on your own.
What is a 503 error?
When a web browser sends a request to your web server, the server responds with the requested resource, if applicable, and a status code. The code consists of a 3-digit number, which indicates the success or failure of the request.
Any response code in the 5xx series indicates a server-side error. 503, in particular, means Service Unavailable. Unfortunately, it does not tell you why the requested service is failing.
Rule Out a Server Issue
First, let’s make absolutely sure that you’re not dealing with an issue with your LiteSpeed Web Server.
The easiest way to do this is to temporarily switch your server to Apache. Once you’ve switched, try to duplicate the 503 error while Apache is running.
If you still get the 503 error while Apache is running, then this is not a server issue. Switch back to LiteSpeed, and keep reading the troubleshooting suggestions below.
If the 503 error goes away while Apache is running, then it’s time to contact LiteSpeed support. You can open a ticket from your client area. Be sure to provide as many details as possible to help the support team reproduce the issue!
If you’ve ruled out a server issue, it’s time to figure out what is really causing the problem. 503 errors are often caused by a PHP crash, a memory issue, or both. There’s a lot that you can learn from a PHP Info page. If you don’t have one, you can create one.
Check the phpinfo page
The PHP info page gives you a lot of detail about your PHP installation. Even if your system is having an issue with PHP, it should be able to handle processing this very basic page. Among other things, the PHP Info page gives you useful information about extensions, memory limits, and execution time.
With this information, you can see if OPCache is enabled, what the memory limit is, and which extensions are loaded, all useful information when looking for the cause of a 503 error.
You can also use this page to compare differences between Apache and LiteSpeed’s PHP implementations.
TIP: If the Apache and LSWS PHP info pages are different, please open a support ticket so we can take a look.
Check Log Files
There are many different log files that may help you determine the cause of the 503 error. Try checking these logs in the following order:
- Standard Error Log
- Web Server Error Log
- System Log
- PHP Error Log
Standard Error Log stderr.log
The stderr.log
file contains standard errors generated while PHP is running. You can usually find it in either the /var/log/apache2/
or /usr/local/lsws/logs/
directory. This log is often the most helpful.
In this example output from a standard error log, you can see that you are dealing with a memory issue:
[STDERR] fork() failed, please increase process limit: Cannot allocate memory
Web Server Error Log
This error log is generated by the web server. You can usually find it in either the /var/log/apache2/
or /usr/local/lsws/logs/
directory. If the web server has some role in causing PHP to fail, you should get some helpful hints from this log.
This example output from a web server error log indicates the you have too many open files:
[INFO] [319934] [1.1.1.1:49873-1#APVH:lsapi] connection to [uds://tmp/lshttpd/APVH-php56.sock] on request #0, confirmed, 0, associated process: 0, running: 0, error: Too many open files!
Another good thing to try: search /etc/apache2/logs/error_log
for the term oops
:
grep oops /etc/apache2/logs/error_log
That will give you some idea how many 503 errors have been generated since your last attempted fix, if you take a look at the timestamp. Unfortunately, it’s not likely to give you the reason why the errors are occurring, but it will allow you to see when they are happening and which domains are involved.
System Log
This error log is generated by the operating system. You can usually find it as either /var/log/messages
or /var/log/syslog
. This log is helpful if PHP is being affected by the operating system.
In this example output from a system log you can see that the lsphp
process was killed by the LFD firewall security feature:
lfd[18304]: *User Processing* PID:18264 Kill:1 User:xxxxx VM:538(MB) EXE:/usr/local/lsws/fcgi-bin/lsphp-5.4.42 CMD:lsphp5
You can fix this problem by excluding lsphp
from LFD.
PHP Error Log
This error log is defined in php.ini
and you can check phpinfo.php
for the file location. By default, cPanel will set it to error_log
. Depending on the logging level that you have set in PHP, it will be updated when PHP detects an error or a warning. It is usually generated inside of the same folder that the PHP script runs in.
This example output from a PHP error log shows that there is a fatal error within the test.php
application:
Fatal error: Call to undefined function my_function() in /home/mysite/public_html/test.php on line 2
The best way to solve these types of errors is to forward them to the developers of the PHP applications that are failing.
Disable opcode cache
Opcode cache stores bytecode in shared memory so PHP does not need to process the same calls over and over, but it can occasionally cause issues.
For example, this error points to an opcode cache problem:
[STDERR] zend_mm_heap corrupted
These are some common opcode cache extensions that you should consider disabling while you troubleshoot:
- OPCache
- APC/u
- XCache
- eAccelerator
Disable unsafe PHP extensions
In addition to the opcode cache extensions, there are other PHP extensions that have been known to cause issues, especially when they are outdated. These include:
- Imunify360
- ZendGuardLoader
- Suhosin
- ionCube
We recommended you regularly check for updates for these extensions. If you are already using the latest versions, try to disable them and see if the problem persists.
If you disable these plugins and are still getting a “503 Service Unavailable” response, disable all other extensions, and check again.
Check disk space
PHP will sometimes store files on your server in order to function properly. If your disks become full, especially the partition that houses /tmp/
, that could be the cause of your 503 error.
To check your disk space usage, run the following command:
sudo df -h
The output should look something like this:
Filesystem Size Used Avail Use% Mounted on devtmpfs 901M 0 901M 0% /dev tmpfs 915M 96K 915M 1% /dev/shm tmpfs 915M 89M 827M 10% /run tmpfs 915M 0 915M 0% /sys/fs/cgroup /dev/mapper/cl_centos 29G 4.2G 25G 15% / /dev/vda1 976M 184M 726M 21% /boot tmpfs 183M 0 183M 0% /run/user/0
If your disks are full, clean them up. Remove any unnecessary files. This should solve the 503 error.
Check CloudLinux limits
If you are running CloudLinux and Lightweight Virtual Environment (LVE) it is possible that you are hitting the LVE limits. To adjust them, follow CloudLinux’s guide.
Check memory limits
If you’ve confirmed that you are running within LVE limits, try adjusting your PHP memory limit. The PHP Info page will tell you where your php.ini
file is located. Edit the file and increase the memory_limit
value.
Sometimes a script may append lines to .htaccess
that override the PHP settings. This can supersede what is set in your php.ini file. A memory_limit
entry inside of .htaccess
would look something like this:
php_value memory_limit 100M
You can add, delete, or modify this line inside of your .htaccess
file to suit your needs.
If none of the above has an impact, then it is possible LSPHP needs to increase its virtual memory. To do so, navigate to WebAdmin Console > Configuration > Server > PHP, and click Edit for PHP Handler Defaults.
Change the following settings, then click Save:
- Memory Soft Limit:
4097M
- Memory Hard Limit:
4098M
Navigate to Actions and press the icon next to Restart Detached PHP Processes. Then Apply Changes / Graceful Restart.
Auto Fix 503
You may have noticed that LiteSpeed Web Server has an Auto Fix 503 Error setting. This feature does not permanently fix 503 errors. It restarts the server gracefully, which often fixes the issue temporarily.
Auto Fix 503 Error is enabled by default. This means the server will restart automatically whenever the number of 503 errors exceeds thirty in a 30-second span. You should not rely on this feature to fix recurring 503 errors. Going through the steps above to find a permanent fix is always recommended.
TIP: If you would like to disable this feature, navigate to WebAdmin Console > Server > General and set Auto Fix 503 Error to No
.
Conclusion
This information should help you track down most causes of 503 errors, but if you need more detailed troubleshooting ideas, take a look at our documentation. The docs take a deeper dive into some of these topics, and give you a few more advanced tools to use in your search for answers.
Comments