問題描述

這是我的設定。我有一個在 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。