Store
Community Documentation

v3 Knowledgebase

How to enable MySQL Replication?

Notice: This feature requires phpFox 2.0.5 or higher

phpFox v2.0.5 or higher comes with the ability to setup database replication with MySQL. In this article we will provide information on how to enable MySQL database replication from our scripts perspective and assuming you have already setup your database servers. MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. You can setup as many slave servers as we have no limit on how many servers can be used.

If you haven't already setup your servers for database replication here are some useful articles:

Before we start its important to set this up on a test environment or least when your site is offline. When setting this up and if at anytime you get a "blank" page or your site simply does not work make sure to enable debug mode. More information on that can be found here.

Let's begin.

First, open the file:

include/setting/server.sett.php

Look for:

$_CONF['db']['slave_servers'] = array();

In our example we will be adding 2 slave servers. In order to do this we include 2 arrays so it looks like:

$_CONF['db']['slave_servers'] = array(
	array(
		'192.168.0.193',
		'root',
		'phpfox',
		false,
		false
	),
	array(
		'192.168.0.195',
		'root',
		'phpfox',
		false,
		false
	)	
);

You will notice each array looks like:

array(
	'192.168.0.193',
	'root',
	'phpfox',
	false,
	false
)

The first param is the server host name. The 2nd param is the MySQL user name for that server. The 3rd param is the MySQL password for that server. The 4th and 5h params can be both set to "false". Depending on your setup this array can look different.

Next, look for:

$_CONF['db']['slave'] = false;

Replace that with:

$_CONF['db']['slave'] = true;