MySQL and Apache2 running together crashes MySQL

Posted May 18, 2016 6.7k views
UbuntuMySQLApacheWordPressDigitalOcean 1-Click Apps Marketplace

So this is a very odd issue that I can not seem to find an answer to anywhere else, but is causing me a huge problem.

So I am working on a website for a friend and I set him up with a digital ocean droplet running Wordpress (using the one click install). The server was fine for about a week, but then I would start to get the “Error establishing a database connection” message when trying to load the site. I eventually figured out that it was because MySQL was no longer running. I started the service again, thinking nothing of it and went about my day. I check back later, same error. I once again restart MySQL but watch htop this time. I see my RAM usage skyrocket, followed by my CUP usage, then it all goes back down and MySQL has crashed again. I ask another friend who has much more experience than me and he recommended rebuilding the droplet. Exported MySQL databases and backed up Wordpress files, rebuilt, imported settings, and was fine for a few days, but today I noticed the issue is happening again, but slightly different this time. Last time, MySQL lasted a good two minuted before crashing, now it seems to be about an hour between crashes, and in-between those times, CPU and RAM usage is normal and steady. I can guarantee you this isn’t a problem with the server being overloaded from a large amount of traffic, there are only about 10 people who know the site exists and there have only been about 24k requests since the site went active on May 5th (a majority of them being me). I have tried to solve this on my own but have had no luck at all, this is getting to be very frustrating.

To add some more information, before MySQL crashes, it starts creating new process that I can see from htop, but never ends them.
I can run Apache2 just fine without MySQL and I can run MySQL just fine without Apache2 and there is no issue, but when the two are running at the same time, MySQL crashes.
Here is my Apache2 config file. If there is anything else you need, let me know and I will get it for you as soon as I can.

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

What about your logs?
Did you check the log of mysql? Maybe Apache2 floads the mysql DB with requests?
Also just to be sure check your apache2 log.
And what is the last thing you changed before this problem started? Maybe you installed a plugin?

You could run these(as seperate commands):

  • tail -30 /var/log/mysql.err
  • tail -30 /var/log/mysql.log
  • tail /var/log/mysql.log
  • tail -30 /var/log/apache2/error.log
  • mysql.err and mysql.log were both empty. However, the apache2 error.log was filled with stuff. Going back and looking, it was at the exact time the server crashed as well. Here is a link to the contents of that log.

    Edit: Just started MySQL and CPU usage immediately shot up to 100% and crashed within two minutes. Here is the log from that crash.

    • Hi,

      This log is intresting:
      [Thu May 19 12:32:47.502195 2016] [mpm_prefork:error] [pid 14468] (12)Cannot allocate memory: AH00159: fork: Unable to fork new process
      [crit] Memory allocation failed, aborting process.
      [crit] Memory allocation failed, aborting process.
      [crit] Memory allocation failed, aborting process.
      [crit] Memory allocation failed, aborting process.

      How many ram does your droplet have? I’ve seen this before with Java, basicaly meaning Apache2 consumes to much ram, thus the kernel is killing the process in order to keep the system running.

      Does your kernel log show the same error? The kernel should log the killing of a process due to a shortage of memory.

      • I am currently on the $10 droplet. So 1gb of RAM. I checked the kernal log and I see a lot of talk about killing an apache2 process. Here is a small excerpt of the log, I would post all of it from that time but it is huge, mainly repeating this section. The end of this log is where it currently ends for me.

        • Hi,

          sorry for my late reply, but i’m pretty sure your machine is running out of RAM.
          Try upgrading your droplet, or check your apache settings.
          Below is a very helpful tutorial for performance optimization:

          If the above tutorials doesn’t work, you should upgrade your droplet.

          by Matthew Nuzum
          Apache is an amazingly powerful and capable web server. In order to make initial setup as easy as possible, it comes with numerous modules pre-installed. This makes it a great choice for new projects when you need to quickly be productive, but as your site grows you may start to bump into performance problems. This tutorial will cover a few things you should do to optimize performance if you’re running Apache with your Django app.
          • Sorry for my long delay in replying, but I was testing some things with apache. Messing around with the mpmprefork config files did stop it from crashing, but it made the website INCREDIBLY slow and basically useless. I’m talking taking probably a minute to load each page, but it did stop the crashing. I tried to raise some of the values in the mpmprefork config to improve load times, but I could never get it high enough to actually be usable and stable. When I would raise the values, it would either use all of the available RAM or CPU usage would go up to 100%. I know this isn’t an issue with my server actually having too little RAM because I have a local web server running one core and one GB of RAM, that when no requests are being made CPU is at 0 and ram is less than 100 MB. What doesn’t make sense to me is how this server ran perfectly fine for over a week, with no RAM issues at all, then all of a sudden it crashes every single time I start it.

Well, to anyone coming here that has the same problem, I was unfortunately unable to solve it. I have now moved from Apache to Nginx. It only took me about 20 minutes to move and everything is working beautifully. Here is the wonderful guide I followed to transfer everything over.

by Justin Ellingwood
Many users initially set up WordPress installations using the Apache web server. While Apache does an excellent job serving content in most instances, Nginx, an alternative web server, can often do the same using fewer resources. The implication of this is that your WordPress site can handle more users if it is being served by Nginx. In this guide, we will discuss how to migrate your WordPress installation from Apache to Nginx.