2016-12-20 22 views
0

我嘗試連接我的本地安裝WordPress對我自己使用的代碼域分貝此處提供: https://coderwall.com/p/ck8v4a/remote-database-with-local-wordpress-instance本地WordPress的使用遠程數據庫,Ubuntu的,的Apache2

define('WP_CACHE', true); $currenthost = $_SERVER['HTTP_HOST']; 
$mypos = strpos($currenthost, 'localhost/wpdir'); 
if ($mypos === false) { 
    define('WP_HOME','http://example.org/wpDir/'); 
    define('WP_SITEURL','http://example.org/wpDir/'); 
} else { 
    define('WP_HOME','http://localhost'); 
    define('WP_SITEURL','http://localhost/wpDir/'); 
} 

與上面的配置,我可以打開該站點在本地,它正確加載導航和最近的帖子名稱,所以db連接似乎工作。 我無法使用鏈接,但頁面未找到。

如果我加我/wpDir/define('WP_HOME'...和/或strpos($currenthost,...它被重定向到http://localhost/wpDir/home/(因爲它應該),但我得到沒有找到URL錯誤。

我的本地主機目錄是標準的/var/www/html這是我本地wordpress安裝的地方。

任何想法如何解決這個問題?

更新:我回到了這個工作,它會真的幫助很多,如果我能設法使用遠程數據庫爲我的本地測試 我認爲這可能是某種URL重寫問題,但我所有的努力找到一個解決方案沒有奏效...

回答

0

不知道爲什麼它是如此難以找到,但我設法按照這裏的WP-抄本做到這一點(另一種方式)基本上是:使用下拉式方法 https://codex.wordpress.org/Running_a_Development_Copy_of_WordPress : 我的db.php文件中的代碼看起來像這樣:

<?php 
// paste this in a (new) file, wp-content/db.php 
add_filter ('pre_option_home', 'test_localhosts'); 
add_filter ('pre_option_siteurl', 'test_localhosts'); 
function test_localhosts() { 
    if (strcasecmp($_SERVER['REQUEST_URI'], '/localCopyOfSite') == 0 
     || strcasecmp(substr($_SERVER['REQUEST_URI'], 0, 17), '/localCopyOfSite/') == 0) { 
    return "http://localhost/localCopyOfSite/"; 
    } 
    else return false; // act as normal; will pull main site info from db 
} 
相關問題