Ubuntu 16.04 LAMP & Wordpress - MySQL keeps crashing

In the last few days, my Linode which runs ubuntu 16.04 with a LAMP installation with PHP7 and Mysql is experiencing serious problems.

The mysql is crashing constantly.

I have done an apt-get update & upgrade.
I've done all the wordpress plugin upgrades.

But the mysql is crashing a LOT. I have noticed that when my website seems to be getting a lot of traffic that this seems to happen then. But it is now out of control.

Is there any diagnostics I can do to try and determine what is going wrong?

5 Replies

What's the size of your Linode?

You write:

I have noticed that when my website seems to be getting a lot of traffic that this seems to happen then.

You may be having memory issues.

-- sw

Hi,
Thanks for the feedback. Someone else took a look and showed me some logs and he says that the mysql on my linode is running out of memory. He says that is why it's crashing.

These were the logs:
45.253634] Out of memory: Killed process 1181 (mysqld) total-vm:1131844kB, anon-rss:168160kB, file-rss:0kB, shmem0
[ 53.619463] Out of memory: Killed process 1766 (mysqld) total-vm:1127356kB, anon-rss:178872kB, file-rss:0kB, shmem0
[ 70.537025] Out of memory: Killed process 1881 (mysqld) total-vm:1128360kB, anon-rss:165968kB, file-rss:0kB, shmem0
[ 89.326634] Out of memory: Killed process 2045 (mysqld) total-vm:1133884kB, anon-rss:143052kB, file-rss:0kB, shmem0
[ 94.989052] Out of memory: Killed process 2300 (mysqld) total-vm:1121928kB, anon-rss:168480kB, file-rss:0kB, shmem0
[ 175.303993] Out of memory: Killed process 2466 (mysqld) total-vm:1132520kB, anon-rss:138524kB, file-rss:0kB, shmem0

My linode size is this:
1 CPU Core
50 GB Storage
2 GB RAM
0 Volumes

I would appreciate any guidance. Thanks.

First thing I would do is upsize your Linode to 4Gb and allocate a swap volume of 2Gb.

The next thing I would do is dump mpm-prefork on your apache2(8) server and go with one of the multi-threaded multi-processing modules…mpm-event or mpm-worker. In order to do that, you'll have to dump the apache2(8) PHP plugin and use the FastCGI Process Manager. You can read more about that here:

https://php-fpm.org

Doing this will affect only your apache2(8) configuration…not your WP site.

Lastly, I'd prob upgrade to Ubuntu 20.04 and the attendant upgraded versions of apache2(8) and PHP. However, you're prob going to run into "you can't get there from here" WP plugin hell.

-- sw

Thanks for the advice. I'm busy resizing to the next level.

I just want to ask: Your suggestion to dump mpm-prefork - will Wordpress still be able to work?

Is there a guide on how to do this?

@Rhodesia --

You write:

I just want to ask: Your suggestion to dump mpm-prefork - will Wordpress still be able to work?

Yes.

Is there a guide on how to do this?

I found a couple of Linode guides but they're really old. I found this for Ubuntu 18.04…it should translate well:

https://www.interserver.net/tips/kb/apache-php-fpm-ubuntu-18-04/

There are some steps you don't need to do (install apache2(8), php, etc.). The pieces you need are probably already on your system. However, YMMV…

The key to making php-fpm(8) fast and secure is to make it not use TCP sockets…use local-domain sockets. Also, since php-fpm(8) is multi-threaded, you can adjust the number of PHP service threads up/down to match your workload.

You modify php-fpm(8)s behavior by editing a configuration file in /etc/php/7.3/fpm/php-fpm.conf (if your php version is 7.3…adjust your version accordingly). php-fpm(8) also has its own php.ini in /etc/php/7.3/fpm/php.ini. Service-thread pools are defined/configured by conf files in /etc/php/7.3/fpm/pool.d (you can have different thread pools for different things…allowing you to further tune for your workload).

Once you implement php-fpm, all your PHP processing is off-loaded to it…apache2(8) doesn't do it anymore. php-fpm(8) is a separate process to it has to be running when apache2(8) is running:

sudo systemctl start|stop|restart php73-fpm  (adjust version accordingly)

Get php-fpm(8) to work with mpm-prefork first, then change everything to mpm-event or mpm-worker:

sudo a2dismod mpm-prefork
sudo a2enmod mpm-event OR sudo a2enmod mpm-worker
sudo systemctl restart apache2

All should be well. You can tune the number of service threads, etc by modifying /etc/apache2/mods-available/mpm-event.conf or /etc/apache2/mods-available/mpm-worker.conf and restarting apache2(8) when you're done. The meanings of all the parameters are explained in each file.

Make a backup before you start any of this so you can recover if you mess up…or, better yet, do this on a new Ubuntu 20.04 Linode and then migrate your WP installation to that when you're done. You can do all this on a nanode and then upsize it when you're done.

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct