wp-config.php settings cheat sheet
Database
-
define( 'DB_NAME', 'database_name_here' );The name of the site's database, as created in your hosting control panel or on the database server.
-
define( 'DB_USER', 'username_here' );The user that connects to the database. Use a separate user for each site, with privileges on that site's database only.
-
define( 'DB_PASSWORD', 'password_here' );The password of the database user. After you change the password in the database, update DB_PASSWORD as well, or the site shows the error Error establishing a database connection.
-
define( 'DB_HOST', 'localhost' );The address of the database server. With most hosting services, localhost is correct and doesn't need changing. When the database is on a separate server, enter the server's hostname or IP address.
-
define( 'DB_HOST', 'localhost:3307' );Connects on a port other than the default: add a colon and the port number after the hostname. The same form works with an IP address, for example 127.0.0.1:3307.
-
define( 'DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock' );Connects through a Unix socket: after the colon, enter the path to the socket file of the database server. The path varies between servers, so check it in the database server's settings.
-
define( 'DB_CHARSET', 'utf8mb4' );The character set of the tables. utf8mb4 stores every character, including emoji. Even when the value is utf8, WordPress actually uses utf8mb4. Caution: changing this constant on an existing site can cause problems displaying content, so change it only after a backup.
-
define( 'DB_COLLATE', '' );How text in the tables is sorted and compared. An empty value, the default, leaves the choice automatic, and WordPress uses utf8mb4_unicode_520_ci when the server supports it. Here too, a change on an existing site can cause problems.
-
$table_prefix = 'wp_';The prefix of the table names in the database. It's a variable, not a constant, so it's written without define. Use only letters, numbers, and underscores, and when several sites share one database, give each site its own prefix. Changing this line on an existing site doesn't rename the tables, and the site stops working.
Security keys
-
define( 'AUTH_KEY', 'put your unique phrase here' );The AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, and NONCE_KEY keys improve the encryption of the information stored in login cookies. Each value should be a long, random string unique to the site. All four keys are required. Don't leave the sample value in place.
-
define( 'AUTH_SALT', 'put your unique phrase here' );The salts, AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT, and NONCE_SALT, complement the keys. They're recommended but not required, and when they're missing, WordPress generates them itself.
-
https://api.wordpress.org/secret-key/1.1/salt/A WordPress.org service that returns eight ready-made define lines with random values. Replace all the key lines in the file with them. Changing the keys invalidates all login cookies, and all users, including site administrators, have to log in again.
Troubleshooting
-
define( 'WP_DEBUG', true );Turns on debug mode, which reports all errors, warnings, and notices. The default is false. Write true and false without quotes. In debug mode, errors are also shown on the page by default, so on a live site, combine it with WP_DEBUG_LOG and with WP_DEBUG_DISPLAY turned off.
-
define( 'WP_DEBUG_LOG', true );Saves errors to the wp-content/debug.log file, and works only when WP_DEBUG is on. The file is in a folder that can be accessed from the browser, so delete it when you finish checking.
-
define( 'WP_DEBUG_LOG', '/home/user/logs/wp-errors.log' );Instead of true, you can enter a full path to a file, so the log is saved outside the site folder and visitors can't access it. The folder must exist and be writable.
-
define( 'WP_DEBUG_DISPLAY', false );Stops errors from being shown on the page when debug mode is on, and errors are written only to the log. The default is true.
-
@ini_set( 'display_errors', 0 );Turns off the display of PHP errors on the page. In the official documentation, this line appears together with WP_DEBUG_DISPLAY turned off, so errors aren't shown even when the server settings display them.
-
define( 'SCRIPT_DEBUG', true );Loads the full, unminified versions of the core JavaScript and CSS files. Suited to development and to troubleshooting the WordPress dashboard, not to a live site.
-
define( 'SAVEQUERIES', true );Saves every database query, with its run time and the function that called it, for analysis. Caution: this option slows the site down, so turn it on only for a short time and not on a live site.
-
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );Turns off recovery mode, which shows a general message about a critical error and emails the site administrator a login link. Useful in a development environment, to see the full error instead of the general message.
-
define( 'WP_ALLOW_REPAIR', true );Turns on the database repair tool at wp-admin/maint/repair.php. Caution: the page opens without logging in, so delete the line as soon as the repair is done.
Memory, cache, and content
-
define( 'WP_MEMORY_LIMIT', '256M' );The amount of memory WordPress requests for each page load. The default is 40M for a single site and 64M for a multisite network. When the server sets a lower memory limit, also raise memory_limit in the PHP settings.
-
define( 'WP_MAX_MEMORY_LIMIT', '512M' );The memory limit in the WordPress dashboard and for image processing, which usually use more memory than a regular page load.
-
define( 'WP_CACHE', true );Loads the wp-content/advanced-cache.php file at the start of every request, when the file exists. The constant alone doesn't turn on caching, and page caching plugins usually set it themselves.
-
define( 'WP_POST_REVISIONS', 5 );The maximum number of saved revisions for each post and page. The default is true, meaning no limit. A small value keeps the posts table from growing on a site with many edits.
-
define( 'WP_POST_REVISIONS', false );Turns off saving revisions. Autosave in the editor keeps working.
-
define( 'AUTOSAVE_INTERVAL', 120 );The interval in seconds between autosaves in the editor. The default is 60 seconds.
-
define( 'EMPTY_TRASH_DAYS', 30 );The number of days items stay in the trash before they're permanently deleted. The default is 30. Caution: the value 0 turns off the trash, and items are deleted permanently without a confirmation prompt.
-
define( 'IMAGE_EDIT_OVERWRITE', true );When you edit an image in the media library, only one set of edited files is kept, instead of new files with every edit, and it's deleted when you restore the original image.
URLs and folders
-
define( 'WP_HOME', 'https://example.com' );The site address visitors type. The constant overrides the home value in the database without changing it. Enter a full URL with https:// and no trailing slash. Useful when you migrate a site and have no access to the WordPress dashboard.
-
define( 'WP_SITEURL', 'https://example.com' );The address where the WordPress core files are located, which overrides the siteurl value in the database. When WordPress is installed in a subfolder, for example /wordpress, the address includes it.
-
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/blog/wp-content' );A new location for the wp-content folder, as a full server path with no trailing slash. Set WP_CONTENT_URL along with it.
-
define( 'WP_CONTENT_URL', 'https://example.com/blog/wp-content' );The full URL of the wp-content folder after the move, with no trailing slash.
-
define( 'WP_PLUGIN_DIR', dirname( __FILE__ ) . '/blog/wp-content/plugins' );A new location for the plugins folder, as a full path with no trailing slash. Set its URL with WP_PLUGIN_URL. The themes folder can't be moved with a constant.
-
define( 'UPLOADS', 'blog/wp-content/uploads' );A different location for the folder of files uploaded to the site. The path is relative to the WordPress root folder, with no leading slash.
-
define( 'COOKIE_DOMAIN', 'www.example.com' );The domain WordPress cookies are saved for. Needed only in unusual setups, for example when a subdomain serves static files. Browsers don't save a cookie whose domain doesn't match the site address, so a wrong value can prevent logging in to the WordPress dashboard. Don't set this constant without a real need.
Security
-
define( 'DISALLOW_FILE_EDIT', true );Turns off the plugin and theme file editor in the WordPress dashboard, so code can't be added to the site through the editor. The setting doesn't stop malicious files from being uploaded in other ways, but it may stop some attacks.
-
define( 'DISALLOW_FILE_MODS', true );Turns off installing and updating plugins and themes from the WordPress dashboard, and the file editor as well. Caution: the constant also turns off all automatic updates, including core security updates, so install updates another way, for example with WP-CLI.
-
define( 'FORCE_SSL_ADMIN', true );Requires HTTPS for logging in and across the WordPress dashboard, so the site needs a valid SSL certificate. The old FORCE_SSL_LOGIN constant is no longer used.
-
define( 'WP_ENVIRONMENT_TYPE', 'staging' );The environment type: production, staging, development, or local. An invalid value counts as production, which is the default. In the development environment, when WP_DEBUG isn't defined, debug mode turns on automatically, and plugins can read the value and adapt their behavior to a test site.
-
define( 'WP_HTTP_BLOCK_EXTERNAL', true );Blocks outgoing requests from the site to external servers, and allows only the local server and the site itself. Caution: without a list of exceptions, requests to the WordPress.org update servers are blocked too.
-
define( 'WP_ACCESSIBLE_HOSTS', 'api.wordpress.org,*.github.com' );The list of servers the site may contact when WP_HTTP_BLOCK_EXTERNAL is on, separated by commas. You can use an asterisk for subdomains.
Updates
-
define( 'WP_AUTO_UPDATE_CORE', 'minor' );Automatic updates for minor releases only, such as maintenance and security releases, without an automatic move to a new major version. When the constant is set, it overrides the setting on the Updates screen.
-
define( 'WP_AUTO_UPDATE_CORE', true );Automatic updates for all core releases, including new major versions.
-
define( 'WP_AUTO_UPDATE_CORE', false );Turns off all automatic core updates. Caution: security releases won't be installed automatically either, so you have to update the site manually.
-
define( 'AUTOMATIC_UPDATER_DISABLED', true );Turns off all types of automatic updates, for the core and for other components. Caution: the site won't get automatic security updates, so set it only when updates are managed another way.
Scheduled tasks (cron)
-
define( 'DISABLE_WP_CRON', true );Turns off WP-Cron, which by default runs on visitor page loads. Caution: once it's off, scheduled tasks, such as publishing scheduled posts and checking for updates, won't run until you set up a real cron job on the server.
-
*/15 * * * * wget --delete-after https://example.com/wp-cron.phpA crontab line that runs WP-Cron every 15 minutes. Set it up on the cron jobs screen in your hosting control panel, if it has one, or in the crontab file on the server, and replace example.com with your site address.
-
define( 'WP_CRON_LOCK_TIMEOUT', 60 );The minimum number of seconds between two WP-Cron runs, so it doesn't run several times in a row.
-
define( 'ALTERNATE_WP_CRON', true );An alternative method that runs the tasks through a redirect of the visitor, when the server can't make requests to itself and WP-Cron doesn't run. According to the official documentation, it carries risks, so use it only when there's no other solution.
Permissions and file system
-
define( 'FS_METHOD', 'direct' );Sets how WordPress writes files during installs and updates: direct, ssh2, ftpext, or ftpsockets. WordPress usually picks direct itself when it's suitable. If it asks for FTP details, the file ownership isn't set correctly. Caution: forcing direct on a server that isn't configured properly can create security problems, so it's better to fix the file ownership.
-
define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );The permissions for folders WordPress creates. The value is written as an octal number, with a leading 0 and no quotes.
-
define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) );The permissions for files WordPress creates. The value 0644 lets the owner read and write, and everyone else only read.
Multisite network
-
define( 'WP_ALLOW_MULTISITE', true );The first step in setting up a multisite network: adds a network setup screen to the Tools menu in the WordPress dashboard. When the setup is done, WordPress shows more lines to add to the wp-config.php and .htaccess files. Back up the site before the setup.
-
define( 'NOBLOGREDIRECT', 'https://example.com' );In a multisite network, the address visitors are redirected to when they reach a subdomain or subfolder of a site that doesn't exist in the network.
Proxy server
-
define( 'WP_PROXY_HOST', '192.168.84.101' );The address of the proxy server the site uses to contact external servers, for example to check for updates. Needed only on a network where internet access goes through a proxy.
-
define( 'WP_PROXY_PORT', '8080' );The port of the proxy server. It has no default, so you must set it.
-
define( 'WP_PROXY_USERNAME', 'username' );The username for the proxy server, when it requires authentication.
-
define( 'WP_PROXY_PASSWORD', 'password' );The password for the proxy server, when it requires authentication.
-
define( 'WP_PROXY_BYPASS_HOSTS', '*.wordpress.org, api.example.com' );Servers the site contacts without going through the proxy, separated by commas, with asterisk support. There's no need to include localhost and the site itself, because they always bypass the proxy.
No matching constants.
Where the file is and how to edit it
The wp-config.php file is in the WordPress root folder, next to the wp-admin and wp-content folders. When WordPress is installed in the site's root folder, you can move the file one folder up, and WordPress finds it there too. Save a copy of the file before every edit, because a single syntax error, such as a missing quote or semicolon, takes the whole site down.
Add new constants above the line /* That's all, stop editing! */, because lines added after it are read once WordPress has already loaded, and some of them won't take effect. Define each constant only once, and write true, false, and numbers without quotes, because the value 'false' in quotes counts as true.
The file contains the database password and the security keys, so the official documentation recommends that only the owner and the web server can read it, usually with 400 or 440 permissions, depending on the user the site runs under. Permissions are explained on the Linux file permissions page, and to block browser access to the file, use the .htaccess cheat sheet.
You can also change constants from the command line with wp config set, and more commands are on the WP-CLI commands page. To create new security keys, use the WordPress salt key generator, and fixes for common issues are on the common WordPress errors page.
With WordPress hosting plans, you install WordPress with one click and can edit the wp-config.php file in the file manager in the control panel. Every plan includes a free SSL certificate, daily backups, and personal support via HelpDesk. For a busy site that needs guaranteed resources and full root access, a WordPress VPS is the right fit.
wp-config.php FAQ
Where is the wp-config.php file?
The wp-config.php file is in the root folder of your WordPress site, the same folder as the wp-admin and wp-content folders. On a hosting plan, you open it in the file manager in the control panel or over FTP, and on a VPS, you can also edit it with a text editor on the command line. When WordPress is installed in the site's root folder, the file can also be one folder up, and WordPress finds it there automatically.
How do I limit the number of saved post revisions?
Add the line define( 'WP_POST_REVISIONS', 5 ); to wp-config.php, above the line That's all, stop editing. From then on, WordPress keeps up to five revisions for each post and page, so the posts table in the database doesn't keep growing. The value false turns off revisions completely, and autosave in the editor keeps working.
How do I change the WordPress security keys?
Create eight new values with the WordPress salt key generator or the official WordPress.org service, and replace the lines from AUTH_KEY to NONCE_SALT in wp-config.php with them. On a server with WP-CLI, the wp config shuffle-salts command does this in one step. After the change, all users are asked to log in again, which makes it a quick way to end open sessions on every device.
How do I run WordPress scheduled tasks at fixed times?
By default, WP-Cron runs when visitors load pages, so on a site with few visits, tasks may be delayed. Add the line define( 'DISABLE_WP_CRON', true ); to wp-config.php and set up a cron job that requests your site's wp-cron.php URL at a fixed interval, for example every 15 minutes. Set up the job on the cron jobs screen in your hosting control panel, if it has one, or in the crontab file on a VPS.
How do I stop code editing from the WordPress dashboard?
Add the line define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php, and the plugin and theme file editor disappears from the WordPress dashboard. From then on, you make code changes in the file manager or over FTP, and installing and updating plugins keeps working as usual. That's why this setting suits almost every site.