Forum

Thread tagged as: Question, Configuration, Hosting

Sharing A Database

I have a client that has a Perch created site I did. They have acquired another business and wish to reuse the content but with the new branding and a few tweaks to the styling.

Is there a way to share the existing site's database between these two sites?

  1. Currently the new site is with a different host, so I assume this is not doable?

  2. If not is there a way to achieve this if both sites are hosted on the same ISP/Server?

Nigel Coath

Nigel Coath 1 points

  • 3 months ago
Drew McLellan

Drew McLellan 2564 points
Perch Support

If multiple sites have access to the same database, you can configure them to use the same database. Realistically that's not going to work well if the sites aren't with the same host.

Okay so assuming I do have them with the same host, can you explain what I need to do? I found this doc: https://docs.grabaperch.com/perch/building/servers/multiple-server-config/

What I don't get is the path that would need to be set to point both urls to the same db? I am sure I can get my ISP to make sure they are on the same server, but what would the path need to be?

I assume it would need to be more than just "define("PERCH_DB_DATABASE", "my-database-name");"

And before you say it, yes I have two licenses!

Drew McLellan

Drew McLellan 2564 points
Perch Support

I assume it would need to be more than just "define("PERCH_DB_DATABASE", "my-database-name");"

No, that's all you need to do.

Sorry to be dense, if I have two urls www.spam.com and www.morespam.com and both reside on the same server space but not in the same virtual server eg they are sharing hardware but probably on separate virtual server spaces, how can I share a database?

This is a typical ISP scenario where although they are on the same server, they are sold as separate domains/virtual servers.

Or is it that this database resides at the root of the server after all?

Its just I would have thought this database would need to be referenced more specifically than just by its name?

Drew McLellan

Drew McLellan 2564 points
Perch Support

I can't really comment as to your hosting setup, but obviously both sites need to have permission to connect to the database.

Jonathan Elliman

Jonathan Elliman 22 points
Registered Developer

Hi Nigel

You'd just need to use the DB server's IP address (rather than localhost) when you use define("PERCH_DB_SERVER", 'IP_ADDRESS_HERE'); and/or then switch case in the config file, depending upon the domain that's being used. It depends on whether the host allows DB sharing across IPs for this to work.

Thank you both, will check with ISP.