Good defaults for Wordpress (on a cPanel server)

After spending some time finding problems in a few Wordpress sites, both local in my dev environment and on a cPanel hosted server, I finally decided to sit down and work out the best base settings for each environment. The settings I've picked are mainly around dev and debugging, however I will try and keep this post updated as I come across new settings.

php.ini settings

Local Dev
These settings can be set in your local dev env php.ini (e.g. in c:\php-installdir\php.ini)
display_errors = On
display_startup_errors = On
log_errors = On
error_log = C:/temp/php-errors.log
error_reporting = -1
Production / hosted
On cpanel servers, create a file in public_html: ".user.ini" (/home/[user]/public_html/.user.ini). Its without quotes but starting with a dot. Similar contents but limited by what you can set.
display_errors = Off
error_log = /home/[user]/logs/php-errors.log
error_reporting = -1
Depending on the server you may be able to alternatively use .htaccess (/home/[user]/public_html/.htaccess):

php_value display_errors Off
php_value error_log /home/[user]/logs/php-errors.log
php_value error_reporting -1

wp-config.php settings

Local Dev
// outputs more errors
// https://codex.wordpress.org/WP_DEBUG
define('WP_DEBUG', true);
// don't set WP_DEBUG_LOG=true as it overrides error_log set for php.ini
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);

// stop external http connections (this gives false errors when running locally)
define('WP_HTTP_BLOCK_EXTERNAL', true);

// not needed in dev most of the time
define('DISABLE_WP_CRON', 'true');
Production / hosted
// you might want to enable/disable this one as you come across errors
//define('WP_DEBUG', true);

// stop external http connections, speeds up loads
define('WP_HTTP_BLOCK_EXTERNAL', true);

/*
 * Disable the 'virtual cron'. For scheduled posts etc, instead use actual cron. see:
 * http://www.inmotionhosting.com/support/website/wordpress/disabling-the-wp-cronphp-in-wordpress
 */
define('DISABLE_WP_CRON', 'true');

Comments