Mostly
Mostly

Reputation: 227

Google Cloud Compute Instance + WordPress

I've recently setup and deployed two standard WordPress installations using Google Cloud Compute VM Instance.

The issue that I am having is that when the site is idle for a few hours or a couple of days, there is an error establishing a connection to the database.

If I reset the server, everything works fine.

I'm the furthest thing away from being an expert on Cloud based servers, any advice would be greatly appreciated!

Upvotes: 3

Views: 1094

Answers (1)

Mostly
Mostly

Reputation: 227

I also posted this question in the Google GCE Group.

https://groups.google.com/forum/#!topic/gce-discussion/8knQumfLsBY

Credit to George from Google Support, the fix was rather simple.

On GCE idle TCP connections are disconnected after 10 minutes. If your instance initiates or accepts long-lived connections with an external host, you can adjust TCP keep-alive settings to prevent these timeouts from dropping connections. You can configure the keep-alive settings on the Compute Engine instance, your external client, or both, depending on the host that typically initiates the connection. You should set the keep-alives to less than 600 seconds to ensure that connections are refreshed before the timeout occurs. You can do that by running the following command:

sudo /sbin/sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=5

You will oly be able to run the command as root. So sudo su to switch to root.

To ensure that the settings survive a reboot, add the settings to your /etc/sysctl.conf file.

This option is only available from the command line on the instance itself. In order to have the changes added to the " /etc/sysctl.conf " you can access the file using any of your preferred editors (vi, nano...) and add the following:

# increase the time default value for connections to keep alive
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 60

This solution is a confirmed fix to my problem, hope it helps someone else.

Upvotes: 4

Related Questions