我在wp配置中做了一些修改。允许WordPress使用我的版本控制过程的php。我认为,经过一些调整,这些修改也可以满足您的需要。
1) Make URLs relative instead of absolute.
这很有用,因为WordPress喜欢将绝对URL写入数据库,但由于您从不同的URL提供相同的内容,这会变得很混乱。
将以下内容添加到wp config。两台服务器上的php
define(\'WP_SITEURL\', \'http://\' . $_SERVER[\'SERVER_NAME\'] );
define(\'WP_HOME\', \'http://\' . $_SERVER[\'SERVER_NAME\']);
define(\'WP_CONTENT_DIR\', $_SERVER[\'DOCUMENT_ROOT\'] . \'/wp-content\');
define(\'WP_CONTENT_URL\', \'/wp-content\');
define(\'FS_CHMOD_DIR\', (0755 & ~ umask()));
define(\'FS_CHMOD_FILE\', (0644 & ~ umask()));
define(\'UPLOADS\', WP_CONTENT_URL . \'/uploads\');
2) Define database credentials for both (or more) environments
在您的情况下,两台服务器的数据库凭据将是相同的。
您的用户名和密码在两个网站上都是相同的。
替换wp config部分。php,其中使用以下内容定义数据库凭据:
// define environments
$environments = array(
\'server1\' => array(
\'address\' => array( \'domain1.com\', \'www.domain1.com\' ),
\'db\' => array(
\'name\' => \'\',
\'user\' => \'\',
\'password\' => \'\',
\'host\' => \'localhost\',
\'charset\' => \'utf8\',
\'collate\' => \'\'
),
\'ssl\' => false,
\'dev\' => false
),
\'server2\' => array(
\'address\' => array( \'domain1.com\', \'www.domain2.com\' ),
\'db\' => array(
\'name\' => \'\',
\'user\' => \'\',
\'password\' => \'\',
\'host\' => \'\',
\'charset\' => \'utf8\',
\'collate\' => \'\'
),
\'ssl\' => false,
\'dev\' => false
)
);
// allows wildcards in the array to be searched
function better_in_array( $needle, $haystack ) {
foreach ($haystack as $value) {
if ( fnmatch( $value, $needle ) === true ) {
return true;
}
}
return false;
}
// loop through environments to get proper db credentials
foreach( $environments as $key => $env ) {
if ( better_in_array( $_SERVER[\'SERVER_NAME\'] , $env[\'address\'] ) ) {
// if we find a matching environment, apply db credentials
define( \'DB_NAME\', $env[\'db\'][\'name\'] );
define( \'DB_USER\', $env[\'db\'][\'user\'] );
define( \'DB_PASSWORD\', $env[\'db\'][\'password\'] );
define( \'DB_HOST\', $env[\'db\'][\'host\'] );
define( \'DB_CHARSET\', $env[\'db\'][\'charset\'] );
define( \'DB_COLLATE\', $env[\'db\'][\'collate\'] );
if ( $env[\'ssl\'] == true ) {
define( \'FORCE_SSL_ADMIN\', true );
}
if ( $env[\'dev\'] == true ) {
define( \'WP_DEBUG\', true ); // Turn debugging ON
define( \'WP_DEBUG_DISPLAY\', false ); // Turn forced display OFF
define( \'WP_DEBUG_LOG\', true ); // Turn logging to wp-content/debug.log ON
}
$environment = $key;
break; // break foreach if we find a match
}
}
// make sure all db constants are set.
if ( !defined( \'DB_NAME\' ) || !defined( \'DB_USER\' ) || !defined( \'DB_PASSWORD\' ) || !defined( \'DB_HOST\' ) || !defined( \'DB_CHARSET\' ) || !defined( \'DB_COLLATE\' ) ) {
echo \'Environment not configured.\';
exit;
}
3) Sync the uploads between servers.
有几种方法可以做到这一点,而如何做到这一点实际上可能取决于您的服务器设置。
rsync
? 将上传内容存储在Amazon S3存储桶中?
BitTorent Sync 可能有用(而且免费)。快速的谷歌搜索显示了本教程:
http://blog.bittorrent.com/2013/09/17/sync-hacks-how-to-set-up-bittorrent-sync-on-ubuntu-server-13-04/核心、插件和模板更新等内容也需要同步。通常,我会将所有这些都保存在版本控制中,并部署到两个服务器来处理这一问题。您可以通过将整个站点设置为同步而不仅仅是上载目录来实现这一点,但我没有这方面的经验,也不知道这会导致任何问题。