you are a website owner who mainly uses WordPress, you must have at least once encountered the need to modify the wp-config.php file. Because this file is considered one of the files on which the site’s work and performance in general is built, it is necessary to understand well the codes this file contains and the correct ways to modify them to reach what you want, and this is what we will explain and clarify in detail within this article.
What is the wp-config.php file and where is it located?
Surely you know that during the installation stage of WordPress on the hosting service provider, and in the first step to do so, it requests some data from you to complete the installation stage. That data is (the name of the database – the username of the database administrator – the password of the database administrator) and some other data. . This data that is requested during the installation phase, WordPress stores and saves it inside the wp-config.php file so that it is permanently available and accessible if needed.
As you can see in the image above, all the data that is requested and highlighted in red is automatically stored by WordPress in a file called wp-config.php that is automatically created within the WordPress files themselves.
Note: Missing the wp-config.php file or an error in its code may cause the entire site to crash and a message “Error establishing a connection to the database” to appear.
Therefore, you should not open this file and modify it unless you know well how to modify it correctly and without destroying it.
Where is the wp-config.php file located and how to access and modify it?
The wp-config.php file is located inside the main directory where you installed WordPress within the hosting in the file manager. It can be easily reached in one of the following two ways:
The first way is to open the wp-config.php file and modify it
From within your hosting manager account, you log in to (File Manager) to open the entire site’s file manager, including the WordPress files that you installed on the hosting before.
Click on Public_html to display a diverse list of files, including our own file, wp-config.php, right in front of you.
In this case, you can open the file easily by right-clicking on it and choosing Edit. This will show you the file editing page that contains all the codes for the file that you can modify and click “Save” after completing the required modifications.
The second method is to open the wp-config.php file and modify it
In this method, you can access the site’s file manager without opening the file manager from within the hosting itself. To do this, you must download one of the programs that allows communication via the FTP protocol, and the most famous of these programs is FileZilla . After downloading the program, you will be asked for FTP service login information, which you can obtain from your hosting provider.
After entering the login data, a window will open for you containing all the site’s files, in which you will also see the Public_html folder, where you enter it to find the wp-config.php file, which you can click on to download it and open it using one of the code editing programs, and then re-upload it again after completion. From the amendment.
Why modify the WP-config
Before we talk about the purposes for which the wp-config.php file can be modified, we must once again note that modifying this file must be done with great care because this file is responsible for connecting all WordPress files to databases , and thus losing it. This means your site crashes completely.
Modifying the wp-config.php file does not require you to be an experienced programmer for several years, but it is enough just to know that this file in general contains some functions that were built using the PHP language and are defined using a function called define that you will find repeated frequently within the file. The following picture shows you that:
Basic functions of wp-config.php file
Below are the most important functions that you will need to perform with the WP-config file, and if you do not work on them now, you will need to work on them later.
1- Access to connection information for the site’s databases, MYSQL Database
You can access the connection information for your site’s database and change it if you want from within the wp-config.php file with ease, as you scroll inside the file and look for this part of the code that contains the database connection data:
You can preview the code as follows:
This part of the code shows some variables for database connection information:
- Value DB_NAME: Contains the name of the database that is used to store all data of the WordPress site, transfer articles, users, and other data.
- Value DB_USER: contains the user name for accessing the database
- Value: DB_PASSWORD: contains the password to enter the database
Thus, this part of the code contains data for connecting to databases. You can only modify their values without modifying at all the names of constants such as DB_NAME, DB_USER, and so on… so as not to cause damage or disruption to the site.
2- Activate debugging mode
This option is only useful for programmers and developers who want to participate in modifying the WordPress source code and correcting potential errors. To activate the debugging mode, you can easily do this from within the wp-config file via the following line, where you change the value “False” to the value “True”, thus activating the debugging mode.
3- Change the prefix of WordPress tables Table_prefix
The table prefix is one of the fields that appears in front of you in the first steps of installing WordPress. This field means that all data tables that are created within your site’s databases will begin their name with the special definition _WP.
To change this definition to any other definition for security reasons, since hackers know very well the name of this default definition, you can simply change this definition from within the Wp-config file from the following line of code:
Here you must change the definition “_WP” to any other definition you want.
Note : Changing the table prefix definition is not limited to changing it only from within the Wp-config file, but you must enter the database manager PHPMyadmin and change the names of all tables whose name begins with the definition “_wp” to the new definition or the new name that you set within the WP file. -config.
For example, you will first change the table prefix inside the wp-config.php file from the value “_WP” to the new value “Site”, for example as follows:
Now we change the value of the table prefix within the database in the following way from the value “WP” to the new value “site”.
We open the site’s database from within PhpMyadmin within your hosting account, and then we click on the WordPress database to open for us a list of the tables that are within the database, and all the tables begin with “_WP” as you can see in the image:
Then you select Select for all the tables that appear in front of you and that begin with “WP,” as you notice.
After selecting the tables, you will click on “With Selected” as indicated in the image above, and then choose “Replace Table prefix” as also indicated in the image above. The following screen will appear for you:
As the picture shows, in the “From” field, you will write the old value, which is “_wp,” while in the “To” field, you will write the new value, which is “_site.” Then you click Continue.
Thus, the table prefix value will be successfully changed, as you can see in the following image:
4- Changing security authentication codes and keys
It is possible to increase the security of your site’s data, which is stored in cookies, for example, by setting security authentication codes and keys, or what are known as Authentication Keys and Salts, within the WP-config file.
First, if these keys are not assigned within your file, they will look like this:
In this case, you must create these security keys via the WordPress security code generator . When you enter the code materials link, a program code that is automatically generated will appear for you, and its appearance will be as the following image shows:
All you have to do is copy these values into the space designated for them in the wp-config.php file to look like this:
Where you will copy those values that appear to you in the code generator of the WordPress site and then put them in the wp-config.php file, so that you put the value of the first line, for example, which is “AUTH_KEY” instead of the phrase “put your unique phrase here.” Thus, you repeat this step on the rest of the lines.
Some information about security authentication codes and codes. Authentication Keys and Salts
- When you set the values of these ciphers as we explained, it adds an additional layer of protection to your site’s data, as WordPress will encrypt password files and user data so that hackers cannot obtain them and decrypt them if the site’s data is hacked.
- If you set the values for these codes, WordPress will log all users out of the site and ask them to log in again.
- Never disclose these codes or make them visible to anyone because they may pose a threat to the security of your site.
- You can change these codes at any time you want using the WordPress code generator, but every time all users will be logged out and required to register again.
- You must change these codes through the WordPress code generator every time you feel that something strange has happened to your site, such as a severe slowdown in the site or loss of site files.
5- Set the absolute path for WordPress files
The image above shows the last part of the wp-config file for your site. The function of this code is to specify the path to the WordPress files, which are used programmatically for the purpose of saving, storing, and creating data files for the WordPress site.
You should not make any changes at all to these lines of code and leave them as they are so as not to cause the entire site to crash.
Additional functionality can be set and added using the wp-config.php file
1- Change the site link to Site Domain
In the event of transferring to a new domain or completely new hosting, the domain name or site URL must be changed so that there are no problems opening the site. You can change the links through the wp-config.php file by adding the following two lines to the file:
You will add the link to your new website instead of example.com.
2- Change the path to your website’s Uploads folder
The Uploads folder inside your WordPress site contains the uploaded media files that you upload to the various pages of your site, such as images and others. If you want to change the location where a site’s media files are saved, you can do so from within the wp-config.php file as follows:
If you want to change the path for saving media files, all you have to do is go to your site’s file manager, then go to the folder > wp-content, then create another folder to use to upload media files. Let’s create a folder called “siteimages”. Now you will write this code inside the wp-config folder, which in turn will redefine the path of the media saving folder from the uploads folder to the siteimages folder.
3- Stop automatic updates
By default, WordPress applies any new update to your site, and this is something that may be useful in most cases, but other times it may cause great harm to your site. The best solution is to apply the updates yourself manually.
You can easily stop manual updates from within the wp-config.php file by adding the following line to the file:
4- Determine the number of copies of “auto-save” within the database
You must have seen the phrase “There is a saved copy of this article” when you opened the editing page for one of your articles on your site. Automatic copies are copies of the content of the page or article that are saved within the database in the event that the content is modified and the Internet connection is lost, for example, WordPress stores an automatic copy within the databases so that you can retrieve it when you are connected to the Internet again.
If these automatic copies exceed the permissible limit within the databases, they can form a large burden on your site space and thus cause many problems.
The number of times automatic copies can be stored in databases can be determined so that only the oldest copies are saved and only the most recent copies are kept. For example, we can limit the number of saved copies to 2 only, and thus all old copies and more than 2 are saved by adding the following code inside the wp-config.php file as follows:
You can also control the time period that separates each autosave copy from another, using the following line:
By adding the previous line, the time period that separates each copy from the next that is stored in the databases will be 120 seconds, or two minutes. Therefore, the modification that will be made before 120 seconds have passed since the previous modification will not be saved.
You can also completely disable saving automatic copies. This means that any automatic copies of modifications will not be saved completely, and you may lose any modifications that were not saved due to an interruption of the Internet connection, for example. To disable automatic copying, you can add the following code in the wp-config.php file. :
5- Change the path of the Wp-content file from within the wp-config.php file
Changing the password in which the Wp-content file is located is considered one of the security measures that you can take at some point, because hackers know very well where this file is located, which contains all the important files for the WordPress site, such as plugins, images, templates, and other important files, which It is located directly inside the Public_html folder.
To properly change the Wp-content folder, open the wp-config.php folder and look for the following line of code, which is often found at the end of the file:
Directly above this code, you will add a code definition to set the new path for the wp-content folder that you want to move. The new path definition code will be as follows:
Considering that you change the path “blog/content/wp-content” to the new path of the wp-content folder.
Immediately after that, you will add another meta code to set the access link to the wp-content folder like this:
Consider changing http://example.com with your real website link.
Thus, the final form of the code will be as follows:
6- Change the path of the Plugins file for WordPress plugins and its contents
Just as we explained above how to change the path of the wp-content folder, you can in the same way change the path of the Plugins folder as well, by adding the identification code to set the new path to the plugin file as follows:
After that, you add the code to set the access link to the plugins file whose path we changed as follows:
After that, there is an additional step that you must also take, which is to write the following line of code as well, which contains the PLUGINDIR function in which the path of the new plugins file must be set as follows:
Note: You must change the paths in the code above to the real paths of your site.
7- Disable and prevent the Theme Editor
Modifying the code of the source code of the template or one of the add-ons without sufficient experience is one of the things that can cause a complete failure of the site. Therefore, disabling the code editor is a good option if the person managing the site does not have sufficient programming experience to modify the source code.
Using the following line, which is added inside the wp-config.php file, you can completely disable editing template codes and plugins:
8- Control deletion of items from the Trash
When you delete an article, page, or comment from your site, it goes into the WordPress Trash, and that data certainly creates an additional burden on your site, so you can easily control how long items remain in the Trash from within the wp-config.php file.
For example, we can specify the period of time that items remain in the trash for only one week using the following code:
You can also change the number “7”, which indicates the number of days the trash items are kept. If the number is set to zero, this means that the items that are deleted will not go to the trash and will not be saved, but will be deleted forever.
9- Secure the site administrator’s login
When the site administrator logs in to his account on the WordPress site, the browser tries to store his password in cookies, and this may not be in the interest of the site’s security.
To disable tracking of admin passwords and login data, you can easily add the following code inside the wp-config.php file:
10- Blocking external link requests
Hackers try to send requests to website databases to hack data, so blocking requests for external links may be an ideal option in this case. All you have to do is insert this code into the wp-config.php file to block external link requests:
You can also add the following code to allow official WordPress links to send requests to your site, which may be necessary sometimes:
That’s it, these are the most important functions you can perform using the wp-config.
What should I do if I don’t find the wp-config.php file?
Do not worry if you do not find the file or lose it. You can create the file yourself with ease. All you have to do if you do not find the wp-config.php file inside the file manager in Majdal WordPress is to search for another folder called “wp-config-sample.php” and change the name of this file by clicking the right mouse button and choosing “Rename” and rename it “wp-config.php” and that will do the trick perfectly.
How do I avoid crashing my entire site if there is an error while modifying the wp-config.php file?
To avoid your site from being controlled or completely crashed by incorrect modification of the file, you must take a backup copy of your entire WordPress site (Backup) using one of the different methods, the easiest of which is through some WordPress plugins that take a backup copy of your site to restore it again in the event of a crash. The site or some files are lost from it.
In the end, I hope you benefited from this article in learning how to use the WP-config file and make the most important modifications to it. Some of these modifications may be useful to you and some are not necessary at the moment, but in any case it is important to be aware of these functions
Leave a Reply