Forum

Thread tagged as: Installation, Configuration, Hosting

How to install multipe sites on your hosted server?

Situation

I want to have two sites on my 1 external hosted server. It's for two sites from the same customer. I already have 1 site with a database and tables with content. (So I will have the same server space, with two url's pointing at it.)

a. I want to use the same perch core files
b. I have different pages, different content for my extra site
c. I have one database at my disposal, so I have to use 'PERCH_DB_PREFIX'

I came across the explanation for a switch in the config.php file:
https://solutions.grabaperch.com/development/multiple-server-config

My plan was to use htaccess for the pages (b.) and a switch in config.php for using two databases (c.)

Step 1.

Change config.php, so the extra site will go to the same database (i can only use 1) but different tables in this database.

//Switch Site 
$http_host = getenv('HTTP_HOST');  
switch($http_host)
{
    case('sitebyrene.com') :
        define('PERCH_LICENSE_KEY', 'PXXX-QXXX- etc');
        define("PERCH_DB_USERNAME", 'myusername');
        define("PERCH_DB_PASSWORD", 'mypassword');
        define("PERCH_DB_SERVER",   "mydbserver");
        define("PERCH_DB_DATABASE", "mydatabase");
        define("PERCH_DB_PREFIX",   "perch2_");
        break;

    case('thephrase.org') :
        define('PERCH_LICENSE_KEY', 'QXXX-RXXX- etc');  // different from 1st site
        define("PERCH_DB_USERNAME", 'myusername');
        define("PERCH_DB_PASSWORD", 'mypassword');
        define("PERCH_DB_SERVER",   "mydbserver");
        define("PERCH_DB_DATABASE", "mydatabase");
        define("PERCH_DB_PREFIX",   "perch2b_");  // different from 1st site
        break;
}

Step 2.

Install the database for the new site. New tables have to be created in the same database, but with a different prefix from the default 'perch2_' prefix.

Add the deleted folder 'setup' from the installation files. (One of the installation steps is to -delete the setup folder- after installing. So it has to be reinstalled for this extra site.)

Step 3.

Start the setup for the new site 'mynewsite.org/perch/setup

Problems

1. In the setup there is nowhere to add the database prefix. So the default of 'Perch2_' is used. Which will not overwrite the current tables, so nothing is done.

2. Your (newly changed) config.php is overwritten with a default. EVEN if you set a different '/perch' folder to fool the setup.

Solution

I have found a solution, although I'm not sure it's the best way to go about this:

1. Change the table prefix at installation
To make sure that the tables in the database are created using a new prefix, to have to change

/perch/setup/config_sample.php

change the PERCH_DB_PREFIX value into a preferred prefix name for the tables.

define("PERCH_DB_PREFIX", "perch2b_");

2. Make copy of config.php
Before installing make a copy of your altered config.php. Let the installation overwrite yours, and replace it after installation.

Question

This solution worked for me, is this the right way to go about adding a new site to an existing installation? (giving the fact that I want to use the same server space for two url's)

For the actual frontend pages (b. I have different pages, different content for my extra site) I will have to change the .htaccess file.

René Banus

René Banus 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's far simpler to create the config.php file yourself first. Setup will then use the values in it, including the prefix.

Off course I tried changing the config.php first.
But it got overwritten. Two times I tried this. The prefix in it wasn't used.
No database tables where created.

Newest release (core and setup folders) from today. Then I turned to the solution I have written down.

Strange this.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It will get overwritten, yes.

It looks like you only have once license configured for these two sites. That's not permitted.

Thanks for reminding me. I have now tried with the (other) license that was intended to be used here. But no difference.

The config.php gets overwritten, yes. But not including the PERCH_DB_PREFIX.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I'll see if we can get the option ported over from the Runway installer.