Configuring WordPress with wp-config.php

WordPress configuration file

Basic Settings

The most important file in WordPress installation is wp-config.php file. It contains all the configuration settings needed to run a WordPress site smoothly. The first step in installation is to rename wp-config-sample.php to wp-config.php. The file wp-config.php is generally stored in the root directory of the WordPress installation. However you can move it to parent directory. That will make wp-config.php inaccessible by web browsers.  WordPress always checks for the wp-config.php file in the root directory of WordPress installation , if not found there it will look for the parent directory.

WordPress configurations are stored in the form of constants and that can be seen like below

When options are added to WordPress it must be noted that options must be added to the above the following line that reads.

This file contains all database connection settings , that includes database name, database user name, password, host, character set and collation

DB_CHARSET option defines which character set is used for storing values in database.

DB_COLLATE option defines which order to use while sorting the character set.

You should change these options before installing WordPress. It would create problems if you alter these after installation.

Security Settings

WordPress security can be enhanced by setting secret keys in the file. These adds random keys to password you set and make your website harder to hack. To have secret keys auto‐generated for you, visit the link to for secret key generation in your wp‐config.php fi le (‐key/1.1/salt/ ).  When you change these keys all WordPress cookies get invalidated and users need to login again.

Another security settings is to set $table_prefix variable to your choice, which will make you safe from SQL injunction attacks. Also this setting allows  you to have multiple WordPress site to be installed on same MySQL database.

WP_DEBUG option makes it easier to debugging errors. Enabling this displays errors on the screen instead of displaying white screen when error occurs. Also a great debugging option is SAVEQUERIES, it will display all database queries in an array.


Advanced wp-config.php Options

These options are not in the wp-config.php file and these must be manually added to the file

To set your WordPress address and blog address, use the following two options. These will change the siteURl and WordPress home settings temporarily. These are not changed in WordPress database.

We can set automatic backgroud updates for WordPress.

AUTOMATIC_UPDATER_DISABLED option allows automatic updates to be disabled

WP_AUTO_UPDATE_CORE option allows updates to happen either for major releases or minor releases.

We can set the wp-content directory to our chosen directory. It can be set by the following options

We can change our plugin directory using the below options

To set a custom location of uploads directory use the following option

WordPress saves revisions for each edit you have made. If you make too many edits quickly it can fill the database , which in turn make your website slow. Hence we can limit the number of revisions stored in the database using options. Also we can change the autosave time settings

WP_MEMORY_LIMIT option allows memory limit to be set for execution of WordPress PHP scripts.

Localisation of WordPress sites can be done using WPLANG option. It sets the language interface for WordPress site

We can have multiple WordPress sites to have a common user base using following options. These will allow websites to share author information among them.

You can set multiple cookie options . This will help usually on a multisite WordPress with subdomains.

For automatic installation of plugins and themes and automatic updates of core we can set FTP details directly in the configuration file.

WP_CACHE options lets you some cache plugins to work on your WordPress site. Setting it to true makes wp-content/advanced-cache.php file to be included and executed.

There are some options that force SSL login to both common user and administrative users in WordPress site.

EMPTY_TRASH_DAYS sets the number of days a deleted content is stored in WordPress site.

DISABLE_WP_CRON  allows cron jobs to be disabled

We can define multisite options in a WordPress site using following option. Setting this true makes a new SubMenu Tools->Network setup to be open. There we can setup multiple websites.

 The .htaccess fie

By default WordPress creates ugly urls with query strings to posts. By enabling pretty permalinks WordPress can create user friendly and search engine friendly URLs for posts.  We can go to Settings->Permalinks to setup permanent links structure. To allow permalinks in WordPress website mod_rewrite must be enabled and rewrite rules must be defined in .htaccess file in the root directory of WordPress.

The secret of permanent links can be set through following rewrite rules in the .htaccess file

If there is an available file for URL structure then no rewriting rules applied, if incoming URL doesn’t match any file structure, then rewriting rule is applied for permanent links and suitable post is extracted and displayed.

There are plenty of configurations allowed through these two files which allow fine tuning of WordPress sites.

Leave a Reply

Back to Top
%d bloggers like this: