Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2 3

Author Topic: Multiple installations using one sNews engine and one database.  (Read 16868 times)

Joost

  • Guest

This mod makes it possible to run several  installations, whith only one snews.php file. The respective installs are located in their own directories.
The first approach will create independend functioning installation, with different settings and passwords.
The second approach will point all installations to one settings table.

The differences for every install is located in // DATABASE VARIABLES in snews.php.
1) A separate configure file with database variables for each installation has to be created and put into a config.php.
2) Database variables in snews.php have to be deleted.
3) News.php has to be included in each config.php and  each config.php is included in index.php.

A schematic:



Database tables
For each installation 4 tables have to be created in the database. The tables have to have a prefix, which basically means you will have to add an extra name before each table like this:

britney_articles,  britney_comments ,britney_settings ,britney_categories.

Do the same for the other installations. The package includes a file to create three times four tables, thus you can create three installs. Alter the prefixes to your convenience and add more tables if needed.

.htaccess
One .htaccess file for each installation is needed. Adjust #RewriteBase for each installation.

folder
For every installation one folder.Every folder contains:
 - index.php
 - .htaccess
 - style.css
 - config.php
(Renaming each config.php to a different name like britney.php or office.php makes it easier to maintain and you could keep all files in one folder with snews.php. Make up your mind before installing.)

Here is the package. No snews.php included. Use your favourite modded snews.php (without database variables).
It is not an easy install package. It is merely an example to visualize the structure. In the package Britney and German are subdirectories/folders of office, and will have the following url's.

domain.com/office/
domain.com/office/britney/
domain.com/office/german/
____________

Multiple installations, one settings table

This might be useful if you use the extra installs to expand your website, pretending  it to have subcategories. To achieve this, all installations have to point to one (prefixed) settings table (or the other way around  :rolleyes:  ).

step zero: Backup snews.php
Search and replace in snews.php
Quote
".db('prefix')."settings
with
Quote
prefix_settings
Change prefix_ with the name of the table you want to use. In a default installation you will have to repeat this four times. Now you only be using the settings table of your choice. If you wish, you can safely delete the other settings tables or simply don't create them at all.

Tip: You can attach one stylesheet to all index.php's.
Note: For every installation there is still a separate upload file, a separate archive and a separate sitemap (did I say it was perfect?).


Linking to editors, js and images from snews.php Both approaches
If your snews engine is linking (html) to a file such as editors, js and images, start the path from the root of the site,  like:
Quote
/ office/pencil.js
or
Code: [Select]
http://www.solucija.com/javascript.jsIndex.php links can be treated as usual.
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Multiple installations using one sNews engine and one database.
« Reply #1 on: July 06, 2007, 10:06:24 AM »

Interesting ;)
Few thoughts:
- Might be good to emphasize in description of this the removal/commenting out of function db() from snews.php as separate step to do. That phrase regarding removal of database variables from doesn't exactly cut it through for casual reader :)
- Probably, single approach with fixed name config.php in the root and subdirectories as well would be more handy as well as reduce clutter in the root. Or may be not ;)
Logged

Joost

  • Guest
Multiple installations using one sNews engine and one database.
« Reply #2 on: July 06, 2007, 10:23:33 AM »

Quote from: codetwist
Interesting ;)
Few thoughts:
- Might be good to emphasize in description of this the removal/commenting out of function db() from snews.php as separate step to do. That phrase regarding removal of database variables from doesn't exactly cut it through for casual reader :)
- Probably, single approach with fixed name config.php in the root and subdirectories as well would be more handy as well as reduce clutter in the root. Or may be not ;)
- Description emphazised
- I am not sure what you mean with 'single approach'
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Multiple installations using one sNews engine and one database.
« Reply #3 on: July 06, 2007, 12:59:26 PM »

That 'single approach' actually meant only that config.php are named just that and stored in each subfolder without any renaming and keeping them in root folder. I was even looking for these config.php indownloaded example. But that's not big deal as it's just my preferences ;)
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Multiple installations using one sNews engine and one database.
« Reply #4 on: July 06, 2007, 02:24:57 PM »

This is a most interesting approach Joost. The"Multiple installations with one settings table" will be easier for me to test-run since I've already replaced all table-names file-wide with variables at the top of snews.php in my current mod-pack. I must put other projects aside and try this out today. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Multiple installations using one sNews engine and one database.
« Reply #5 on: July 06, 2007, 03:13:43 PM »

I want to try this approach with bakercad's Multi-Users mod which has an extra (5th) "Users" table, mainly because I am working on a project that needs multiple admin access and will have several sub-departments or sub-sites within it. So... let me just confirm what I think is how this works (thinking out loud...)

Each install has its own dbase config file which includes the same snews.php engine file used by all installs but uses its own set of 4 tables... and the config file is included into its respective index.php file... ensuring all the engine functions pass through all config files to all index.php files. I should be able to have separate users tables for each install too... or use just one users table for all.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

TheTick

  • Full Member
  • ***
  • Karma: 6
  • Posts: 105
Multiple installations using one sNews engine and one database.
« Reply #6 on: July 06, 2007, 03:41:31 PM »

Question: How does this relate to the Search function? Will someone browsing the "Britney" section searching for a term get results from articles or pages in the "office" & "shop" section as well as the"Britney" section?

That would be a deal breaker for me if you don't have a site-wide search...
Logged

centered

  • Guest
Multiple installations using one sNews engine and one database.
« Reply #7 on: July 06, 2007, 06:15:09 PM »

Quote from: TheTick
Question: How does this relate to the Search function? Will someone browsing the "Britney" section searching for a term get results from articles or pages in the "office" & "shop" section as well as the"Britney" section?

That would be a deal breaker for me if you don't have a site-wide search...
QFT. Really Joost, I think you are on to something good.  Where is agent?  Doesn't he have a similar setup?
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Multiple installations using one sNews engine and one database.
« Reply #8 on: July 06, 2007, 06:51:09 PM »

centered -- yeah, sort of but I haven't gone as far into it as Joost has, yet. I'm actually in the middle of a site where I am/will be doing more or less exactly like Joost has described above. The main difference is this:
Quote from: The Penguin Exterminator
Search and replace in snews.php
Quote
".db('prefix')."settings
with
Quote
prefix_settings
Change prefix_ with the name of the table you want to use. In a default installation you will have to repeat this XX times. Now you only be using the settings table of your choice. If you wish, you can safely delete the other settings tables or simply don't create them at all
:o

@Joost -- User Guide? :lol: (Good use of prefixes. Thanks!)

@key's -- Sharp minds, etc. The site I'm working on also uses the bobster's MU... ;)
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Multiple installations using one sNews engine and one database.
« Reply #9 on: July 06, 2007, 06:56:50 PM »

As discussed above the search probably goes to this list as well:
Quote from: Joost
...

Note: For every installation there is still a separate upload file, a separate archive and a separate sitemap (did I say it was perfect?).

...
Might be feasible to change approach a little and define a little bit more complex configuration for this one. Like loading all config-s into global assoc array and fixing current 'subsite' (root, britney, whatever)?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Multiple installations using one sNews engine and one database.
« Reply #10 on: July 06, 2007, 07:10:33 PM »

Quote from: agentsmith
@key's -- Sharp minds, etc. The site I'm working on also uses the bobster's MU... ;)
@ Agent... I created a new variable array and replaced all table-name instances... file-wide... with the new values... so I can choose to use any combination of tables within the database. I 'spose I could have just added these to the existing $db array and called the values from there but I wanted to test new arrays file-wide anyway. It's useful if you wanted to have several sub-sites running different content and settings tables, but all using the same users table. :)
Quote
function gl($variable) { # for use with the Bobster's 16MU
   $gl = array();
   # Variables replacing table names throughout this file.     - search-for locations
   $gl['articles_table'] = 'articles';   //      ".gl('articles_table')."
   $gl['categories_table'] = 'categories';   //      ".gl('categories_table')."
   $gl['comments_table'] = 'comments';   //      ".gl('comments_table')."
   $gl['settings_table'] = 'settings';   //      ".gl('settings_table')."
   $gl['users_table'] = 'users';      //      ".gl('users_table')."
   return $gl[$variable];
      }
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Joost

  • Guest
Multiple installations using one sNews engine and one database.
« Reply #11 on: July 06, 2007, 07:34:10 PM »

Thank you all for the response. Actually it was something I thought about before I ever had installed my first sNews, after reading Keys tutorial how to set up a database with multi installs. Since I am not a good coder I have to think about reusing what is already available in the system. :)
I hasitated for a while, because I had not seen this approach before, but knowing that keyrocks was in the middle of a multi installation project., I thought it was time to test it and publish it.

@TheTick
In both approaches it is not possible to search Britney from within Office.
However, I think you can make the search site wide, when changing the query in function search()
Quote
db('prefix')."articles
has to be replaced with something like
Quote
office_articles, britney_articles etc., (look into the mysql syntax for proper notation)
Could be done for other queries as well.

Quote from: agentsmith
User Guide?
I don't get it.:/
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Multiple installations using one sNews engine and one database.
« Reply #12 on: July 06, 2007, 07:38:41 PM »

Quote from: Saint Keyrocks
It's useful if you wanted to have several sub-sites running different content and settings tables, but all using the same users table
Makes sense ... keeps things organised.

So, [stupid question #1] you exclude users in each 'prefix_' subset, right? (does that work?)

@Joost: just yanking your chain a little...
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Multiple installations using one sNews engine and one database.
« Reply #13 on: July 06, 2007, 08:14:59 PM »

@agent:  bobster's MU  ?,  is this the same as rui's MU ?

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Multiple installations using one sNews engine and one database.
« Reply #14 on: July 06, 2007, 08:16:44 PM »

More on what I meant in my post above ... kind of triggered some code excerpting frenzy :D

In index.php apart from inclusion of config.php file the current subsite should be fixed (obviously different for each subsite or root). So at top folder where for example office site is located it could look like this:
Code: [Select]
$curSubsite = 'root';
include( 'config-lib.php' );
//include( '../config-lib.php' );
include( 'config.php' );
Configuration files are created in each subsite and root folders and named just config.php. So, for  example, office site configuration file could look like this:
Code: [Select]
$cfgSubsite = 'root';

$db = array();
$db['website'] = 'http://domainname/office/';// Change this for every directory
$db['dbhost'] = 'localhost'; //MySQL Host
$db['dbname'] = 'insert database name'; //Database Name
$db['dbuname'] = 'insert user'; //Database Username
$db['dbpass'] = 'XXXXXXXX'; //Database password
$db['prefix'] = 'office_'; //Database prefix               INSERT A PREFIX FOR EVERY INSTALLATION
$db['dberror'] = 'There was an error while connecting to the database.
 Check your database settings.'; //Database error message
//
//$db['settings_prefix'] = $db['prefix'];
$db['settings_prefix'] = 'office_';
//
$db['users_prefix'] = $db['prefix'];
$db['users_prefix'] = 'office_';

initDb( $db, $cfgSubsite );

if ($cfgSubsite == 'root') {
   include( 'snews.php' );
}
else {
   include( '../snews.php' );
}
And for britney subsite configuration file could look like this:
Code: [Select]
$cfgSubsite = 'britney';

$db = array();
$db['website'] = 'http://domainname/office/';// Change this for every directory
$db['dbhost'] = 'localhost'; //MySQL Host
$db['dbname'] = 'insert database name'; //Database Name
$db['dbuname'] = 'insert user'; //Database Username
$db['dbpass'] = 'XXXXXXXX'; //Database password
$db['prefix'] = 'britney_'; //Database prefix               INSERT A PREFIX FOR EVERY INSTALLATION
$db['dberror'] = 'There was an error while connecting to the database.
 Check your database settings.'; //Database error message
//
//$db['settings_prefix'] = $db['prefix'];
$db['settings_prefix'] = 'office_';
//
//$db['users_prefix'] = 'office_';

initDb( $db, $cfgSubsite );

if ($cfgSubsite == 'root') {
   include( 'snews.php' );
}
else {
   include( '../snews.php' );
}
For this to work few additional functions are created and stored either in separate config-lib.php file stored at site root folder (this example - office) along with config.php:
Code: [Select]
function initDb( $dbCfg, $subsite = 'root' ) {
   global $dbCfgs;
   //
   if (!isset($dbCfgs) || !is_array($dbCfgs)) {
      $dbCfgs = array();
   }
   //
   $dbCfgs[$subsite] = $dbCfg;
}


function getDbVar( $variable, $subsite = 'root' ) {
   global $dbCfgs;
   //
   if ( is_array($dbCfgs) && is_array($dbCfgs[$subsite])) {
      return $dbCfgs[$subsite][$variable];
   }
}


function prefixTableName( $tableName, $subsite ) {
   if ( $tableName == 'settings' ) {
      if ( $prefix = getDbVar( 'settings_prefix', $subsite ) ) {
         return getDbVar( 'settings_prefix', $subsite ) . $tableName;
      }
      else {
         return getDbVar( 'prefix', $subsite ) . $tableName;
      }
   }
   elseif ( $tableName == 'users' ) {
      if ( $prefix = getDbVar( 'users_prefix', $subsite ) ) {
         return getDbVar( 'users_prefix', $subsite ) . $tableName;
      }
      else {
         return getDbVar( 'prefix', $subsite ) . $tableName;
      }
   }
   else {
      return getDbVar( 'prefix', $subsite ) . $tableName;
   }
}

function db( $variable ) {
   global $curSubsite;
   return getDbVar( $variable, $curSubsite );
}
And finally change from:
Code: [Select]
db('prefix') . 'settings'to:
Code: [Select]
prefixTableName( 'settings', $curSubsite )across all snews.php :/ And same for users if such is use :P
Logged
Pages: [1] 2 3