Xampp服务器上的Wordpress - 未定义索引:主机

时间:2014-04-10 20:17:24

标签: mysql wordpress

我最近在Windows 7上使用XAMP在本地设置了Wordpress。我已经为我的安装创建了一个SQL数据库,并设置了一些配置文件来处理实时服务器和本地,以便在我开始使用git时使用。

我有一个 wp-local-config.php

<?php 
// Local server settings

// Local Database
define('DB_NAME', '<mysiteuser>');
define('DB_USER', '<mydbuser>');
define('DB_PASSWORD', '<db password>');
define('DB_HOST', 'localhost');

// Overwrites the database to save keep edeting the DB
define('WP_HOME','/client.dev');
define('WP_SITEURL','/client.dev');

// Turn on debug for local environment
define('WP_DEBUG', true);

我的 wp-config.php

<?php

// Use these settings on the local server
if ( file_exists( dirname( __FILE__ ) . '/wp-local-config.php' ) ) {
  include( dirname( __FILE__ ) . '/wp-local-config.php' );

// Otherwise use the below settings (on live server)
} else {

  // Live Server Database Settings
  define( 'DB_NAME',     '<live db name>');
  define( 'DB_USER',     '<live db user>');
  define( 'DB_PASSWORD', '<live db pw>' );
  define( 'DB_HOST',     'localhost'  );

  // Overwrites the database to save keep edeting the DB
  define('WP_HOME','http://<client url>');
  define('WP_SITEURL','http://<client url>');

  // Turn Debug off on live server
  define('WP_DEBUG', false);
}

然而,当我登录我的wordpress安装时,我遇到了很多调试错误,例如:

(在屏幕顶部)

Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\theme.php on line 1820
Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\theme.php on line 1820
Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\theme.php on line 1876
Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\theme.php on line 1876

在wordpress new中:

Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\http.php on line 470
Notice: Undefined index: host in C:\xampp\htdocs\client.dev\wp-includes\class-http.php on line 129

任何人都可以帮我找出为什么会发生这种情况吗?

5 个答案:

答案 0 :(得分:5)

@ MAT-视觉:

正如用户RDrazard所指出的那样:在你的wp-local-config.php中,改变这两行:

define('WP_HOME','/client.dev');
define('WP_SITEURL','/client.dev');

看起来像这样:

define('WP_HOME','http://localhost/client.dev');
define('WP_SITEURL','http://localhost/client.dev');

我使用自己的本地WordPress安装测试了它,它清除了你得到的错误。希望你觉得这很有帮助!

答案 1 :(得分:5)

我会推荐类似的东西,但为了避免为我的网站编写任何硬编码:

define('WP_HOME','http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL','http://' . $_SERVER['HTTP_HOST']);

答案 2 :(得分:1)

将网址更改为绝对路径为“http://localhost/client.dev”。

如果问题仍然存在,请将localhost更改为127.0.0.1,从而生成如下路径地址

http://127.0.0.1/client.dev

并在所有网址中进行必要的更改。

答案 3 :(得分:1)

你的问题是关于某些数组在文件theme.php中没有索引'host',例如:

$array['host']

这不是错误,只需注意,您可以使用以下方式隐藏通知:

error_reporting(E_ALL ^ E_NOTICE);

如果您不介意,请添加更多的theme.php部分,我可以为您提供更多帮助。

答案 4 :(得分:0)

这应该排序......

define('WP_HOME','http://'。$ _SERVER ['HTTP_HOST']); define('WP_SITEURL','http://'。$ _SERVER ['HTTP_HOST']);