php - 使用远程数据库、ubuntu、apache2 的本地 wordpress

标签 php linux wordpress apache ubuntu

我正在尝试使用此处提供的代码将我的本地 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/');
}

使用上面的配置我可以在本地打开网站,它正确加载导航和最近的帖子名称,所以数据库连接似乎可以工作。 我无法使用链接,但找不到页面。

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

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

有什么解决办法吗?

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

最佳答案

不知道为什么这么难找到,但我基本上通过遵循 wp-codex 找到了(另一种方式): https://codex.wordpress.org/Running_a_Development_Copy_of_WordPress 使用 drop-in 方法: 我的 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
}

关于php - 使用远程数据库、ubuntu、apache2 的本地 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41251153/

相关文章:

php - Imagick 注释图像 : how to set text position from the top left

php - 创建包含php执行结果的文件

linux - Youtube 的 Zend_Gdata 库未导入 Linux 环境中的 cakephp 1.2 应用程序

php - 将延期交货库存状态添加到 Woocommerce 可变产品下拉列表中

php - 在 WooCommerce 结帐期间验证预定义的运输邮政编码

php - PHP 中错误的时区 MongoDate

php - 为什么这种 mongo 排序在 PHP 中不起作用?

c++ - 从源 : libstdc++. so.6 : version `CXXABI_1.3.8' not found (required by/usr/lib/x86_64-linux-gnu/libicuuc. so.55 构建 gcc 4.8.3 时出错)

mysql - 远程访问 MysqlDB

javascript - 将触发器中的 href 作为另一个元素的背景图片