Error establishing a database connection
Yeah, that was pretty much the message that was seen if you went onto my site yesterday, especially during the evening. I had thought it was something that fucked up in the database, but it wasn’t. As it turned out, someone (or something) was pretty much DOSing my site, and I’ve stopped it for now. I wouldn’t call it a DDoS attack because it was only two IP addresses (and come on, they were both only one number off from one another), but they have been abolished from visiting the site for now.
Anyways, it took me til this morning to actually fix the problem. I honestly just thought that my database went corrupt, hence why the database connection error was happening. So what I did was I uninstalled MariaDB and reinstalled it, set up the database like normal and boom! However, the problem came back, after restoring a backup of the site. However, that was just me not thinking rationally, because every time I restarted MariaDB, the site would load fine—only for about three seconds before coming back with the database connection error. PHP was working fine, so that’s what lead me to blame MariaDB.
After hours and hours of Googling (combined with all the Googling I did last night, early this morning, and then after waking up today), I found a solution through a link on DigitalOcean’s website (wink wink, they power this site 😉 ): check out my Apache access log to see the IP addresses. They also provided the IPTables command for me to use to ban the IP addresses that were causing the site to go all haywire.
I’m just glad now that I got the site restored, and I’m especially thankful for that backup I made the other day as well, especially since I had to reset the site and “start over.” The only real things I had to do was remake the menu, add the site logo, favicon, and mobile app icon. However, all of those were simple and now the site looks like it was never reset to begin with!
So here’s the lesson I learned today from all of this hoopla: Check your Apache server access log to make sure you’re not getting DDoSed if your site goes down. If you are, just place a ban on the IP address/IP range and then restart MariaDB and/or Apache.