How to read the wp-config file, and what can I do with it?

If you use an installer you might have never actually looked into the wp-config file. Many people will tell you that it is probably one of the more important files in your ClassicPress installation to understand. This is because there are so many things that it can do to cause problems if used incorrectly. That is why I want to take some time to decipher it piece by piece for people who might be intimidated by all the code. This explanation follows the base wp-config-sample.php of a clean install. Things might be added, out of order or missing in your production site. Just because there is something in your file that is not discussed here does not mean it is bad, but try to make note of these. When you are having problems you can then look if removing these unknown lines is the solution.

The database settings

The first and, arguably, most important part of the wp-config file are the database settings. It’s important that all six of these are filled in correctly or you might run into trouble with your database.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for ClassicPress */
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', '');

What do they mean?

define('DB_NAME', 'database_name_here');: This is the name of your database. This is often automatically generated by your hosting. This is basically just what your database is called.
define('DB_USER', 'username_here');: This is the username of your database. This is different from your database name, even though a lot of hostings use the same name for both. The username is a distinct login to gain access to your database.
define('DB_PASSWORD', 'password_here');: This is the password of the username from above. To login, ClassicPress needs the password belonging to the username you’ve chosen.
define('DB_HOST', 'localhost');: This is the location of your database. For a lot of people this will be Localhost. But in the rare cases that a database is in a seperate location from the ClassicPress installation, the correct ip-adress can be filled in here.
define('DB_CHARSET', 'utf8');: This is the set of characters that the database uses. The standard value is utf8 and is in almost all cases the correct one. Utf8 supports all languages, and as such is the most ideal value.
define('DB_COLLATE', '');: This is the specific subset of charset that your database should use. Do not change this unless you’re absolutely certain.

The security keys

Underneath the database settings, you have the security keys. These consist out of four secret keys and four salts. In very simplified terms, these keys make it harder to break your security barriers. The four salts further complicate your defenses. While the keys are nessecary, the salts are not, but it’s still recommended to use them!

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');

Your keys are not something you have to remember so make them as long and complicated as possible. You can also use one of the many online key generators.

The table prefix

The next important line of code is the table prefix. What this does is tell ClassicPress what the prefix of your table is. That is not very surprising, but what is the prefix of a table?

$table_prefix  = 'cp_';

In your database there will be several characters in front of the table name, usually cp_ or wp_. But you can change this during installation. Do not change this value after installation or you will break your database!

The debug settings

Under the table prefix is the debug setting. This decides if errors are logged or not. Set this to false to hide errors

define('WP_DEBUG', false);

If you set this to true you can also add extra lines to decide how exactly the errors are logged.
define( 'WP_DEBUG_DISPLAY', true );: Insert this line to enable display errors in text on the browser. Or change true to false to hide these errors.
define( 'WP_DEBUG_LOG', true );: Insert this line to enable an error_log file that you can access through FTP or your file manager. Or change true to false to block this feature. You can also change true into a path to add these logs to a specific file. For example: define( 'WP_DEBUG_LOG', '/error/cperrors.log' );

The directory settings

The final two settings can usually just be left alone. They are there to help ClassicPress find its settings.

/** Absolute path to the ClassicPress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up ClassicPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

The first part will define the ABSPATH. But what is the ABSPATH? Simply said it is a map for ClassicPress to find its own main folder. An absolute path to the main folder. The second setting will then use this ABSPATH to tell ClassicPress where it can find wp-settings.php.

Extra settings

Of course this is not everything that wp-config.php can do. There are many more settings for all kinds of objectives. If you want to use some of these, simply copy and paste them between WP-DEBUG and ABSPATH. Some of the more interesting of these are:

WP_SITEURL and WP_HOME

Using define( 'WP_SITEURL', 'http://example.com/classicpress' ); you can change the location of your ClassicPress installation without changing your home url. Simply use your main URL and then / with the name of the folder that you placed ClassicPress in. This overrides the option from settings in your CMS.

define( 'WP_HOME', 'http://example.com' ); can be used in combination with the above to change the home URL to keep it at root level or to change the homepage to a / something. It can also be used to force https or a main url when your domain has aliases. This also overrides the option from settings in your CMS. This makes sure that it can’t accidentally be changed by another user.

Moving directories

You can move several directories into seperate folders. These are uploads, themes, plugins and/or the entire wp-content folder. You can use the following settings for this, simply changing the relative URL:
Wp-content: define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' );
Plugins: define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/wp-content/plugins' );
Uploads: define( 'UPLOADS', '/wp-content/uploads' );

But what about themes?

Themes are a little more complicated. The theme folder is hardcoded relative to the wp-content folder. But what you can do is register an extra themes folder using:
register_theme_directory( dirname( __FILE__ ) . '/themes' );

Cache

Using define( 'WP_CACHE', true ); you can turn ClassicPress’ advanced caching features on. You can also turn them off using define( 'WP_CACHE', false );.

Core updates

You can use the auto core update settings to decide how your ClassicPress installation should deal with updates. There are three settings:
define( 'WP_AUTO_UPDATE_CORE', false );: This turns off all automatic updates.
define( 'WP_AUTO_UPDATE_CORE', true );: This turns on all automatic updates.
define( 'WP_AUTO_UPDATE_CORE', 'minor' );: This turns on all minor automatic updates but will not do major updates automatically. This is the default.

PHP memory limit

There are a lot of errors that occur related to php memory limit. And while its better to change this in php.ini, not everyone has access to this. You can use wp-config to define a limit using: define( 'WP_MEMORY_LIMIT', '64M' ); This does not always work as some hosting providers block this.

Wrapping up

All in all, you can do a lot of stuff with this little file that most people ignore after installation. There is also a lot that I haven’t even mentioned yet! I hope that this article has given you a bit more insight if you were unfamiliar with using the config. Of course with this power comes a lot of responsibility and I advise against experimenting on a production site because you can also break a lot here. Please be careful and quoting the wp-config file: /* That's all, stop editing! Happy blogging. */. Well actually ‘start editing responsibly’. 😉

About Patrick Klein

Front-end web developer and Google certified SEO and SEA professional from the Netherlands working for a company that has been around for over 50 years with a specialty in PR and advertisement. In recent years we have also been working on getting beautiful websites up and running that are affordable for smaller companies.

Notable Replies

  1. Great write up but I think you meant wp-config-sample.php there :wink:

  2. klein says:

    Haha, never trust automatic spellcheckers. Also, three people have read this thing before it went live and nobody noticed that. Thank you. I have updated the article on the main site.

  3. One of them was me! :flushed:

Continue the discussion at forums.classicpress.net

Participants