multiple sites on same server

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Yota
Forum Newbie
Posts: 5
Joined: Mon Feb 28, 2005 12:39 pm
Location: Europe : Uk and France

multiple sites on same server

Post by Yota »

Hi all,
Any pointers gratefully followed.. had a really good look around the forum.

I am re-writing my CMS, up to now only 3 domains are using it. I hope it will be dozens in the future.

I have been taking big steps now with oop, really got to grips with php5 and even start to understand how MVCs work.

This is all great - but for the life of me I cant work out how I can centralise all my php code to the degree I want - so that a future upgrade does not end up with me opening and ftping the same file on dozens of domains.

Imagine something like this on 24 domains:

Code: Select all

// this would be news.php
// heres an example news page, styles, headers, script and content all generated on the fly 
<? 
page_ID=24;//cause this is in domain #24, so gets their css, their login, their content etc
include('head.php');
do_news(24);    
include('foot.php');
?>
How can I make a page WITHOUT there actually being a page? I have gone to modrewrite.com and hunted around there so I know how to redirect things around at the Apache level, but before I start learning something else is mod_rewrite really the answer?

What if a link in this news page links from news.php to events.php in the same domain?

I still want real urls to give out to the public.

Has anyone else come across this and if so what is your strategy?

Will be using LAMP (MySql) and all domains will be on the same server.

Yota.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use virtual hosts and directory aliasing to this "central" folder?
firepages
Forum Newbie
Posts: 5
Joined: Sun Jul 28, 2002 4:22 am
Location: Perth::Australia

Post by firepages »

Hi I had similar issues , my own CMS runs several sites off the same core classes and modules.

After lots of FTP'ing and playing with rsync etc I bit the bullet and rewrote the main code so now my main config/db/session file also defines a path to my libraries..

DEFINE('FPA_LIB','/home/httpd/fpa_lib');

any generic logic is contained in fpa_lib , so anytime I update a major component all sites are updated at the same time. (this has its own issues if you are not into unit testing etc)

However any site-specific stuff still lives in the root of the individual site so even though (e.g) my news module classes live in FPA_LIB/modules/news , the templates for display will be held relative to the site in question /www/tpl/news etc.

As feyd mentions you can also simply alias this directory via apache or add it to your php-ini include path , I define it in each site for reasons that I forget ;) though possibly because I like using absolute paths ~ .

On that note , if any content in the shared directory has to be called via http://etc (e.g. admin javascript etc) I also alias the directory via apache.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

I did the same thing with a CMS several years ago. I had all the domains pointed at one set of scripts and database and used sessions to set which site the user was surfing. Besides allowing different domains, I also allowed subdirectories to set the "domain" and then did a redirect to the main page. Besides the normal DB changes I also put keywords into the CSS which in then parsed and replaced with that domains color scheme and logo. The end result was pretty good since it looked like different sites even though it was really the same.
Yota
Forum Newbie
Posts: 5
Joined: Mon Feb 28, 2005 12:39 pm
Location: Europe : Uk and France

Post by Yota »

Thanks for the replies. Its reasuring to know I'm not alone - and that seemingly this could be the right place to ask this question.

One thing I can't figure out though is - how can I allow users, in say http://www.domain-one.com/news.php to link to http://www.domain-one/events.php?e=1234

Can the GET querystring be shovelled around by Apache too?

How would a POST request work then?

All of the sites would look and behave quite differenly using differnet <div> sidebars, headers, css etc. Core pages would contain the same logic and would extract from different databases.

I have worked on the same thing on/off for 4 years so have made just about every error in terms in code maintenance nighmares.

Does anyone see anything in php5 that changes the way they look at their solution? OR should I just be reading up on Apache mod_rewrite?
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Yota wrote: One thing I can't figure out though is - how can I allow users, in say http://www.domain-one.com/news.php to link to http://www.domain-one/events.php?e=1234
Is the second link supposed to be http://www.domain-two.com?
Yota
Forum Newbie
Posts: 5
Joined: Mon Feb 28, 2005 12:39 pm
Location: Europe : Uk and France

Post by Yota »

No, I can see your point but I really did mean 'would this allow me to link to other pages in the same domain passing an arg in the query string'.

Could I link from news to a single event.. This is typically what I am linking to/from.

For clarity, I am only concerned now with how public pages appear. Single login for CMS management should be pretty easy if each domain had a different database. When I discovered how simple that would make my life I sought a similar solution for public pages.

Each public site will have up to around 20 pages, extracting from their own dbase.

Does your solution allow for this kind of linking? Passing vars in via the get method?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in-domain linking is quite simple and rarely has much to do with the host it's run on unless you always output full url's
Yota
Forum Newbie
Posts: 5
Joined: Mon Feb 28, 2005 12:39 pm
Location: Europe : Uk and France

Post by Yota »

Thank you all for your comments.

I will go and have a play now..

rgds
Post Reply