【问题标题】:local wordpress using remote database, ubuntu, apache2使用远程数据库、ubuntu、apache2 的本地 wordpress
【发布时间】:2016-12-20 20:59:19
【问题描述】:

我正在尝试使用此处提供的代码将我的本地 wordpress 安装连接到我拥有的域上的数据库: 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/');
}

通过上述配置,我可以在本地打开站点,它会正确加载导航和最近的帖子名称,因此 db-connection 似乎可以工作。 我无法使用链接,但找不到页面。

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

我的 localhost 目录是标准的 /var/www/html 这是我的本地 wordpress 安装位置。

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

更新:我将重新开始工作,如果我能够设法使用远程数据库进行本地测试,那将真的很有帮助 我认为这可能是某种 url 重写问题,但我所有寻找解决方案的努力都没有奏效......

【问题讨论】:

    标签: php linux wordpress apache ubuntu


    【解决方案1】:

    不知道为什么它很难找到,但我基本上通过遵循 wp-codex 做到了(另一种方式): 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-17
      • 2010-11-29
      • 2014-06-06
      • 2013-04-19
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多