Rename table prefix on existing WordPress site

Follow these few steps to rename the table prefix of your existing WordPress site.

Edit wp-config.php and change

$table_prefix = 'wp_';

to any other prefix, try to make it abstract and hard to be guessed by anyone, for example:

$table_prefix = 'v5r33w67ee_';

Rename the tables in your database, these are the SQL queries to rename the core tables:

RENAME table `wp_users` TO `v5r33w67ee_users`;
RENAME table `wp_usermeta` TO `v5r33w67ee_usermeta`;
RENAME table `wp_comments` TO `v5r33w67ee_comments`;
RENAME table `wp_commentmeta` TO `v5r33w67ee_commentmeta`;
RENAME table `wp_links` TO `v5r33w67ee_links`;
RENAME table `wp_options` TO `v5r33w67ee_options`;
RENAME table `wp_posts` TO `v5r33w67ee_posts`;
RENAME table `wp_postmeta` TO `v5r33w67ee_postmeta`;
RENAME table `wp_terms` TO `v5r33w67ee_terms`;
RENAME table `wp_term_taxonomy` TO `v5r33w67ee_term_taxonomy`;
RENAME table `wp_term_relationships` TO `v5r33w67ee_term_relationships`;

Add the queries to rename any other existing table that have been created from other plugins or themes.
You can also rename the tables in phpMyAdmin, by clicking on the operations tab

Update the references to the old table prefix in the usermeta and options table running these SQL queries.

UPDATE `v5r33w67ee_usermeta` SET `meta_key` = REPLACE( `meta_key`, 'wp_', 'v5r33w67ee_' );
UPDATE `v5r33w67ee_options` SET `option_name` = 'v5r33w67ee_user_roles' WHERE `option_name` = 'wp_user_roles';

Repair corrupt database

If the database is corrupt probably the user isn’t able to login, you can run a script located on http://your_domain/wp-admin/maint/repair.php, this script can run without needing the user to log in. But before running the script you must add the following line in the wp-config.php file:

define( 'WP_ALLOW_REPAIR', true );

NOTE: Do not forget to delete the line after the database is repaired.

Extra configuration in wp-config.php

Set WordPress to empty the trash automatically after a number of days.

define( 'EMPTY_TRASH_DAYS', 30 );

Change the Autosave Interval for your posts, pages, etc.
Set the seconds that you would like to have your content saved while you are editing it.

define( 'AUTOSAVE_INTERVAL', 160 );

Limit posts revisions. Or disable them with setting it to false.

define( 'WP_POST_REVISIONS', 3 );

Enable the Debug mode without displaying it on your pages.
These lines will save the error log into debug.log file in your wp-content/ directory.

define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);

The following lines are already in the wp-config.php file, and you should always change the default values.
A way to do this is going to https://api.wordpress.org/secret-key/1.1/salt/ and replace the default values with the ones given.

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Enable Multisite functionality.

define( 'WP_ALLOW_MULTISITE', true );

Define the Site URL address.

define('WP_HOME', 'http://www.wptips.me');
define('WP_SITEURL', 'http://www.wptis.me');

Override file permissions.

define('FS_CHMOD_FILE', 0755);
define('FS_CHMOD_DIR', 0644);

You can set Automatic Database Optimizing. If a database is corrupt normally the user isn’t able to login so to run this script the user doesn’t need to be logged in. It’s recommended to delete this line after you repair your database.
After including the line in your wp-config.php the script can be found at http://your_domain/wp-admin/maint/repair.php

define( 'WP_ALLOW_REPAIR', true );

You can increase your PHP memory limit (won’t work with all hosts).

define('WP_MEMORY_LIMIT', '64M');

Define custom user tables.

define('CUSTOM_USER_TABLE', $table_prefix.'custom_users');
define('CUSTOM_USER_META_TABLE', $table_prefix.'custom_usermeta');

Disable plugin and themes editors:

define( 'DISALLOW_FILE_EDIT', true );

Change the wp-content directory name and location:

define( 'WP_CONTENT_DIR', dirname(__FILE__)  . '/some-folder/site-content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] .  '/some-folder/site-content';

Save the database queries to an array stored in the global $wpdb->queries.
This will have a performance impact on your site, turn off when not debugging.

define('SAVEQUERIES', true);

And don’t forget to protect your wp-config.php through the .htaccess file:

1
2
3
4
5
 
<Files wp-config.php>
    order allow,deny
    deny from all
</Files>

For more advanced use of wp-config.php visit http://codex.wordpress.org/Editing_wp-config.php