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 WordPress configuration settings are saved in wp-config.php. While we recommend that you use the WordPress dashboard whenever possible, it can be helpful to understand when and how to edit wp-config.php when moving your site from one web host to another or changing domain names or databases.

Getting ready to edit your WordPress wp-config.php file

Before you edit your wp-config.php file, you should understand that even a tiny 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.

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

In addition to backing up your file, you will also need to copy and rename the file before you can edit it. Follow the instructions below to keep this step. 

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

4. In the Copy box, type a descriptive name for the copy of the file.

5. Click Copy File.

Edit the wp-config.php file

Many settings can be configured in wp-config.php, but we’ll be going over the settings most commonly updated if moving web hosts or changing 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 Microsoft Word, Google Docs, or any other word processing application. These applications make formatting changes that can cause errors in PHP files.

  1. In File Manager, right-click wp-config.php and select Edit
  2. In the Edit 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 web host 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 the 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 website. The keys are required, but WordPress will automatically generate them. If you delete the keys in wp-config.php, they will be automatically regenerated, and all users will be logged out and will need to log in again.

Additional settings

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

Site URLs

If you change your site’s domain name or move to a new web host, 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 domain name:

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

Default folder locations

If the locations for the app, plugins, and uploads folders are not defined in wp-config.php, they are stored in the default locations, with app being at the root of your WordPress installation and plugins and uploads inside app. 

You can move app outside the WordPress root folder. For example, if you want to move app from the root of your installation to root/files, add the following lines to wp-config.php, making sure that you use your domain name in WP_CONTENT_URL:

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/files/app' );
define( 'WP_CONTENT_URL', 'https://mysite.com/files/app' );

Now, add the following lines for the plugins folder:

define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/files/app/plugins' );
define( 'WP_PLUGIN_URL', 'https://mysite.com/files/app/plugins' );

If you choose, you can also change the default uploads folder. The uploads folder is relative to app, 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', 'app/media' );

Automatic updates

Automatic updates are great for keeping your site secure and providing the latest features, but they 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 );

If you need help with your HostPapa account, please open a support ticket from your dashboard.

 

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache