User Login    
 + Register
  • Main navigation
Login
Username:

Password:


Lost Password?

Register now!
Who's Online
80 user(s) are online (5 user(s) are browsing XoopsWiki)

Members: 6
Guests: 74

summary, andrax, ofvirkur, oklaslim, mythmanq, sakyant, more...
Documentation
Nominate XOOPS!!!!
[Main Page]

Dev:Xoops and Virtual Host

From XOOPS Project

Main Page | Recent changes | Edit this page | Page history | Switch to MediaWiki mode

Printable version | Disclaimers | Privacy policy
Category: Development

There are many ways to make Xoops "vhost aware", the one to choose depends on what you want to achieve. I have two solutions up and running in productive context, that I am going to describe now. You should be able to draw your own conclusions how to solve your specific problem after having seen how it can be done.

Way one is the difficult way, offering more flexibility at the cost of more detailed understanding the code and DOING more for each vhost. I use this way to handle a set of domains that each has its "own Xoops" (sharing the global installation, though) and is completely seperated in DB and DOCUMENTROOT otherwise. Each vhost domain simply does an "include /xoopsroot/mainfile.php" in index.php Way two is the easy way that uses ONE DB for all vhosts (sharing user etc), which eventually requires patching modules to allow "local statements".

WAY ONE (not a ONE WAY, though) allows Xoops to "sit" anywhere, being INCLUDED from any directory or vhost. The advantage of this method is that you keep your full local directories for additional code. It requires databases to be set up for every vhost following the simple algorithm: the sld/tld is the DB name, with "-" or "." replaced by "". Each vhost has its own DB here AND its own "DOCUMENTROOT". Example: foobar.com needs a DB named "foobar_com", "one-two-three.org" needs a DB named "one_two_three_org". The content of this DB is just a NORMAL Xoops DB. My code currently HARDCODES the Xoops prefix for the tables to be "local", the reason for this is some global/local data sharing code I did somewhere else. You could easily adopt this to a configurable prefix, naturally. Also WAY ONE requires config.php to reside in the xoops root directory at /config/domainname.php. Example: foobar.com needs its config at /config/foobar.com.php Also WAY ONE requires the system cache files to be at /modules/system/cache/domainname.mainmenu.php (and ...adminmenu.php). Example: foobar.com needs its mainmenu cache file at /modules/system/cache/foobar.com.mainmenu.php

In general the cached menu files are not written properly in Xoops. They include HARDCODED domain names, where they should use "XOOPS_URL" instead. This is a long time know "bug" in Xoops that I always correct, as using defined parameters makes the code flexible and usable... You should correct the writing mechanism of these caches files yourself, making it write "XOOPS_URL" instead of XOOPS_URL's content!

In order to RESPECT the http_host variable for vhosting in WAY ONE mainfile.php has to be adopted:

mainfile.php


   if ( !defined("XOOPS_MAINFILE_INCLUDED") ) {
   define("XOOPS_MAINFILE_INCLUDED",1);

// XOOPS Physical Path // Physical path to your main XOOPS directory WITHOUT trailing slash // ROOT PATH is set to where THIS file actually resides. This is some kind of // automatic configuration

   define("XOOPS_ROOT_PATH",dirname(realpath(FILE)));
   if(!file_exists(XOOPS_ROOT_PATH."/mainfile.php")) die("Please correct the main installation path in mainfile.php, which currently points to ".XOOPS_ROOT_PATH);

// XOOPS Virtual Path (URL) // Virtual path to your main XOOPS directory WITHOUT trailing slash // This is now created from the HOST NAME the user (visitor) whishes to see

   define("XOOPS_URL", "http://".$_SERVER['HTTP_HOST']);

// Database // Choose the database to be used

   $xoopsConfig['database'] = "mysql"; // whatever!

// Table Prefix // This prefix will be added to all new tables created to avoid name conflict in the database. If you are unsure, just use the default 'xoops'. // As this is the prefix for the "local" vhost, prefix is "local", no need to change as // every vhost will have its own DB, which is clearly defined by his HTTP_HOST

   $xoopsConfig['prefix'] = "local"; // whatever!

// Database Hostname // Hostname of the database server. If you are unsure, 'localhost' works in most cases.

   $xoopsConfig['dbhost'] = "localhost"; // whatever!

// Database Username // Your database user account on the host // THIS IS TO CHANGE // This value should be looked up in some global setup system, not fixed, as every DB will // most likely have its own access rights

   $xoopsConfig['dbuname'] = "username"; // whatever!

// Database Password // Password for your database user account // THIS IS TO CHANGE // This value should be looked up in some global setup system, not fixed, as every DB will // most likely have its own access rights

   $xoopsConfig['dbpass'] = "password"; // whatever!

// Database Name // The name of database on the host. // Created from HTTP_HOST, where all "." and "-" are replaced by "_"

   $xoopsConfig['dbname'] = str_replace(".","",str_replace("-","",$_SERVER['HTTP_HOST']));

// Use persistent connection? (Yes=1 No=0) // Default is 'Yes'. Choose 'Yes' if you are unsure

   $xoopsConfig['db_pconnect'] = 0;

// Config file is now named based on the requested host name

   define("UCMS_CONFIG",XOOPS_ROOT_PATH."/config/".str_replace("/","_",
   str_replace("http://","",XOOPS_URL)).".php");
   define("UCMS_MAINMENU",XOOPS_ROOT_PATH."/modules/system/cache/
   ".str_replace("/","_",str_replace("http://","",XOOPS_URL)).".mainmenu.php");
   define("UCMS_ADMINMENU",XOOPS_ROOT_PATH."/modules/system/cache/
   ".str_replace("/","_",str_replace("http://","",XOOPS_URL)).".adminmenu.php");

// ################################################################################# // ATTENTION: we check whether we can connect to the DB at all, if not, die with a message

   if(! $d=mysql_connect($xoopsConfig['dbhost'],$xoopsConfig['dbuname'],$xoopsConfig['dbpass']))
   die("Please change the DB SETTINGS in mainfile.php, they currently do not allow connecting to the DB");
   if(!mysql_select_db($xoopsConfig['dbname'],$d))
   die("Please change the DB SETTINGS in mainfile.php, they currently do not allow selecting the DB ".$xoopsConfig['dbname']);
   if(!file_exists(UCMS_CONFIG)) {
   die("We need settings for /config/".UCMS_CONFIG." and /modules/system/cache/".UCMS_MAINMENU." and /modules/system/cache/".UCMS_ADMINMENU.".");
   }

// #################################################################################

   include(XOOPS_ROOT_PATH."/include/common.php");
   }

mainfile.php

The rest of files needs some adopting, feel free to contact me for a CVS access to our development base. I have this up and running for one domain with currently eight subdomains (xxx.yyy.zz), each subdomain having its own DB and local directories. It's running correctly with no problems at all.

WAY TWO (it's a "way, too", in fact) requires Apache's DOCUMENTROOT for any vhost sharing Xoops to address the same directory. By simply patching some elements in modules or core you could easily do some auto-configuration for hosts. In general this is the easy way to server any number of domains with Xoops, automatically adopting some things to "local requirements" like TITLE etc. A typical Apache Virtualhost entry would be like this:

   <VirtualHost wwww.xxxx.yyyyyy.zzzz>
   DocumentRoot /your/global/xoops/directory
   ServerName whatever.wherever
   ServerAlias www.whatever.wherever
   </VirtualHost>

You only need to patch mainfile.php and replace the definition of XOOPS_URL with this:

   define("XOOPS_URL", "http://".$_SERVER['HTTP_HOST']);

This is the "generic" set up. The rest all depends on what you want to do: You could modify your THEMES to respect SERVER['HTTP_HOST'] where needed (I did so...), you could modify include/functions.php to respect it for the page TITLE (I did so ...) etc. What I also did was to patch some modules like news and newbb to respect the HTTP_HOST for differencing between global and local data. This way I have a set of 10 domains running ONE code base with discussion forums that are "globally accessible" and LOCAL forums that are only available and visible to people logged in the correct DOMAIN.


Back to the dev:Main Page

Retrieved from "http://www.xoops.org/modules/mediawiki/index.php/Dev:Xoops_and_Virtual_Host"

This page has been accessed 360 times. This page was last modified 01:49, 16 December 2007. Content is available under XOOPS Project.


Powered by
XOOPS Code hosted on SourceForge

Powered by PHP



Powered by MySQL

Powered by Smarty

OSI certified

All content on this site is subject to the Creative Commons License
Local Support Sites