Wordpressのwp-config.phpファイルの場所をドキュメントルート以外のディレクトリへ変更する
セキュリティ上、ドキュメントルート以下にwp-config.phpをおいておくのは怖い…
ここではドキュメントルートの2つ以上上位階層への移動の方法を示す。(直上階層まではデフォルトで可能)
まずは、wp-load.phpを編集します。
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
require_once( ABSPATH . 'wp-config.php' );
} elseif ( file_exists( dirname(dirname(dirname(ABSPATH))) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another install*/
require_once( dirname(dirname(dirname(ABSPATH))) . '/wp-config.php' );
次に、配置したwp-config.phpを編集。
wp-config.phpのパーミッションは755に設定します。
/** WordPress absolute path to the Wordpress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/www/hoge/hoge/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');