Solution:
Put your custom wp-config.php code before this:
/** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');