doutui7955 2016-12-20 20:59
浏览 64
已采纳

本地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...

  • 写回答

1条回答 默认 最新

  • douhan0562 2017-01-31 09:28
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。