The wp-config.php file is the main configuration file for WordPress, and is located in the root directory of your WordPress installation.
Although most people think of it as an install file, it is actually read each time a WordPress page/post is loaded, and not just when WordPress is installed. See Beginners Guide to the WordPress Load process.
If you do a manual WordPress install then you will need to edit this file prior to running the install script.
If you do a scripted installed, then the installation script will modify this file for you.
What you will Learn
- How to create a wp-config.php file.
- Common install settings.
- Advanced settings that are useful to know.
Creating a wp-config.php File.
The WordPress installation files contain a template file called wp-config-sample.php which you will need to:
- Rename to wp-config.php
- and then edit.
Common Installation Settings
Before you run the install script you will need to make changes to these settings.
So open the file in Wordpad ( Notepad may not display the file correctly hence the use of wordpad), and change the database name, database user, and password to match what you created in the MySQL configuration. The server location may also need editing.
In my case I’m using the database name wordpress and the database user called wordpressadmin and the password of password.
So my edited file looks like this:
In addition to the changes above, which you must make, the following changes are strongly recommended.
You need to replace the secret keys you find in wp_config.php file
with a new one just click this link and the new keys will be generated.
Just copy and paste them into the file to overwrite the ones that are there.
WP table Prefix
The default table prefix is wp_ and it was only changed if you wanted to install Multiple WordPress instances on a single database.
However today it is recommended that you change it for security reasons.
You need to Use only letters and numbers e.g w16_
Autosave and Revisions
WordPress by default will autosave ( every 60 seconds.) a post/page while you are editing.
Note: The autosave will only save the page/post if it has changed.
You can change the interval by using the following entry, where xx is the new value in seconds.
define( ‘AUTOSAVE_INTERVAL’, xx ); // Seconds
If you don’t want WordPress to autosave then you can turn it off with the following:
define( ‘WP_POST_REVISIONS’, false );
Note: not recommended
You can change the number of revisions that WordPress keeps. The default seems to be very large or there isn’t one. Add the following entry to limit the number where xx is the value you want e.g. 20
define( ‘WP_POST_REVISIONS’, xx );
Increasing Memory Limit
Because PHP scripts run on a shared server environment they have memory limits imposed on them.
If you get error messages that indicate you have run out of memory
PHP: Fatal Error:”Allowed memory size of xxxxxx bytes exhausted.
you can increase the memory limit allocated to WordPress.
To increase the memory limit to 128MB add the following line:
define( ‘WP_MEMORY_LIMIT’, ‘128M’ );
By default minor version updates are enabled on WordPress, but major version updates will need to be done manually.
You should get an email notification like the one below informing you of the update.
You can disable all updates and/or enable All updates (Major and Minor).
Add one of the following:
# Disable all core updates:
define( ‘WP_AUTO_UPDATE_CORE’, false );
# Enable all core updates, including minor and major:
define( ‘WP_AUTO_UPDATE_CORE’, true );
# Enable core updates for minor releases (default):
define( ‘WP_AUTO_UPDATE_CORE’, ‘minor’ );
Resources and references:
Related Tutorials and Resources:
- How to do a Manual WordPress Install
- Understanding WordPress Files and Folder structure
- WordPress Security Basics