Have you seen a tutorial that instructs you to update the wp-config file on your website, but you have no idea what that file is or how to do it? The good news is that we’ve got you covered. In this piece, we will walk you through the process of editing the wp-config.php file in WordPress so that it functions correctly.
What is wp-config.php File?
It’s a configuration file, as the name suggests, and all self-hosted WordPress sites have it.
Unlike other files, the wp-config.php file doesn’t come with WordPress. Instead, it’s made just for your site when you install WordPress.
The wp-config.php file is where WordPress stores the information about your database. If you don’t have this information, your WordPress site won’t work, and you’ll get the error “error establishing database connection.” (If you get this error please read our tutorial How to Fix Error Establishing a Database Connection in WordPress)
Aside from information about the database, the wp-config.php file has a number of other high-level settings. We’ll talk more about them in the rest of this article.
Since this file has a lot of sensitive information, you shouldn’t mess with it unless you have no other choice.
But since you’re reading this article, it means you need to know how to edit wp-config.php in WordPress. Here are the steps you need to follow to do it the way you would not regret it.
The first thing on your to-do list should be to generate a full backup of your WordPress installation. The wp-config.php file is so important to a WordPress site that even a small mistake will make it impossible to get to. We recommend using Updraft Plus, if your web hosting company offers a server-side backup, even better.
To connect to your website, you will require an FTP client. We recommend FileZilla or CyberDuck. You can move files from a server to your computer using an FTP client.
Use the FTP client to connect to your website. You’ll need FTP login information, which your web host does provide. Typically you have to create a separate FTP User. If you can’t remember your FTP login information, you can get help from your web host. As an alternative to FTP you are also free to use CPanel File manager if your web hoster provides access to it.
Typically, the wp-config.php file is in the root folder of your website, along with other folders like /wp-content/.
Just right-click on the file and choose “download” from the menu that appears. The wp-config.php file will now be downloaded to your computer by your FTP client. You can open it in a plain text editor like Notepad or Text Edit and change it there.
Understanding wp-config.php file
Have a look at the complete code of the wp-config.php file that comes with WordPress before you get started. You may also view a preview of this file right here on our website.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', ''); define('AUTH_KEY', 'put your unique phrase here'); define('SECURE_AUTH_KEY', 'put your unique phrase here'); define('LOGGED_IN_KEY', 'put your unique phrase here'); define('NONCE_KEY', 'put your unique phrase here'); define('AUTH_SALT', 'put your unique phrase here'); define('SECURE_AUTH_SALT', 'put your unique phrase here'); define('LOGGED_IN_SALT', 'put your unique phrase here'); define('NONCE_SALT', 'put your unique phrase here'); $table_prefix = 'wp_'; /* That's all, stop editing! Happy blogging. */
Let’s take a more in-depth look at each area that is contained in the wp-config.php file.
MySQL Settings in wp-config.php File
In the wp-config.php file, the “MySQL Settings” section tells you how to connect WordPress to your database. To fill out this section, you will need your MySQL host, database name, database username, and database password.
You can find information about your database in the databases section of the cPanel for your web hosting account.
If you are unable to locate the username and password for either your WordPress database or your MySQL account, you will need to contact the support team of your web hoster.
Authentication Keys and Salts
Authentication unique keys and salts are both examples of security keys that might assist in making your WordPress website more secure. With these keys, WordPress can create strong encryption for user sessions and cookies.
You can make security keys for WordPress and paste them here. This is especially helpful if you think someone may have hacked your WordPress site. When you change security keys, all users who are currently logged in to your WordPress site will be logged out and have to log in again.
WordPress Database Table Prefix
By default, WordPress gives all tables it creates a wp_ prefix. You should change the prefix of your WordPress database tables to something random. This will make it hard for hackers to guess your WordPress tables and protect you from some common SQL injection attacks.
Please keep in mind that you can’t change this value for a WordPress site that already exists.
WordPress Debugging Mode
This setting is especially helpful for people who want to learn how to develop WordPress and for people who wish to try out new features. By default, WordPress hides notices that PHP makes when it runs code. You can see these messages by setting the debug mode to true. This gives developers important information they need to find bugs.
Useful wp-config.php Hacks and Settings
There are more options in the wp-config.php file that can assist you in error troubleshooting and provide solutions to a variety of typical WordPress faults.
Changing MySQL Port and Sockets in WordPress
If your WordPress host uses different ports for MySQL, you will need to change the value of DB HOST to include the port number. Note that this is not a new line. Instead, you need to change the DB HOST value that is already there.
define( ‘DB_HOST’, ‘localhost:5067’ );
Don’t forget to change the port number from 5067 to whatever your web host gives you.
If your host uses sockets and pipes for MySQL, add it this way:
define( ‘DB_HOST’, ‘localhost:/var/run/mysqld/mysqld.sock’ );
Changing WordPress URLs Using wp-config.php File
When you move a WordPress site to a new domain name or web host, you may need to change the URLs. You can change these URLS at the Settings » General page.
You can also use the wp-config.php file to change these URLs. This comes in useful in the event that you are unable to enter the WordPress administrative section owing to an error involving too many directs. Simple add these two lines to your wp-config.php file:
Don’t forget to use your own domain name instead of onlyanexample.com. You should also remember that www.onlyanexample.com and onlyanexample.com are seen by search engines as two different places. If your site is indexed with the www prefix, then you need to add your domain name.
Change Uploads Directory Using wp-config.php
All the media files that you upload to WordPress are saved in the wp-content/uploads directory by default. If you would rather keep your media files in a different directory, you may do so by including the following line of code in the wp-config.php file of your WordPress installation.
define( ‘UPLOADS’, ‘wp-content/media’ );
Disable Automatic Updates in WordPress
In version 3.7 of WordPress, automatic updates were first implemented. It gave WordPress sites the ability to automatically update themselves whenever a minor update was made available. Automatic updates are fantastic for improving a website’s level of security; yet, in certain instances, they might damage a WordPress site, rendering it unavailable to users.
If you add this one line of code to the wp-config.php file of your WordPress website, it will turn off all of the automated updates that are performed.
define( ‘WP_AUTO_UPDATE_CORE’, false );
We really hope that this post was helpful in guiding you through the process of learning how to Edit wp-config.php in WordPress as well as all the interesting things that you can do with it.
Our other Blog posts
Yoast SEO 20.0 Update
Yoast SEO, the popular WordPress plugin, recently released version 20.0 with a completely redesigned user interface. According to Thijs de
Top 10 Mistakes Small Business Owners Make When Using SEO
Know Which Common SEO Mistakes to Avoid to Grow Your Local Business In spite of the importance of search engine
What is WordPress Metadata and Meta Tags? (For Beginners)
What is: Metadata Metadata plays a crucial role in organizing and managing the content on your WordPress website. It helps