virtual hosts support [message #5238] |
Sat, 24 August 2002 12:10 |
venus
Messages: 30 Registered: August 2002 Location: Urals, Russia
Karma: 0
|
Member |
|
|
current version of FUDforum doesn't support virtual hosts, where absolute url can be either http://www.domain.com/forum/ or http://forum.domain.com/ or http://forum.intranet.domain/.
i think there are no important reasons for this limit and not to hard to add virtual domain support to FUDforum:
1. do not hardly configure cookie domain in GLOBALS.php but set it from HTTP_HOST environment variable.
right now i use hacked root_index.php.t, with $GLOBALS['COOKIE_DOMAIN'] = $_SERVER['HTTP_HOST'];
right after include_once "GLOBALS.php";
2. do not make all links absolute (http://domain/root/path/file) after theme rebuilding but use relative (path/file) instead. now i use msg file converted by this sed script:
s%{ROOT}%http://'.\$_SERVER['HTTP_HOST'].\$_SERVER['PHP_SELF'].'%g
s%{VAR: url}%http://'.\$_SERVER['HTTP_HOST'].'{VAR: url}%g
i know my hacks is not best solution but it works fo me.
correct me if too hard to add virtual domain support.
[Updated on: Sat, 24 August 2002 12:12] Report message to a moderator
|
|
|
Re: virtual hosts support [message #5240 is a reply to message #5238] |
Sat, 24 August 2002 16:07 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Well, what you are actually asking for is to have 1 forum work across many domains. That is problematic for numerous reasons and while various hacks may be a perfect solution as a whole I do not think they are a goo idea.
For example, since cookies can only be set for a domain you are currently on, if I am logged it at forum.domain1.com and I go to
http://domain2.com/forum/, which happens to be the very same forum I'd still need to login again.
This is just one problem, there are others.
FUDforum Core Developer
|
|
|
|
Re: virtual hosts support [message #5249 is a reply to message #5246] |
Sat, 24 August 2002 18:42 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
venus wrote on Sat, 24 August 2002 14:03 |
i think that logging to different domains is no problem, single user uses single domain usually.
|
That may be true in your situation, which is solved by the hack you've posted, but such an assumption cannot be made in a software that would be used by different people.
Quote: |
but why do you prefer to have absolute links including server name and full path for all forum pages? such links make forum less flexible and make pages bigger.
|
Page size difference is negible, and if you use compressions like mod_gzip the difference is virtually non existant.
FUDforum Core Developer
|
|
|
|
|
|
Re: virtual hosts support [message #26461 is a reply to message #26459] |
Thu, 21 July 2005 22:58 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
It seems to me that the simplest solution would be to modify the GLOBALS.php to retrieve the "core" settings like paths and database values from some data store based on the domain.
It seems like a trivial hack anyone interested could easily add.
FUDforum Core Developer
|
|
|
Re: virtual hosts support [message #26464 is a reply to message #26461] |
Fri, 22 July 2005 01:25 |
ruzam
Messages: 44 Registered: July 2005
Karma: 0
|
Member |
|
|
Ya, that sounds about like what I was thinking
I'm still a little confused about the differences between $WWW_ROOT_DISK and $DATA_DIR. $DATA_DIR appears to contain most of the dynamic data (errors, messages, tmp, files, cache), but there's also plenty of stuff in that directory that appear to be static (scripts, sql, etc). To tweak FUDforum down the lines of a multi-site configuration, there would have to be a clear seperation between what is owned by the individual site and what is owned by the host.
And sort of along those lines I'm curious, why does GLOBALS.php define the initial settings repetitiously?
for example:
$DATA_DIR = "/var/www/html/FUDforum/";
$ERROR_PATH = "/var/www/html/FUDforum/errors/";
$MSG_STORE_DIR = "/var/www/html/FUDforum/messages/";
$TMP = "/var/www/html/FUDforum/tmp/";
$FILE_STORE = "/var/www/html/FUDforum/files/";
$FORUM_SETTINGS_PATH = "/var/www/html/FUDforum/cache/";
Why not (sorry if my PHP is a little off):
$DATA_DIR = "/var/www/html/FUDforum/";
$ERROR_PATH = $DATA_DIR."/errors/";
$MSG_STORE_DIR = $DATA_DIR."/messages/";
$TMP = $DATA_DIR."/tmp/";
$FILE_STORE = $DATA_DIR."/files/";
$FORUM_SETTINGS_PATH = $DATA_DIR."/cache/";
This makes it a little clearer in the code as to the purpose of $DATA_DIR without limiting the operator's ability to customize it later.
|
|
|
Re: virtual hosts support [message #26466 is a reply to message #26464] |
Fri, 22 July 2005 02:00 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
DATA_DIR and WWW_ROOT_DISK will differ if during 1st stage of the install you specified different values for those two.
Other settings are listed in full to allow on advanced installs to have those directories be located elsewhere...
FUDforum Core Developer
|
|
|
|
Re: virtual hosts support [message #26541 is a reply to message #26540] |
Tue, 26 July 2005 20:16 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
The few values that are hard-coded by the template compiler are done for performance reasons. GLOBALS.php is the main configuration file allowing the admin panels to be used even if the URL had changed.
A simple theme rebuild would update the templates with the new value.
If you want GLOBALS.php to be always used, you need to do a simple modification to compiler.inc in the hadling of the FULL_ROOT template element.
FUDforum Core Developer
|
|
|
|
|
|
|
Re: virtual hosts support [message #26551 is a reply to message #26549] |
Tue, 26 July 2005 22:18 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Existing templates primarily use this value for redirect so grep for header() lines in the code and convert them to use single quotes as needed.
FUDforum Core Developer
|
|
|
|
Re: virtual hosts support [message #26583 is a reply to message #5238] |
Wed, 27 July 2005 21:45 |
Anonymous
|
|
|
|
OK, cool. Those are the same files I modified.
I added this to the beginning of core.inc:
/* virtual support */
if (isset($_SERVER['HTTP_HOST'])) {
....$domain = explode('.', $_SERVER['HTTP_HOST']);
....$count = count($domain) - 1;
# strip the dot name
....$GOBALS['FORUM_SITE'] = stripslashes($domain[$count-1] . '.' . $domain[$count]);
....require($DATA_DIR."sites/".$GOBALS['FORUM_SITE']);
}
Actually, I think it would be smarter to add a $GLOBALS['VIRTUAL_SITESDIR'] variable to $GLOBALS.php, then have this core.inc snippet check to see if the variable is set before deciding to do anything special. compiler.inc could check the same VIRTUAL_SITESDIR and decide whether to automatically build themes with FULL_ROOT static or dynamic.
In the sites directory, for each virtual site I created a $GLOBALS replacement file containing something like this:
<?php
$GLOBALS['WWW_ROOT'] = "http://forum.mysite.com/";
$GLOBALS['DATA_DIR'] = "/var/www/mysite.com/FUDforum/";
$GLOBALS['ERROR_PATH'] = $GLOBALS['DATA_DIR'] . "errors/";
$GLOBALS['MSG_STORE_DIR'] = $GLOBALS['DATA_DIR'] . "messages/";
$GLOBALS['TMP'] = $GLOBALS['DATA_DIR'] . "tmp/";
$GLOBALS['FILE_STORE'] = $GLOBALS['DATA_DIR'] . "files/";
$GLOBALS['FORUM_SETTINGS_PATH'] = $GLOBALS['DATA_DIR'] . "cache/";
$GLOBALS['COOKIE_DOMAIN'] = "forum.mysite.com";
$GLOBALS['DBHOST_USER'] = "xxxx";
$GLOBALS['DBHOST_PASSWORD'] = "xxxx";
$GLOBALS['DBHOST_DBNAME'] = "mysite.com";
etc...
?>
I can redirect the MYSQL to a different DB for each site. Including the compiler.inc tweak, this makes the forum work across virtual sites. With caveats. I still haven't crossed the avatar/smileys bridge yet. For now I'm happy to just leave these non-modify for the virtual forums.
I have to create the individual virtual site directories, and virtual site DBs. Is there an easy way to regenerate the default tables in a new database without writing new code?
The admin tool updates the main GLOBALS.php file directly. This would be far easier to deal with if some or all of this information were stored in a table as well, but for now I'll settle with some kind of control over what the admin tool can do. For instance I don't want virtual site admins to be messing with Database Settings. What's the easiest way to remove admin options? Are they dynamically included or is the admin page set in stone?
|
|
|
|
Re: virtual hosts support [message #26585 is a reply to message #26583] |
Wed, 27 July 2005 22:46 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
The SQL schema for the tables is found inside the sql/* directory of the forum. You simply need to replace the table prefix token with the desired value and pipe them to the database.
Easiest way to remove admin options is to modify usercp template to not show them and then in include/adm.inc always deny access.
FUDforum Core Developer
|
|
|
Re: virtual hosts support [message #28066 is a reply to message #26585] |
Mon, 10 October 2005 04:47 |
ruzam
Messages: 44 Registered: July 2005
Karma: 0
|
Member |
|
|
Yeh! Finally found more time to look at this.
Ok, so I have a modified GLOBALS.php that includes a new var $SITES_DIR. I have a modified core.inc that checks for the new global, and includes a GLOBALS over-ride file from the $SITES_DIR using some magic on the $_SERVER['HTTP_HOST'] to determine a domain name. This is good. I have one domain setup this way and FUD appears to be working OK.
So now I'm trying to re-create the FUD tables in a new database for a second domain. In sql/ I've created the 'create_virtual_site.php' script attached. Things are still a bit hard coded for the moment, but basically, given a site name (domain) and a password (SQL database password), it:
(a) sets DBHOST_USER, DBHOST_PASSWORD and DBHOST_DBNAME according to the site name and password (this DB, User and pass were previousely setup in MYSQL)
(b) Generates a new GLOBALS file in the $SITES_DIR for the domain using a reference template
(c) Finally, connects to the database and runs through every .tbl and .sql file in the sql/ directory to create and default the tables.
So far so good, with a few caveats:
- Running the .tbl and .sql files using PHP seems to get tripped up on the query end ';'. Is this a PHP thing or did I just code this wrong? I ended up coding it ot split the queries, strip the ending ';' and feed the queries on at a time.
- UNIX_TIMESTAMP (in def_forum.sql) needs to be specified as 'UNIX_TIMESTAMP()'. Again, is this a PHP thing or is this file incorrect?
So I've got all the tables created and defaulted. But when I attempt to run this forum it duffs with a 'Fatal error: SQL Error has occurred'. The same config file for the new domain can be made to work with an existing FUD database, so I'm pretty sure the initial config setup is correct. The new domain DB is setup exactly the same as the working DB setup, except that this DB was created and loaded from my script, and not from the standard FUD init script.
I don't know what the SQL error is. The sql_errors log file contains dated entries of the failure, but the error message is just garbage. In fact it's the exact same garbage for every line . Looking at my error file for the working forum domain, they are garbage as well. Very frustrating...
How do I find the real error messages?
Why are the error files reporting garbage?
Are the .tbl and .sql files in the sql directory correct or have they been lapsing in the development?
What must be done to correctly build the required tables from scratch for a working forum?
|
|
|
Re: virtual hosts support [message #28075 is a reply to message #28066] |
Mon, 10 October 2005 15:04 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
The "garbage" is actually the entire error with additional debug information that has been base64 encoded.
The *.sql files are always up to date.
You need to run the queries found inside *.tbl and *.sql files
FUDforum Core Developer
|
|
|
|
|
Re: virtual hosts support [message #28101 is a reply to message #28085] |
Tue, 11 October 2005 14:44 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
The errors are not obscured, base64 is a common way to make thing 7 bit safe. The reason forum encodes them is to ensure that 1 error message == 1 line to simplify parsing.
Decoding the file is trivial.
<?php foreach (file("error_log") as $e) {
echo base64_decode($e);
} ?>
FUDforum Core Developer
|
|
|
|
Re: virtual hosts support [message #28117 is a reply to message #28085] |
Tue, 11 October 2005 17:05 |
ruzam
Messages: 44 Registered: July 2005
Karma: 0
|
Member |
|
|
The init script proved to be useful. Turns out my initial table creation script did not create an entry in the themes table. Without this entry, the anonymous login (or any login for that matter) fails to find the session after it's created.
Suggestion: UNIX_TIMESTAMP in file def_forum.sql should be {UNIX_TIMESTAMP} to make it clear that this is going to be substituted. It's far to similar to the MYSQL UNIX_TIMESTAMP() function, which technically does the same job if the '()' are included.
Here's my latest crack at virtual support:
Patch core.inc - look for a $SITES_DIR global variable. Load an alternate site file to over-ride GLOBAL values. This is totally compatible with all past/existing/future FUDforum installations.
Patch compiler.inc - Again, looking for a $SITES_DIR global variable, use either the original 'FULL_ROOT' hard coded substitutions in pages, or substitute the $GLOBALS['WWW_ROOT'] string. This should be totally compatible with all past/existing/future FUDforum installations. I can't say if it's 100% virtual site compatible (I don't know if all the templates will properly include the format). Seems there are still some css file issues that need looking at.
create-virtual-site.php - This can be run from the command line, hopefully to be someday incorporated into an interactive the FUD admin page option. Creates the necessary files and tables for a virtual site forum.
It's still sketchy. There's no admin page support of any kind, and things will probably break if there's any attempt to update the $GLOBALS from the admin page. But at least it opens the option to hosting multiple domains off the same FUD code base.
Question: I know you've cited performance reasons for hard coding the FULL_ROOT in theme pages. But the way I see it, you're already committed on every page that includes at least one PHP script on it. Does hard coding the FULL_ROOT by default really buy you that much more performance?
Question: I still have trouble seeing the distinction between the various directories declared in GLOBALS. In a multi-site environment, there are really only two distinctions: Dirs/Files which will be updated by the forum and Dirs/Files that will be shared by all but not updated. I'm using $DATA_DIR for the updatable forum stuff. Any paths which are also modifyable by the forum are based off this, errors/, messages/, tmp/, files/, cache/. $DATA_DIR can be easily switched for each site. I'm using $WWW_ROOT_DISK for all the common forum stuff (include/). Everything under $WWW_ROOT_DISK can be made world readable and only root writable. This totally protects the code base from any kind of external influence. Everything under $DATA_DIR can be made apache read/write. I have loose ends to look into regarding avatars and what not, but themes are looking to be a problem. Why are themes organised under $DATA_DIR and not $WWW_ROOT_DISK?
|
|
|
|
Re: virtual hosts support [message #28124 is a reply to message #28121] |
Tue, 11 October 2005 23:09 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
As far as CSS goes the reason it does not work is because a css file is a static file, so putting PHP vars into it will not work. You will need to patch forum.css.tmpl so that the image paths in there do not use the full path. It should be as simple as removing {FULL_ROOT} from the template.
Re: FULL_ROOT
The hardcoding probably does not buy a whole lot of performance, but every little bit counts... Plus as you've found out it is not that difficult to make it not hardcode the data, by tweaking compiler.inc.
Re: Directories
The compiled theme templates are placed in WWW_ROOT_DISK/theme directory so this needs to remain web server writable. The reason there many vars is to allow high traffic installs to split data storage across many locations. For most installs, they are just short-cuts to particular dirs. Things like uploaded avatars also go into WWW_ROOT_DISK.
FUDforum Core Developer
[Updated on: Tue, 11 October 2005 23:12] Report message to a moderator
|
|
|
|
Re: virtual hosts support [message #28127 is a reply to message #28126] |
Wed, 12 October 2005 00:34 |
ruzam
Messages: 44 Registered: July 2005
Karma: 0
|
Member |
|
|
The css could be incorporated into the pages themselves. I mean, it only really makes sense to include it as a separate file if you're hand coding the web pages. As long as everything is generated from templates, does it make any difference? You'd probably gain some speed increase by having it compressed with the original page instead of fetched separately.
Or alternately, the CSS could be located in the FULL_ROOT and created uniquely for each site?
Sure, it's easy enough to tweak compiler.inc, but not being part of the official code, it's an upgrade risk. Besides, the compiler.inc tweak is always going to be land mine for future breakage. I hope you'll consider including a virtual site enhancement some day.
Theme templates in WWW_ROOT_DISK is cool, updated avatars in WWW_ROOT_DISK is not. In a multi-site environment what there really needs to be is gobal default dir, extended with the site personal additions. So say pre-installed avatars come from WWW_ROOT_DISK and 'extra' site installed avatars come from {FULL_ROOT} with the two directories seemlessly blended together. Something I'm sure FUD was never designed for, so it's probably going to be a bear.
Silly question #1:
What's the point of having the 'Database Settings' section (DBHOST values) on the admin page? If these values aren't correct you can't get to the admin page. If you change them on the admin page, you'll never be able to go back and fix them if they're entered wrong. Just seems kind of odd to set them up on the admin page when really, your only option to change them is to edit the GLOBALS.php.
Silly question #2:
Perhaps this relates to your comment about splitting storage, but why link GOBALS.php in many places? Would it not be just as easy to leave it in one place and adjust references accordingly?
Thank you
Thank you or the error log patch. I like mine better but hey, as long as it gets the job done. You don't know how many times I've had to look at the sql_errors while debugging my mods.
|
|
|
Re: virtual hosts support [message #28128 is a reply to message #28127] |
Wed, 12 October 2005 00:46 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Keeping CSS in a separate file makes a LOT of sense, since the browser is then able to cache this information once and not fetch it again. By embeding into pages you make each page larger for no reason.
CSS cannot be inside the FULL_ROOT, since each theme can have its own stylesheet file, therefor they need to be in separate directories.
For avatars I'd wager you best bet would be intoroduce AVATAR_DISK_DIR and AVATAR_WWW_DIR variables into GLOBAS.php and use the to allow each site to specify their own avatar storage placeholder.
Re: Question #1
Several reasons, #1 to see what those settings are. Suppose you need to do some manual SQL work and forgot the forum's settings and what not. As far as adjusting the settings you can do that prior to manual data dump to another server so that the forum can start working in the new location instantly.
Re: Question #2
The file is linked in just 2 places, WWW_ROOT_DISK and adm/, which allows the forum to know precisely where it is without hardcoding its path with a full path.
FUDforum Core Developer
|
|
|
|
|
Re: virtual hosts support [message #28131 is a reply to message #28130] |
Wed, 12 October 2005 03:38 |
ruzam
Messages: 44 Registered: July 2005
Karma: 0
|
Member |
|
|
Ok, still very confused about directories (sorry).
But first, compiler.inc there are a couple of instances of:
$GLOBALS['DATA_DIR'] . 'include/theme
These should be:
$GLOBALS['INCLUDE'] . 'theme
And second, I included three patches admforumicons.php, admsmiley.php and forum.css.tmpl. All to make image URLs relative (and remove any problems with CSS and FULL_ROOT).
Now I'm forever running into problems with the $GLOBALS['DATA_DIR'] '/sql /src /thm' trio. Compiling a theme as no site is fine (DATA_DIR is default), but compiling a theme online (not that a virtual site should) is a mess because DATA_DIR has been changed to the site data directory. As I'm using DATA_DIR for the virtual site directory, the trio doesn't fit. All three are static and should not be under the control of the virtual site (ie apache write). Yet at the same time they also don't fit the description of WWW_ROOT_DISK either. Looks to me there needs to be three main directories:
1) web viewable sources - adm,images,theme,main (WWW_ROOT_DISK)
2) user data - errors, messages,files,cache,etc (DATA_DIR)
3) non-web sources - include,scripts,sql,src,thm (SOURCES_DIR?)
OR user data goes to a new definition (FORUM_DIR?) and #3 above remaind the existing DATA_DIR.
Either that or don't stop with $INCLUDE in GLOBALS.php. Maybe add $SQL, $SRC and $THM as configurable directories as well?
On the one hand I realize that I'm asking these questions out of my drive to use virtual sites and they in no way impact a single site install. On the other hand I think asking these questions will help FUD become more future proof and easier to maintain.
Maybe I'll just sleep on it for a day or two
|
|
|
Re: virtual hosts support [message #28136 is a reply to message #28131] |
Wed, 12 October 2005 13:25 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
No, it should be $GLOBALS['DATA_DIR'] . 'include/theme reason being that inside include/ we have non-theme specific includes like core.inc and inside theme/[theme name]/ includes that are theme specific.
User data and sources are both in DATA_DIR you want some sources to be accessible so that people can create their own themes and customize existing ones. Otherwise you prevent all means of adjusting the forum's layout for the users.
FUDforum Core Developer
|
|
|
|
Re: virtual hosts support [message #28167 is a reply to message #28161] |
Wed, 12 October 2005 20:26 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Because in theme/ we have compiled *.php files in include we have function/class defenitions. Hence the breakdown.
FUDforum Core Developer
|
|
|
|