Multiple websites running on same codebase?
Asked Answered
C

5

5

We are developing an application that would be offered as a hosted solution. I am struck with understanding how can i use multiple sites with same code without duplicating base code.

eg: website 1: www.example.com and website 2: www.sample.com will run on same code, but would have different configuration settings, and different theme... like we run our own domain names in wordpress.

i wish to know how can i do this.

also in case of database.. would it be better i create individual databases for each website or use the same database with website ID as a column in each table.

pls help me.

[clarification] its not domain alias. like... it would be a service. where different clients will be offered the same application on their own domain name with different theme. something like what blogger does.. with own domain names but same blog application

[technology] specifically am looking at how to use the host name to determine which configuration to use we are using PHP and MySQL

Convertiplane answered 15/11, 2009 at 8:48 Comment(2)
Not a bad question, but it would have been nice if you took the time to proofread it before posting.Pasteur
i did check the previous questions and found this. #1530786 but not able to understand.Convertiplane
I
3

Reusing code is definitely desirable. It is hard to imagine from your posts how different the sites will be from each other. Are we talking about logos, and color schemes or different functionality?

I'll start with the different look & feel. I'll also assume that this is the only application on the server.

I recommend planning your directory structure carefully. Something like:

www-root/  
   / lib  
   / themes
        / domain1  
        / domain2  


index.php:

<?php
$host = $_SERVER['HTTP_HOST'];
$include_theme = "themes/" . $host . "/configuration.php";
//make sure the file exists
require_once($include_theme);

This is a simplistic approach but something to thing about.

Isomorphism answered 21/11, 2009 at 17:49 Comment(2)
this was exactly what i was looking for. only theme and config will change. i ll be using the config data from database.Convertiplane
Thanks. Glad it helped. Post another comment here if you have a further question.Isomorphism
S
1

It's very simple actually.

Your code base can and should be single. You upload it to hosting1 and hosting2. When maintaining, as soon as you updated the code, upload it to both hosting spaces.

I suppose it's how this site works as well. Look at the footer of the page. You have there stackoverflow, meta, superuser and serverfault. If you look what the comment on bottom-right says right now, it would be "svn revision: 5404". The same thing. One code base published to four sites. The databases of course are different and contain completely different content.

So the variable parts are:

  1. Configuration

  2. Settings

  3. Data

Those ones you need to copy.

You need to code it this way that configuration and settings are not hardcoded but either stores in some database table or at least in some external configuration files. These do not make part of code (or implementation if you wish) so they do not need to be in code. If you have them in, take them out.

Sneer answered 15/11, 2009 at 8:51 Comment(5)
i need to do it with single hosting. I will be hosting around 1000 websites. so its impractical for me to update all the hosting accountsConvertiplane
Explain please what is the idea behind having multiple sites? Is it just domain alias or several sites of a family?Sneer
its not domain alias. like... it would be a service. where different clients will be offered the same application on their own domain name with different theme. something like what blogger does.. with own domain names but same blog application.Convertiplane
I have sort of been wondering the same thing. I suppose it would have to employ $_SERVER['HTTP_HOST']Consult
can you help me understanding what it stands for and how to use it?Convertiplane
W
1

I suppose you could have two different domains pointing at the same server, and set different configurations based on the host name. I wouldn't recommend this though. You may encounter issues with stability and performance, especially if you have a large user base or a large number of domains pointing to the code base.

Generally, if you are running multiple sites, you should have a different server for each.

Edit:

After reading comments on the other answer, I understand your use-case a little better.

If you have a large number of sites that you want to use this set up for, if you design the architecture correctly, and implement a load-balancing scheme of some sort to handle large user loads, you could make this work.

To recap:

  • get multiple servers, and balance the load across them.
  • design the application to handle a large user load.
  • use the host name to determine which configuration to use.
Wolframite answered 15/11, 2009 at 9:8 Comment(5)
that would increase my server costs.. how do they usualy do it? blogger is an example that comes to my mind? how do they usually do it?Convertiplane
see my edit. What language are you using to develop this application? We might be able to help you out with implementation if we know what you are using to develop the application.Wolframite
yes we are in plan to do that.. load balancing etc... am unable to get the code on how to do the third part "use the host name to determine which configuration to use"Convertiplane
What language are you using to write your application?Wolframite
we are using PHP and MySQL. I am basically not an expert at PHP and just started learning itConvertiplane
O
0

We do this with about 15,000 unique domains right now. It's not difficult, but it does take some design considerations to implement properly.

You can do it off a single codebase & server, and essentially just build your code to depend entirely upon the incoming request's HTTP_HOST value. Then everything in your DB keys off of that value as a means of segregating data properly and answering the request with the appropriate data/html.

Opisthognathous answered 21/11, 2009 at 18:5 Comment(0)
K
0

For security reasons, you might consider:

A) set a separate open_basedir restriction for each host so that user uploaded files cannot be accessed by other websites, for example: /shared_library /host1/user_images /host2/user_images

You can include shared and domain specific directories in the allowed paths.

B) connect to a different database for each host, to prevent any errors in your database queries from accidentally grabbing another website's data, and to allow easier scaling of database servers (e.g. Move busy domains onto a different database server)

If you have an extremely simple application, You might get away with one database.

In any case, you should have a roll out strategy so that none of the sites break when you make changes.

Kolodgie answered 18/4, 2015 at 3:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.