問題描述

這是我的設置。我有一個在 http://example.com 運行的多站點實例,我想做開發和分期。將現有的多站點實例 WP 移動到本地主機是一個噩夢,所以我打算在分段位置做開發。

我設置 http://staging.example.com 指向主機帳户的/public_html /staging /目錄,並將所有 WP 文件從我的根拷貝到/staging /目錄中。我也複製了數據庫文件 (SQL 轉儲,將表導入新數據庫),並將 wp-config.php 文件更改為指向新的數據庫。

在運行 SQL 以更改數據庫記錄之後,我還在 wp-config.php 文件中更改了這一行:

/** Turning on WordPress MU, new in 3.0 */
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example.com' ); // <- I change this line
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

變成:

define( 'DOMAIN_CURRENT_SITE', 'staging.example.com' ); // <- now changed

當我加載 http://staging.example.com,我得到… Error establishing database connection

我已經檢查並三重檢查了用户名和密碼,確保用户擁有新的分段數據庫的所有權限,而且已將 DBHOST 作為’localhost'(儘管將其更改為 staging.example.com 沒有幫助,其一) 。

為什麼數據庫連接失敗?任何人? (感謝您的幫助提前。)

注意:http://example.com 在非常類似的數據庫連接設置上正常運行,只需使用不同的數據庫,因此數據庫服務器關閉不是問題。

最佳解決方案

有一個想法 – 當我訪問 www.example.com/staging/wp-admin 時,它會自動將我重定向到 www.example.com/wp-admin

從 staging.example.com 到 example.com/staging 的重定向是否與現有安裝衝突?

更新:看起來可能與.htaccess 問題和數據庫中複雜的域引用有關

從 WP 食典:

Moving WordPress Multisite

Multisite is far more complicated to move, as the database itself has multiple references to the server name as well as the folder locations.

The best way to move Multisite is to move the files, edit the .htaccess and wp-config.php (if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. If you’re moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly.

次佳解決方案

真正只有一種方法可以輕鬆轉讓我發現的域名或主機。它在單和多站點安裝上對我而言完美無缺。

  1. 將您的數據庫導出到.sql 文件。 (我為此使用 PHPMyAdmin)

  2. 使用稍微不同的名稱創建要編輯的文件的新副本。

  3. 在您打開文件首選文本編輯器> (例如 gedit)

  4. 在從生產到 dev 的域和絕對路徑 (/home /username /public_html /to /home /username /public_html /) 上運行查找/替換。

  5. 保存文件。

  6. 將整個安裝複製到您的開發目錄。

  7. 將以下行添加到 wp-config.php 文件中:define(‘RELOCATE’,true);

  8. 登錄並保存您的永久鏈接設置。

  9. 刪除您放在 wp-config.php 中的定義規則。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。