MENU CLOSE
  • Home
  • Blog
  • Get in touch

Hi, I am George

Hi, I am George

  • Home
  • Blog
  • Get in touch

Solve “Error establishing a database connection” of WordPress on a VPS (EasyEngine v4)

ON 19.06.2020 0 COMMENT

The new version of EasyEngine V4 needs at least 2G of RAM to run smoothly on a VPS. For smaller sites you often do not need a huge VPS and people usually go with the budget $5/$10 machines on DigitalOcean or Vultr.

This will make the WordPress to often go in “Error establishing a database connection” mode. A database restart of the docker container should fix it, but this is only temporary.

To make WordPress work without upgrading to a VPS with more RAM, there is a simple solution. Create a swap file.

First check the free RAM and if you have a swap file on your VPS. Run the

free -m

command. This should tell you how much RAM you have free and if you have a swap file.

Then I suggest that you create at least 2GB swap file. To do that follow these commands (this is for Debain based distros)

Let’s say that I want to add 2 GB of swap space to my system. Use the fallocate command to create a file of size 2 GB.

sudo fallocate -l 2G /swapfile

It is recommended to allow only root to read and write to the swap file. You’ll even see warning like “insecure permissions 0644, 0600 suggested” when you try to use this file for swap area.

sudo chmod 600 /swapfile

Do note that the name of the swap file could be anything. If you need multiple swap spaces, you can give it any appropriate name like swap_file_1, swap_file_2 etc. It’s just a file with a predefined size.

Step 2: Mark the new file as swap space

sudo mkswap /swapfile

Step 3: Enable the swap file

Now your system knows that the file swapfile can be used as swap space. But it is not done yet. You need to enable the swap file so that your system can start using this file as swap.

sudo swapon /swapfile

Now if you check the swap space, you should see that your Linux system recognizes and uses it as the swap area:

swapon --show
NAME       TYPE   SIZE USED PRIO
/swapfile  file 2048M   0B   -2

Step 4: Make the changes permanent

Whatever you have done so far is temporary. Reboot your system and all the changes will disappear.

It’s always a good idea to make a backup before you make any changes to the /etc/fstab file.

sudo cp /etc/fstab /etc/fstab.back

Now you can add the following line to the end of /etc/fstab file:

/swapfile none swap sw 0 0

or just run this command:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

This should fix the sql errors to happen so often.

PREV My Conor McGregor dupe SEO experiemnt
NEXT Migrating EasyEngine 3.8 to WordOps

Leave a Comment Cancel Reply

  • Recent Posts

    • Защо избрах хостинг в Jump?
    • Fonts not working on XAMPP (localhost) on Firefox [Solution]
    • Migrating EasyEngine 3.8 to WordOps
    • Solve “Error establishing a database connection” of WordPress on a VPS (EasyEngine v4)
    • My Conor McGregor dupe SEO experiemnt
  • Archives

    • May 2021
    • January 2021
    • June 2020
    • May 2020
    • March 2020
    • February 2020
    • January 2020
    • December 2018
    • August 2018
    • July 2018
    • May 2018
  • Categories

    • SEO