Page 1 of 1
multiple sites on same server
Posted: Mon Feb 28, 2005 1:26 pm
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.
Posted: Mon Feb 28, 2005 1:30 pm
by feyd
why not use virtual hosts and directory aliasing to this "central" folder?
Posted: Mon Feb 28, 2005 8:33 pm
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.
Posted: Tue Mar 01, 2005 6:18 am
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.
Posted: Tue Mar 01, 2005 1:03 pm
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?
Posted: Tue Mar 01, 2005 1:06 pm
by smpdawg
Is the second link supposed to be
http://www.domain-two.com?
Posted: Wed Mar 02, 2005 2:12 am
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
Posted: Wed Mar 02, 2005 9:30 am
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
Posted: Sat Mar 05, 2005 11:40 am
by Yota
Thank you all for your comments.
I will go and have a play now..
rgds