Question

Apache and MySQL crashing

Posted November 23, 2014 2.8k views

I have a problem about Apache and MySQL that are often crashes.
I’ve read the same problems about this matter, and “ivan.denkov87” suggest something like this:

“I use a script to check couple of services every 5 minute if they are running, and start / restart them if they do not. You can use” monit “”

Anyone know or maybe have an example script? I want to try it.

thank you

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.

×
3 answers

Thanks… I’ll try it :)

  • Bear in mind, that is not meant to be a solution, but rather a tool to trouble-shoot and keep things going while you figure out what is causing the crashing.

    Two things I always do on WordPress installs that are useful:

    install Login Lockdown plugin. This will reduce brute-force attacks on your WordPress login.

    Change out the WordPress login page. I wrote a plugin for doing this, but I would have to write up a tutorial on how to install it…or you can just google on how to do it.
    It is a simple thing, but it has saved me a lot of time. You would be amazed at how many robots are trying to login to your WordPress site…sometimes one every few seconds…and this can often cause crashes.

Thank you for your suggestion.

Right! MySQL is still crashes . MySQL would not restart yesterday and I have to restart my VPS manually using SSH .

I ’ve changed the login page according to your suggestion manually .

Hopefully… this can prevent MySQL crashes .

Is there another solution to avoid crashes MySQL ?

thank you

Hello, @beitisetiawan

I will recommend you to examine the MySQL error_log as well, because this is likely to give you a more verbose error and point you in the right direction to see what exactly is causing the issue here.

The location of the error_log should be:

/var/log/mysqld.log or /var/log/mysql/error.log

If you’re unable to locate the errorlog in this two locations you can double check your my.cnf file and see if the errorlog is saved somewhere else.

What you can do is to examine the last logged entries in the log using tail

You can use either:

tail -f /var/log/mysqld.log and tail -f /var/log/mysql/error.log

or

tail -n 100 /var/log/mysqld.log and tail -n 100 /var/log/mysql/error.log

You can share the output of the log here so we can have a look.

You can also create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps!
Regards,
Alex

Submit an Answer