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.