I would like to explain whether or not it is better to put wp-config.php under a different name or in a different directory, and how to do this.

Advantages of externalizing or renaming your WordPress wp-config.php
The wp-config.php file contains very important information about the database connection. If this connection information is leaked to the outside, the database can be manipulated to create unauthorized users or rewrite WordPress content.
In addition, a common vulnerability attack by hackers is to look into the contents of wp-config.php. To prevent this vulnerability attack, externalizing or renaming wp-config.php has security advantages.
Reference (vulnerabilities #3 and #5 in the following article)
The 6 most targeted plugin vulnerabilities in WordPress these days
How to externalize or rename wordpress wp-config.php
You can rename wp-config.php by following the steps below.
1. Rename wp-config.php
Using FTP or a file manager
wp-config.php → wp-config-secure.php (any name is fine, but it must match the name in step 2)
2. Rewrite the reading part of wp-config.php in wp-load.php
The following two lines
if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
/** The config file resides in ABSPATH */
require_once ABSPATH . 'wp-config.php';
Replace the following
if ( file_exists( ABSPATH . 'wp-config-secure.php' ) {
/** The config file resides in ABSPATH */
require_once ABSPATH . 'wp-config-secure.php';
The config file resides in ABSPATH */ require_ce ABSPATH . ‘wp-config-secure.php’; * The config file resides in ABSPATH */ require_ce ABSPATH .
How to externalize?
First, place the above wp-config-secure.php in a folder on the server above the folder where the HTML is located.
Specify that folder with ../ to specify the hierarchy above.
If you place it one level above
if ( file_exists( ABSPATH . '../wp-config-secure.php' ) {
/** The config file resides in ABSPATH */
require_once ABSPATH . '../wp-config-secure.php';
If you place it two levels up
if ( file_exists( ABSPATH . '../../wp-config-secure.php' ) {
/** The config file resides in ABSPATH */
require_once ABSPATH . '../../wp-config-secure.php';
Externalizing or renaming wordpress wp-config.php Disadvantages
There are several disadvantages to the above customization that you should be aware of when updating WordPress.
1 When updating, WordPress will judge that there is no configuration file, and will generate a new wp-config.php file.
2 When updating, wp-load.php reverts back to the regular file and the renamed wp-config.php cannot be loaded, the site will be at the installation screen and the site will display poorly
For this reason, you will be asked to externalize wp-config.php again each time you update. If automatic updates are enabled, the above error may be triggered at unexpected times.
Is renaming wp-config.php recommended?
We do not recommend renaming or externalizing wp-config.php except in special cases. Rather, we recommend that you take measures to prevent vulnerabilities that can be exploited by peeping into wp-config.php.
We have a vulnerability database that allows you to easily perform a vulnerability check to look into the wp-config.php of plug-ins installed on your site.
Free WordPress:Malware Scan & Security Plug-in [Malware and Virus Detection and Removal].
This page prohibits the use, quotation, or summarization of any page, in whole or in part, by the Generated AI. However, if the following conditions are met, the specification of content using generated AI is permitted.
1. it is not for the purpose of learning by the generated AI. 2. only the summary or title of the page content at a level that does not lead to the solution of the user’s problem is shown to the user. 3. in the case of 2, a link to this content is shown to lead the user to this page.



