Understanding wp-config.php: A practical guide for WordPress configuration
wp-config.php stores your WordPress database credentials and core settings. This guide explains its purpose, common options, security best practices, and how to fix frequent issues.
Introduction to wp-config.php
wp-config.php is a critical file in WordPress. It contains the site’s database credentials and a handful of settings that control how WordPress loads and interacts with your environment.
What is wp-config.php?
The wp-config.php file is the main configuration file for WordPress. It defines constants that WordPress uses to connect to the database, locate the installation, and enable or disable features.
Core purposes
- Store database credentials: DBNAME, DBUSER, DBPASSWORD, DBHOST
- Set character set and collation: DBCHARSET, DBCOLLATE
- Define table prefix: $table_prefix
- Enable debugging and logging: WPDEBUG, WPDEBUGLOG, WPDEBUG_DISPLAY
Where is it located
You’ll find wp-config.php in the WordPress root directory. In most setups it sits alongside wp-admin, wp-content, and wp-includes. For added security, some admins move wp-config.php one directory above the web root.
Key configuration options in wp-config.php
Database settings
- define('DBNAME', 'yourdb_name');
- define('DBUSER', 'yourdb_user');
- define('DBPASSWORD', 'yourdb_password');
- define('DB_HOST', 'localhost');
- define('DB_CHARSET', 'utf8');
- define('DB_COLLATE', '');
Security keys and salts
Defines for authentication keys and salts: AUTHKEY, SECUREAUTHKEY, LOGGEDINKEY, NONCEKEY, and their corresponding salts. Generate unique values to improve security. If you don’t see them, WordPress can fill them in during installation or you can update them manually.
Debug settings
- define('WP_DEBUG', false);
- define('WPDEBUGLOG', true);
- define('WPDEBUGDISPLAY', false);
Site URL and home
- define('WP_HOME', 'https://example.com');
- define('WP_SITEURL', 'https://example.com');
Other useful constants
- define('FORCESSLADMIN', true);
- define('DISALLOWFILEEDIT', true);
- define('DISALLOWFILEMODS', true);
- define('WPALLOWREPAIR', true) // use carefully and remove when not needed
Security best practices
Move wp-config.php
Where possible, move it one directory above the web root to prevent direct access via the browser.
Permissions
Set restricted file permissions (e.g., 640 or 600) to limit access.
Keep credentials out of version control
Avoid committing wp-config.php with credentials to public repos. Use environment variables or separate config files for production.
Use secure keys and rotate
Ensure all security keys are defined and updated if you suspect compromise.
Disable file editing and mods
Set DISALLOWFILEEDIT and DISALLOWFILEMODS to true to reduce risk of unauthorized changes.
Protect with proper hosting and backups
Ensure your hosting environment is secure and keep regular backups.
Common issues and fixes
Incorrect database credentials
Double-check DBNAME, DBUSER, DBPASSWORD, and DBHOST in wp-config.php.
Database connection errors
If you see error establishing a database connection, verify credentials and that your database server is reachable.
Permissions issues
If WordPress cannot read wp-config.php, adjust file permissions.
Incorrect table prefix
Make sure $table_prefix ends with an underscore and matches your database tables.
Web server configuration
If you moved wp-config.php, ensure your server configuration allows the new path, and that ABSPATH is correctly defined.
Conclusion
wp-config.php is small but powerful: it ties WordPress to its database and defines essential behavior. Understanding its contents and keeping it secure helps improve both reliability and security of your site.
Share This Article
Spread the word on social media
Anne Kanana
Comments
No comments yet. Be the first to share your thoughts!