Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Multi site with one installation

Asked Modified Viewed 1,355 times
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Started this discussions
  • Answered 1 question
asked
Senior Member

I made a multi subdomain site with 1 PHPFusion installation, which uses a separate database for each site.

It is V7.03, but can also be V8.xx.

I have multi subdomains like:
www.sub1.mysite.com
www.sub2.mysite.com

On the webserver every subdomain is pointing to the same folder on the webserver.

each site has its own database e.g. databasenames are like mysite_sub1 and mysite_sub2
each site has its own config.php in the root of the site e.g. config_sub1.php and config_sub2.php

In each config.php the settings for the database access are specified for each subdomain.
So in config_sub1.php the name of the database is: mysite_sub1, together with database login credentials, and different cookie prefix to prevent messing up with different login sessions.

In maincore.php I added the following:

function StripSubdomain($Domain) {
 $domain_array = explode('.', $Domain);
 $domain_array = array_reverse($domain_array);
   return $domain_array[2];
}

$subdomain = StripSubdomain($_SERVER['HTTP_HOST']);
define("SUBDOMAIN", $subdomain);
define("CONFIGPHP", "config_".SUBDOMAIN.".php");



and I modified:

// Locate config.php and set the basedir path
$folder_level = "";
$i = 0;
while (!file_exists($folder_level."config.php")) {
   $folder_level .= "../";
   $i++;
   if ($i == 7) {
      die("config.php file not found");
   }
}


to

// Locate config.php and set the basedir path
$folder_level = "";
$i = 0;
while (!file_exists($folder_level.CONFIGPHP)) {
   $folder_level .= "../";
   $i++;
   if ($i == 7) {
      die("config.php file not found");
   }
}



and

require_once BASEDIR."config.php";
// If config.php is empty, activate setup.php script
if (!isset($db_name)) {
   redirect("setup.php");
}


to

require_once BASEDIR.CONFIGPHP;
// If config.php is empty, activate setup.php script
if (!isset($db_name)) {
   redirect("setup.php");
}


I Tested and this is working OK for me.
So now I can run two different sites from one installation, only different databases.

Question is:
Is this a good practice to do?
It probably need some code to prevent $_SERVER['HTTP_HOST'] containing wrong domain name data.

One thing more to do is: there are some cron-jobs executed also, this needs some modification too, to be sure the cron job is executed with the right database.
This can be done by adding a parameter to the cron-job command line, so the con-job php file 'knows' which database to open, or modify the cron-job php file to run through all the databases after each other.
Edited by douwe_yntema on 26-04-2019 19:44,
0 replies
There are no post found.

Statistics

  • Views 0 views
  • Posts 0 posts
  • Votes 0 votes
  • Topic users 1 member

1 participant

D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Started this discussions
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet