I have a site www.domain.com with Wordpress installed. I need to create a subdomain for testing a new theme and have it linked to the main site's database. I have manually added the Wordpress files into the subdomain and during the install in the browser I added the database info of the main site. However when I then try to complete the installation it tells me that I already have Wordpress installed and directs me to log into the main site. When I do so there is no option to view the subdomain.

How do I link the subdomain to the main site's database and have them work independently?


Change the $table_prefix in the wp-config.php file.

  • But that wouldn't populate the subdomain website with the primary domain content would it? Or to do that do I need to export all the database info from the primary domain and then import it to the subdomain, basically a site migration? – Niall Mar 30 '19 at 2:19
  • Got it to work, thanks! – Niall Mar 30 '19 at 2:43
  • As far as WordPress is concerned it's two separate sites, that just happen to use different tables in the same database. As you say, having them mirror each other is a different matter, as is having one start off as a copy of the other. And (as it sounds like you're aware) to migrate things some changes need to be made -- you can't just blindly export and import. The main issue is that, in many places, WordPress stores links as full URLs that include the domain. Also, by changing the config file you can use a different database on the same mysql server. – Loren Rosen Mar 30 '19 at 2:59

But if you use the same database prefix on both sites, won't theme/plugin changes on the 2nd domain affect the first domain, since both are using the same database? (Theme and plugin settings are usually stored in the wp-options table of the database.)

I would set up a separate install of WP, then export from the 1st site to the 2nd site. That will give you content you can use as you play with themes and plugins. Once you get the themes and plugins working, you can export those (via an export/import plugin) from the 2nd site to the 1st site to get the theme/plugin settings into the 1st site.

If you just need to play with theme settings on the 2nd site, then there are some theme export/import plugins that work well to move the theme settings.


Don't do that. Let your testing site have its own database where you import a dump of your live site's database. Every environment is always supposed to have their own databases. If not, changes on the testing site would either affect the live site and/or raise the risk of FUBAR'ing your live site.

Consider Installing WordPress on your own Computer for that. Then download your live site's upload folder, plugins, themes and your lives site's database, and import your live site's database into the database on your own computer.

Then you can gamble around whatever you want. And if something's wrong, you can simply drop the database and import the live dump again.

Note that when importing your live database locally, you need to tell WordPress it got moved to another URL. So you simply could place the following three lines in your local wp-config.php. Where you replace http://mylocalurl.tld with the actual URL you access the local site on your computer.

define('RELOCATE', TRUE);
define('WP_HOME', 'http://mylocalurl.tld');
define('WP_SITEURL', 'http://mylocalurl.tld');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.