What to do when load on a Linux based web server goes high?
1) We must know about uptime command. If your website is loading slow, login into your web server console and run uptime to know load on your server.
>> uptime
If uptime shows high numbers like 100 or above 100, you must do something immediately, otherwise load might keep on increasing and will the server down.
3) Run following command to login as super user.
>> sudo su
4) Go to www directory
>> cd /var/www/html
5) If load is too high (Server is about to die), disable index.php (This will make your page inaccessible for a moment, but will decrease load as there won’t be new requests.
>> chmod 000 index.php
6) Check the top load causing IPs. Many times people run scripts to download content or to get malicious access. The below command (On Centos) tells you top 1000 visiting IPs.
>> tail -1000 /var/log/httpd/access_log | awk ‘{print $1}’ | sort | uniq -c |sort -n
A similar command for Ubuntu is
>> tail -1000 /var/log/apache2/access.log | awk ‘{print $1}’ | sort | uniq -c |sort -n
7) create a backup of .htaccess file
>> cp .htaccess back.htaccess
8) Block IP addresses in .htaccess if you find some particular IPs hitting your server
>> vim .htaccess
9) Monitor server load
>> watch -n 2 uptime
10) If you did not find any IP causing problems, you might want to check disk space and free memory.
Check available disk space
>> df -h
Check free memory
>> free -m
11) If none of the above steps help, then something might be wrong in your server code. Last but not least, check processes running on your server and try to debug it.
>> ps aux
Please make sure that you are not running heavy code (plugins) on every page load request. Do a lot of caching to avoid frequent DB or Network connections on a page request.
If nothing helps, then your page might have become popular and you need to upgrade your hosting plan.
Recommended Posts:
- Developing a Linux based shell
- Linux Virtualization : Linux Containers (lxc)
- TCP Server-Client implementation in C
- UDP Server-Client implementation in C
- UDP Client Server using connect | C implementation
- AWS EC2 Instance Setup with Apache Server
- Windows Server 2012 R2 Stuck at "Updating Your System”
- du Command in LINUX
- while command in Linux with example
- Linux vs Unix
- od command in Linux with example
- Permissions in Linux
- 'dd' command in Linux
- Linux Commands
- Wikit in Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



