Hi My website is on ec2, I have not put in any post on it still, I am getting the error Error establishing a database connection every 5-6 hours, I have to manually restart the MySQL server using the command line, the site is running on Ubuntu, Apache and using WordPress. Can you please suggest what could be the problem I checked the access logs there were some Russian IP's which I had blocked then I had also checked the CPU usage on AWS which rarely reached 100% usually it was in range of 30-40% Regards
I see a lot of get requests from Russian IP requests https://drive.google.com/file/d/1E-58hGPiXzd08_CBpIKWEb6_W6jM0Rl8/view?usp=sharing could this be the reason? Should I block them via htaccess or use some wordpress plugin apart from that jetpack is constantly checking for site uptime apart from that I see the wp-cron.php running on regular basis
For a wordpress website like this, unless you need cron to run every few minutes, you are better off changing wordpress to run cron manually. You can add this to wp-config.php define('DISABLE_WP_CRON', true); and then add a cronjob to perform cron manually. Generally, you can allow wordpress to run once a day. Here is a script I use on small sites to automatically update cron to run randomly once a day (so that not all sites try to run cron at the same time and cause DB issues) crontab -u [user] -l > mycron echo -e "$((( RANDOM % 60 ))) $((( RANDOM % 24 ))) * * *\t/usr/local/bin/php /home/[user]/public_html/wp-cron.php > /dev/null 2>&1" >> mycron crontab -u [user] mycron rm -f mycron Depending on your servers configuration, the path to php may be different, and you will need to update the path to wp-cron.php, but that should do the trick. Also, if your site is getting bombarded by fake users, then you will want to do the following as well... Add these modifications to your .htaccess file. <files wp-config.php> order allow,deny deny from all </files> <files xmlrpc.php> order allow,deny deny from all </files> A lot of bots will attempt to abuse the xmlrpc.php file, and this will deny their access. If you need it for any reason, you can whitelist the servers ip. Lastly, you most likely do not have wp-admin/wp-login.php locked down. I recommend installed math captcha, or some sort of captcha server. Additionally, you can lock down the wp-admin directory entirely by ip, if necessary. That's a bit more configuration, and you will want a VPN you regularly use and whitelist so that you can always access your server. Also, when was the last time you tuned your database? You may want to check the processlist on it, and also set the mysql connection timeouts low, to something like 60 seconds, if you are getting hammered. You may be running out of connections, as they are not releasing.