本地wordpress使用远程数据库,ubuntu,apache2

问题描述:

im trying to connect my local wordpress install to a db on a domain i own using the code provided here: https://coderwall.com/p/ck8v4a/remote-database-with-local-wordpress-instance

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/');
}

with the above config i can open the site locally, it loads the navigation and recent post names correctly, so the db-connection seems to work. i cannot use links and pages are not found though.

if i add my /wpDir/ to the define('WP_HOME'... and/or strpos($currenthost,... it gets redirected to http://localhost/wpDir/home/ (as it should) but i get an URL not found error.

my localhost dir is standard /var/www/html this is where my local wordpress installations are.

any ideas how to fix this?

update: i am back to working on this and it would really help a lot if i could manage to use the remote database for my local testing i think it may be some kind of url rewriting problem but all my efforts to find a solution did not work...

我尝试使用此处提供的代码将我的本地wordpress安装连接到我拥有的域上的数据库: https://coderwall.com/p/ck8v4a/remote- database-with-local-wordpress-instance p>

  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 /'); 
} 
  code  >  pre> 
 
 

使用上面的配置我可以在本地打开网站,它正确加载导航和最近的帖子名称,所以db-connection似乎可以工作。 i不能使用链接和页面是 但是没有找到。 p>

如果我将 / wpDir / code>添加到 define('WP_HOME'... code>和/或 strpos($ currenthost,... code>它被重定向到 http:// localhost / wpDir / home / code>(应该如此)但我得到一个URL not found错误。

我的localhost目录是标准的 / var / www / html code>这是我本地wordpress安装的地方。 p>

任何想法 如何解决这个问题? p>

更新:我重新开始工作,如果我可以设法使用远程数据库进行本地测试,那将真的有很大帮助 i认为它可能 是某种网址重写问题,但我所有努力寻找解决方案都不起作用...... p> div>

not sure why it was so hard to find but i managed to do it (another way) basically by following the wp-codex here: https://codex.wordpress.org/Running_a_Development_Copy_of_WordPress using the drop-in method: the code in my db.php file looks like this:

<?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
}