Configuration file in wordpress

Configuration file in WordPress

Configuration file in WordPress

The WordPress configuration is very essential in order to set the website. The configuration file is stored at the wp-config.php. This file is found at the root of our installed WordPress file directory and this contains all basic configuration details of our website, such as database connection information.

When we install the WordPress or download a fresh copy of WordPress, the wp-config.php file do not exist at any place. When the WordPress setup process get initiated, it will create a wp-config.php file for us based on the information we have provide.

Sometime it doesn’t create due to some error than, we will be able to create manually by finding the wp-config-sample.php file (located at the same place) or you can use some old file and perform the changes and edit it as required, and then save it as wp-config.php.

Database Connection configuration in Configuration file in WordPress

In order to connect WordPress to the database this is must required part, If we are not doing this than we will not able to setup the WordPress website. For this we are having few definition like,

  • Database Name (DB_NAME) : Database Name which we wanted to connect.
  • Database Username (DB_USER: Username to connect to the host of my Sql.
  • Database Password (DB_PASSWORD) : Password to connect to the host of my Sql.
  • Database Host (DB_HOST) : The hostname of our Database Server. A port number, Unix socket file path or pipe may be needed as well.
/** The name of the database for WordPress */
define('DB_NAME', 'my_databasename');

/** MySQL database username */
define('DB_USER', 'database_username');

/** MySQL database password */
define('DB_PASSWORD', 'database_password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

Database character set and Collation configuration in Configuration file in WordPress

Character set is used to allow the designation of the database character set. This allow us to store informations using a variety of character sets like utf8,  ascii,  cp866utf32. The default value of DB_CHARSET is utf8 (Unicode UTF-8) which is always the best option. UTF-8 supports many languages. and the DB_COLLATION is set according to the DB_CHARSET if it is utf8 than the Collation will be utf8_general_ci

//This will define the 
define( 'DB_CHARSET', 'utf8' );</pre>

define( 'DB_COLLATE', 'utf8_general_ci' );

The above code will show the data in UTF8 Unicodes.

Security Key configuration in Configuration file in WordPress

There is set of key we need to keep in this file. This keys will ensure better encryption of data stored in cookies in order to provide the data security. This keys can be generated using the Salt Generator of WordPress .  This is consist of AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT and NONCE_SALT.

A secret key called as Salt, makes our site safe from hacking and access harder to crack by adding random elements to the password.

define('AUTH_KEY',         '0dQfP&?RC[oRQ{^|U]FQQtL>QQQ8pT_&{^l);K4u1]b1q&|P&e;oV7:F_N@J1%Qb');
define('SECURE_AUTH_KEY',  'a8:3N0WJmns7 zn6xKD?K+O39,`@c|a4vd(DB$lEDW/2lI#x]u*vos*-tr.+.+e[');
define('LOGGED_IN_KEY',    'B|qMk5P-w,!c$1<Gfd+lW#_z.ULZ1Q?WJI1~=W%Sw$T@E9^qww!|WPffnQuv{tNZ');
define('NONCE_KEY',        'Qay7EP^OX&S+BqZr^e&E-}y)%h+yl+,-,aSbl0Mslw?WRa-rsT(Y#p;y72rXDv$(');
define('AUTH_SALT',        '-]aap!C.%8gI`UR&8:EB=UH%Tw@:;f45(4!xOCc5<wWP6E+v`+R4#cP*ITT,;] 1'); define('SECURE_AUTH_SALT', 'O/!f>Z4|q-(-&fqBH+,4k[q)qE$9)3sAh$ZA>&/2A{8M$Nq%j@jW |m(#)H!C0-1');
define('LOGGED_IN_SALT',   'k1Z>{;wbw-M28wQABMqwkMr+]R>?`l*c:G+ W8qV[bPleDY@<41.bF7O[x_uDLEe');
define('NONCE_SALT',       '/+8B&0]O8_{5<mU|QQ%KTffxF|sU[a<H6HE)i-<9|PMj?(c`TSC2HEAReI~6U|N}');

Database table prefix configuration in Configuration file in WordPress

The $table_prefix is the Value kept in as the prefix of our database tables. the default value is wp_ for our database prefix which can be changes as per our need. Typically this is changed if you are installing multiple WordPress blogs in the same database.

$table_prefix = 'wp_';

NOTE : It is advice to change it in order to provide the additional security.

Site URL and Home URL configuration in Configuration file in WordPress

We can set the WP_SITEURL, this will allow us to define the WordPress address (URL). The value defined is the address where your WordPress core files are stored. we have to keep the http:// in the url. there should be no forward slash “/” at the end. Setting this value in wp-config.php will overrides the wp_options table value for siteurl.

define( 'WP_SITEURL', 'http://www.example.com' );
//to set it dynamically we can use the code below.
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress' );

WP_HOME is one more optional option of wp-config.php. This is similar to WP_SITEURL, WP_HOME will also overrides the wp_options table value for home but does not change it permanently. home is the address you want people to type in their browser to reach your WordPress blog. It should include the http:// part and should not have a forward slash “/” at the end.

define( 'WP_HOME', 'http://example.com/wordpress' );

Moving Folders using Configuration file in WordPress

We can move the wp-content directory, which saves our themes, uploads, and plugins, outside of the WordPress application directory. This is helpful when we want to create a Custom Content Delivery Network.

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/cdn/wp-content' );

To change the path of the plugin folder we need to add the option wp_plugin_dir and the destination folder without any trailing froward slash ‘/’.

define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/blog/wp-content/plugins' );

To change the path of the upload folder we need to add the option UPLOADS and the destination folder without any trailing froward slash ‘/’.

define( 'UPLOADS', '/blog/wp-content/plugins' );

Modify Auto Save Interval, Post Revision Configuration file in WordPress

There is only one autosave per user for any post. New autosaves will overwrite the old autosaves. This means that no, your tables do not grow by one row every 60 seconds. But still if you want to increase the autosave interval in wordpress than we need to put AUTOSAVE_INTERVAL with the values in seconds.

define('AUTOSAVE_INTERVAL', 300);

The WordPress revisions stores the record of saved draft or published posts. The revision system also allows us to check what changes are made in each revision by dragging a slider. But it is sometime it is having a pile of the revisions so in order to limit the post revision in WordPress we need to add the WP_POST_REVISIONS with the numbers only in integer. this will limit the number of the revision but if we want to disable it than we have to use WP_POST_REVISIONS with false.

//Disable the revision
define( 'WP_POST_REVISIONS', false );
//Restrict it to 3 revisions
define( 'WP_POST_REVISIONS', 3 );

Disable WordPress Auto Update in Configuration file in WordPress

The easiest way to stop the WordPress core updates is to add the option WP_AUTO_UPDATE_CORE with false.

define('WP_AUTO_UPDATE_CORE', true);

NOTE : It is not advise to disable core update as the security patch and the new features are getting added in core. hence please do not disable the auto update feature of the WordPress.

Disable/ Enable Cache in Configuration file in WordPress

Plug in are having very important role in the WordPress but many time we need to disable the editor of the plugin from the WordPress to disable the editor we need to option wp_cache true.

define( 'WP_CACHE', true );

Empty Trash Configuration in Configuration file in WordPress

We are deleting some unnecessary post or other data that get stored in the trash and lasts till we permanently delete it manually but what if we need to delete trash data after some interval? To remove trash post after some interval we  need to add EMPTY_TRASH_DAYS with the number of days. This will remove the data after defined interval. This will get deleted using the cron job this will not ask for confirmation to delete.

define('EMPTY_TRASH_DAYS', 30);

Error Debugging and Logging

Many time we get error in WordPress while development or we need to debug the data in wordpree or check for the error than this can be achieve this we need to put few option together

WP_DEBUG_LOG is a component of WP_DEBUG which saves all errors to a debug.log log file inside the /wp-content/ directory.

WP_DEBUG_DISPLAY is one more component of WP_DEBUG which controls whether debug messages are shown inside the HTML of pages or not.

//This will show the error and the notice. Disable will hide the notice but not the error.
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false); 
define('WP_DEBUG_DISPLAY', false); 
define('SCRIPT_DEBUG', false);

While we are in coding if we want to debug we need to use error_log( print_r( $log, true ) ); this add the requested data to the data debug.log log file inside the /wp-content/ directory. This can show arrays as we used print_r.

About Pashupatinath Mishra

Pashupatinath Mishra is Software Developer and our Fulltime blogger. He is having good knowledge on the Different Technologies and also having shareable knowledge on Nutrition, Science Topics, Travel and History.

Website

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.