fbpx
 Back to blog

WordPress has more than 60 million users worldwide. Often it is needed to eliminate features in order to save money of your customers. One of the most effective solutions is access to the all-important MySQL databases required by WordPress. However, many hosts grant customers access to a few such databases only. So it may be a problem, if you need to host multiple blogs within the same domain or server name. But there is a solution.

installing-multiple-websites-into-a-single-mysql-database

Actually, you can easily change configuration settings to allow unique WordPress installs into a single MySQL database.

Also, you can specify advanced settings. For example, allow or deny the sharing of password and username information between these installations. This allows using an entirely different approach for multiple websites within the same database, since these advanced options are supplemented by a multisite and easier-to-use feature within the WordPress Dashboard.

mysql_wordpress_hero

MySQL WordPress

You need to change the wp-config.php file and be familiar with basic PHP to enable multiple instances in one MySQL database and make WordPress installations working side-by-side in a single database. Then, you should set up each installation in the WordPress installer, if you are not invoking the included multisite feature.

Locate the WordPress Configuration

WordPress is known for its well-organized file structure. It is great, however, it can make certain libraries or files hard to be found when they are needed. But is will not be a problem, if you know where the wp-config.php fileis located in every your WordPress installation.

You can find the relevant configuration here:

/public_html/your-wordpress-secondary-directory/wp-config.php

You can edit this file via a traditional desktop FTP client or with the help of a web-based file manager in the cPanel. FTP client is preferable due to its more advanced functions.

Make sure that you open the correct wp-config.php file. If you change the wrong file, it will affect your website productivity.

Change the Database Prefix of your WordPress Installation

All you need is to change the database prefix that determines where WordPress will store its information. It will instal multiple iterations of WordPress into the same MySQL database.

Locate the following string of PHP code, right about midway through in order to edit the database prefix of your WordPress installation:

$table_prefix = ‘wp_’; // example: ‘wp_’ or ‘b2’ or ‘mylogin_’

This indicates a wp_ database prefix which is the default for every WordPress installation.

That prefix will need to be changed, if this is a secondary installation of the software. If you leave it unedited, it will overwrite every page, post and user that has been created by the primary installation.

This prefix shows that the proper database tables were edited or manipulated.

Determine Whether it`s Needed to “Share” your Users Between Installations

While fitting multiple WordPress installations into a single database might be a challenge in terms of utilizing a “single sign-on”, the wp-config.php file can be told to use the user from other password and installation tables, since all WordPress installations will be installed into the single database. So you need to tell WordPress to look for users in a different prefixed table than it currently uses to store plugin data, posts and pages.

There are two lines near the configuration file bottom that assign profile data, password and username information to certain database prefixes. Generally this prefix is set to the variable $table_prefix, the same as the prefix mentioned above. If you change that variable, you will be able to store the user information anywhere or pull it in the same database from any other installation.

The user data configuration lines will be changed to pull information from the “mainblog” database prefix. It will be done for the purposes of this article. This is how the lines look like before the changes:

define(‘CUSTOM_USER_TABLE’, $table_prefix.’my_users’);

define(‘CUSTOM_USER_META_TABLE’, $table_prefix.’my_usermeta’);

They will look like this after the modification:

define(‘CUSTOM_USER_TABLE’, mainblog_’my_users’);

define(‘CUSTOM_USER_META_TABLE’, mainblog_’my_usermeta’);

Your users will be able to access every post comments and Dashboard on every website as soon as this change is applied to every WordPress installation located within the same database.

It doesn’t require the duplication of any information or tables, and it is an extremely convenient way to reduce overall size of the database.

Use WordPress Networks to Install Multiple Sites

WordPress has two separate versions. The first version is the standard version. The second is WordPress MU, unveiled in 2007. It was used to run multiple websites using a single database. However, in 2011 WordPress MU was discontinued and its features were included into the standard WordPress version under the name WordPress Networks.

The WordPress Networks feature is hidden by default but it can be enabled simply by instructing WordPress to display the Networks settings in the Dashboard and editing the wp-config.php file. It involves a minimal amount of redundant database resources.

Eliminating redundant information at many hosts will ensure the best utilization of restricted and limited space.

Add the following code to the wp-config.php file to enable the feature:

define(‘WP_ALLOW_MULTISITE’, true);

It will instruct the software to configure this network and tell WordPress to display the WordPress Networks control panel.

Also, you will have to fill in some email information, server’s addresses, the title of the network and to specify the network’s URL, where all blogs will be installed.

Then, you will see the WordPress Dashboard offering you some new code for the .htaccess file. It is necessary for directories or subdomains that will be properly mapped and managed by the Dashboard as well as for permalinks of your network.

Finally, you need to specify a “media” directory. It is a folder where uploaded videos and images will be stored within your new configuration of WP Network.

When finished, your network is ready to be utilized.

Two Ways to Deal with Limited Hosting Plans

There are some ways to work effectively with limited hosting plans. You can modify the default database prefix employed by the wp-config.php file or use the WordPress Networks feature. These two options are both great ways to run within a single database and get multiple sites.



Popular Posts

Like This Article? Subscribe to Our Monthly Newsletter!

Comments are closed.