views:

81

answers:

3

Hi,

I am going to be making a series of about 5 sites. They need to all run on the same system. I am planning on making them all point to the same server, then depending on which domain is used to access it, different content/styles will be served. So its essentially going to be 5 or so different retail sites specializing in a particular product type.

But all using the same back-end code so that it is much easier to maintain. I have never set anything like this up before and want to know if there is any information I should consider or if anyone knows of a good place that explains how to do this well?

Also we are not hosting ourselves but going through a hosting company (if that matters).

Thanks!

+2  A: 

Sounds pretty straight forward to me:

Just have a directory:

/var/www/siteLibraries/foo.php

Or other suitable directory. Then have

/var/www/site1/foo.php
/var/www/site2/foo.php

and setup the default class loading in PHP (http://uk.php.net/manual/en/language.oop5.autoload.php) so that when the specialist site instantiates a class ... it will search the site's local libraries (for specialist overrides) and then default to the shared libraries. You can also arrange content this way.

A brief explanation, but a rough overview of how I would tackle it if you don't need to worry about both sites sharing permissions (I assume clients wont edit code).

Remember: your per-site code should specialize from the default code base (OOP is great for this). What is not specific, is shared. Of course, the shared code-base should be aware it is shared, so things like logs should specify which specific site was utilizing the library when an error occurs and all that.

Good Luck

Aiden Bell
A: 

I'm currently in the process of writing a content management system that addresses this exact issue. A few things that I found helpful to think of.

When developing your sites, reduce them each to the lowest common denominator. That is, what elements are common to all of your websites? For example, each website will have a series of pages, and probably some form of shopping cart system.

For my system, I have a separate template file for each site. This way, I keep my PHP and HTML apart, which makes things a lot easier. Once I had the lowest common denominator, the hardest challenge for me was telling sites apart.

I used my htaccess file to redirect example.com to www.example.com - this way, I can then reliably pick up www.example.com from the header, and use that to select the information for a given site from the database.

Aiden also has some good points on code specific. For me, I found that code wasn't particularly the issue, but rather how I implemented that code for a multi site environment.

Hope this helps.

EvilChookie
A: 

If you want your sites to have different code bases, Aiden's approach looks pretty good.

If your needs are simpler, i.e. all sites run the same code, but display different content based on the domain name, then you can also get away with a simpler solution.

Point all domains to the same directory where your scripts live, and differentiate what kind of content to send based on the HTTP "Host" value.

I.e.:

$host = $_SERVER["HTTP_HOST"];

$rs = mysql_query("SELECT * FROM products WHERE website = '$host'");

// ...etc

N.B: This code is for illustrative purposes. As written it is vulnerable to SQL injection, you should protect it appropriately.

rix0rrr