How to edit your WordPress wp-config.php file

wp-config.php is a core WordPress configuration file. It is generated during the WordPress installation and contains details specific to your installation and server environment. Many configuration settings that are configurable in the WordPress dashboard are saved in wp-config.php and while we recommend that you use the dashboard whenever possible, understanding when and how to edit wp-config.php can be helpful when moving your site from one webhost to another or changing domain names or databases.

Before you begin

Before you edit your wp-config.php file, you should understand that even a small error in the file could make your WordPress site inaccessible. For this reason, we strongly recommend that you make a site backup and a copy of the existing wp-config.php file before you begin editing.

Back up your site

There are many backup plugins available for WordPress, or you can use the backup feature in cPanel.

Copy and rename the wp-config.php file

Log in to your HostPapa dashboard and go to cPanel > File Manager. In the root folder of your WordPress installation locate wp-config.php. Right-click and select Copy.

In the Copy dialog box, type a descriptive name for the copy of the file and click Copy File.

Edit the wp-config.php file

There are many settings that can be configured in wp-config.php. This article includes those that are most commonly updated if you move webhosts or change domain names.

You can edit wp-config.php directly in the cPanel File Manager or you can download and edit it using your preferred text editor, and then upload it again. The examples in this article show the file being edited in the File Manager.

Note: Do not edit wp-config.php in Word, Google Docs, or any other word processing application. These applications make formatting changes that can cause errors in PHP files.

In File Manager, right-click wp-config.php and select Edit. In the Edit dialog box, click Edit.

The file is opened in the File Manager editor. In a default WordPress installation, wp-config.php includes MySQL settings and authentication keys and salts. Depending on how you’ve configured your site, there may be additional settings.

Database settings

If you move to another webhost or need to change database servers for any reason, you’ll need to update your database settings. Without correct database settings, your WordPress won’t be accessible. If you’re not sure about any of these settings, contact HostPapa Support before making any changes. The image below shows default database settings. If you’re moving or changing an existing installation, your settings will be different.

  • Database name (DB_NAME) – Replace database_name_here with your HostPapa WordPress database name.
  • Database username (DB_USER) – Replace username_here with your database username.
  • Database password (DB_PASSWORD) – Replace password_here with the password for your database username.
  • Database host (DB_HOST) – For databases hosted on HostPapa servers, this should be localhost.
  • Database character set (DB_CHARSET) – Leave this setting as utf8.
  • Database collate type (DB_COLLATE) – Leave this setting blank.

Authentication keys

Authentication keys and salts are strings of random characters used to provide encryption and security for your WordPress site. The keys are required but you don’t need to add them here because WordPress will automatically generate them. If you delete the keys in wp-config.php, they will be automatically regenerated and all logged-in users will be logged out and have to log in again.

Additional settings

Depending on your WordPress configuration, these settings may or may not exist in your wp-config.php. Ensure that you understand how these settings affect your site before making any changes.

Site URLs

If you change your site’s domain name or move to a new webhost, you may need to change your site URLs. We recommend that you do this from the WordPress dashboard in Settings General, but you can also make the change in wp-config.php by adding the following lines, using your own domain name:

define('WP_HOME','http://mysite.com');
define('WP_SITEURL','http://mysite.com');

Default folder locations

If the locations for the wp-content, plugins, and uploads folders are not defined in wp-config.php, they are stored in the default locations, with wp-content being at the root of your WordPress installation and plugins and uploads inside wp-content. If you choose, you can move wp-content outside the WordPress root folder. For example, if you want to move wp-content from the root of your installation to root/files, add the following lines to wp-config.php, making sure that you use your own domain name in WP_CONTENT_URL:

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/files/wp-content' );
define( 'WP_CONTENT_URL', 'http://mysite.com/files/wp-content' );

Now, add the following lines for the plugins folder:

define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/files/wp-content/plugins' );
define( 'WP_PLUGIN_URL', 'http://mysite.com/files/wp-content/plugins' );

If you choose, you can also change the default uploads folder. The uploads folder is relative to wp-content, so don’t add a leading slash. For example, to store all of your uploaded files in a folder called media, add the following line:

define( 'UPLOADS', 'wp-content/media' );

Automatic updates

Automatic updates are great for keeping your site secure and providing the latest features, but updates can also cause problems on some sites. WordPress has defined three types of core updates:

  1. Core development updates. These are the latest updates from WordPress developers and are installed only on sites running development versions of WordPress.
  2. Minor core updates. These are maintenance and security updates.
  3. Major core release updates. These are major releases, often including new features and UI updates.

By default, all minor core updates are automatically installed in WordPress.  To disable all automatic updates, including minor core updates, add the following line to wp-config.php:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

To enable automatic updates of all core updates, including development, minor, and major core, add the following line:

define( 'WP_AUTO_UPDATE_CORE', true );

To enable automatic updates of minor core updates and disable development and major updates (the is the default state for all non-development versions), add the following line:

define( 'WP_AUTO_UPDATE_CORE', minor );

For more information about WordPress automatic updates, see Configuring Automatic Background Updates.

More information

For more information see, Editing wp-config.php at codex.wordpress.org.

If you have any questions or need help, you can always contact HostPapa Support by opening a support ticket. Details about how to open a support ticket are here.

 

Was this article helpful?

  • Was this article helpful ?

  • yes   no

Related Articles

Leave A Comment?