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