Can Two WordPress Sites Share A Database

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email
Share on pinterest

Setting up a WooCommerce website is a great way to set up an online store and earn money without leaving the comfort of your home. Depending on your operation, you might need to set up two sites for your products, or you may want to set up one site for your products and another one to promote them using a standard WordPress site.

Can two WordPress websites share the same database? Yes, you can set up two or more WordPress sites using only one database. There are a couple of ways to set this up. First, you can set up a single WordPress instance for two sites using the WordPress Multisite feature. Or, you can set up two WordPress instances using one database while installing WordPress.  

Continuing, we will discuss both methods of setting up two or more websites using only one MySQL database. And, we will cover the pros and cons of using the WordPress Multisite feature versus setting up multiple WordPress instances using a shared database.

Method One: Setting up a Single WordPress Instance Using a Single Database

The WordPress Multisite feature is ideal for creating a network of sites using one installation, or instance, of WordPress. Using this feature also allows you to use a single MySQL database for as many sites as you require.

Below are basic step-by-step instructions for setting up two WordPress sites using this feature. For advanced instructions to include graphics, you can click here to visit the WPBeginner Multisite Installation Guide.

Additionally, you can click here for an instructional video on YouTube showing how to set up WordPress Multisite. And you can click here for a YouTube video showing you how to install plugins on a Multisite Network and how to set it up on WooCommerce sites.

Requirements for Setting Up a Multisite Network

Before installing WordPress Multisite, you will need to make sure that:

  1. You have an active WordPress installation. (Although you can use a shared hosting service, we recommend you have either VPN hosting or a dedicated server due to WordPress Multisite system requirements.)
  2. You have access to the site directory using a control panel like Plesk or cPanel. (Your hosting company can help with this if you don’t already have access.) In the alternative, you will need access to the site directory using an FTP application like FileZilla Client.
  3. You have a full backup of your current WordPress site to include the installation files.

Step One: Choosing Your Domain Structure

Now it’s time to choose whether to use subdomains or subdirectories for the URL structure for your multisite network.

  • Subdomains: The URLs for your subsites will have the following structure: http://subsite1.yourdomain.com with “subsite1” being your first site and “yourdomain.com” being the domain of your main website.
  • Subdirectories: Similarly, the URLs for your subdirectories will have the following structure: http://yourdomain.com/subsite1/

If you choose to use Subdomains for your multisite network, you will need to activate wildcard subdomains on your server, as detailed in the next section. If you opt to use subdirectories, you can skip that step and move on to Step Three.

Step Two: Activating Wildcard Subdomains

  1. Login to your hosting service’s control panel and scroll down to the section labeled Domains and click on Subdomains.
  2. Enter an asterisk (*) in the subdomain field and select your main domain from the adjacent dropdown menu if you have more than one domain.
  3. Your control panel will automatically display the document root in the field below. Once it does, click on the Create button, and you are through activating wildcard subdomains.

Step Three: Activating the WordPress Multisite Feature

There are four simple steps you must perform to activate the WordPress Multisite feature to an existing WordPress installation.

  1. Using your control panel or FTP client, open up the wp-config.php file for editing and look for the line of code that reads: /*That’s all, stop editing! Happy blogging.*/
  2. Add the following line of code directly above that line: /* Multisite */
  3. Hit enter and add the following line of code: define( ‘WP_ALLOW_MULTISITE’, true );
  4. Then, save your wp-config.php file and exit the control panel or FTP client.

Step Four: Setting up Your Network

  1. Log into your website and go to Plugins. Then, go to Installed Plugins and deactivate off of them. Although you can deactivate each plugin separately, it is easiest to select them all and deactivate them in bulk.
  2. Next, go to Tools and select Network Setup. You will be prompted to choose subdomains or subdirectories for your sites.
  3. Name your network and enter the email address you want to be associated with your network and click install.
  4. Once the installation completes, you will be taken to a screen titled “Enabling the Network.”
  5. Follow the directions on that screen to update your wp-config.php and your .htaccess files. If you don’t have a .htaccess file for some reason, create a new one and include the text listed in the Enabling the Network screen.
  6. Once you updated those two files, refresh your website. You will be prompted to log in. Once you are logged back into your site, you will be taken to the Multisite dashboard instead of the usual WordPress dashboard, and you have successfully set up your network of sub-sites.

Adding New Websites to Your Network

  1. Go to your dashboard and click on My Sites. Next, click on Network Admin. Then click on Add New.
  2. Next, enter the site address for the new site, name it, select a language for the site, and enter an email address for the admin.
  3. Click Add Site, and you are finished.

Method Two: Setting up Multiple WordPress Instances Using a Single Database

To set up multiple WordPress instances using a single database is as simple as updating one line of the wp-config.php file for each additional site you are adding to your server.

By default, WordPress assigns the prefix “wp_” to its SQL database. All you need to do is go into the wp-config.php file for each site and look for the line of code that reads “$table_prefix = ‘wp_’; //.”

Then, all you need to do is create a new prefix for each site. For example, you might want to set up a blog featuring articles to promote your WooCommerce site. In that instance you might use “$table_prefix = ‘blog_’; //” for the prefix. It doesn’t matter what you choose instead of wp_. It could be as simple as “mainsite_” and “site1_.”

Whatever method you choose, you will need to manually install your additional WordPress instances because most “one-click” installation programs do not allow you to select the prefix for your database tables.

You can click here for the official WordPress site for more information regarding setting up Multiple WordPress instances using one database. Additionally, you can click here to watch an instructional video on YouTube, showing you how to set up multiple WordPress instances using a single database.

Requirements for Setting up Multiple WordPress Instances Using a Single Database

Before setting up multiple WordPress instances, you will need to make sure that:

  1. You have an active WordPress installation.
  2. You have access to the site directory using a control panel like Plesk or cPanel or by using an FTP application like Filezilla.
  3. You have a full backup of your current WordPress site to include the installation files.

Pros and Cons of a Single WordPress Instance vs. Multiple Instances

There are a few pros and cons to consider when deciding whether to use the WordPress Multisite feature versus setting up multiple WordPress instances.

Pros

The pros of using the WordPress Multisite feature include:

  • Less work on the backend since all your sites will share the same theme, plugins, and design scheme;
  • Less of a load on your server;
  • As the network admin, you can easily update your themes, and manage multiple sites and users from one dashboard;
  • Each site can have an admin who will only have the ability to update their own assigned site(s);
  • Easy backup for multiple sites.

Cons

The cons of using the WordPress Multisite feature include:

  • Hackers can compromise your entire network by penetrating the defenses of only one site since they share system resources;
  • It is not possible to restrict plugins for one specific site;
  • Using shared resources can cause performance-related issues, particularly for sites with high traffic volumes;
  • Some widgets and plugins are not compatible with WordPress Multisite;
  • All sites are restricted to using the same theme, plugins, and design scheme.

Final Thoughts

Depending on your needs, you may want to install more than one WooCommerce site using one database. Fortunately, this is easily accomplished using the step-by-step instructions included in this article.

Which method you use depends on your individual needs and the capacity of your server. Be sure to review the section on the pros and cons of installing a single versus multiple instances of WordPress using a single MySQL database.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email
Share on pinterest

More To Explore

Do You Want To Boost Your Business?

An image of three people in a meeting looking at laptops