Splitting One Site into Many


As mentioned before, this is the "official" way of creating PostNuke Multisites. The module called Multisites is written to achieve site branching, and you can find additional documentation in the module files at /modules/NS-Multisites/docs/readme.html.

Web Server Configuration

There is really only one install of PostNuke in this method; the Multisites system knows to use the separate copies of tables and files by the different domains. The web server needs to be configured to have each of your domains look to the same directory structure, and PostNuke takes it from there. The following is an example of how this is done in the Apache httpd.conf file:

 <VirtualHost *> DocumentRoot /var/www/pets ServerName www.familypets.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/pets ServerName dogs.familypets.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/pets ServerName forums.familypets.com </VirtualHost> 

IIS users will need to use Windows Server 2003 to host the multiple sites. If you need to run a Multisites installation under Windows XP, using Apache's httpd web server is recommended.

PostNuke Install

Install PostNuke normally into the prepared root directory defined previously in Chapter2, "Install PostNuke."

Creating Shared File Directories

First create a new directory called "parameters" in the root of your PostNuke install. All of the files you do not want to share go in this directory. They are copied into a tree of different subfolders so that each site has its own version of the unshared files.

Based on the domains you've set up, create a series of directories that are exactly like the unique elements used in the names. Nonunique elements of a domain include the www hostname found at the start of most full domains and all top-level domains found at the end of the domain, such as com, net, and org. Remove the common elements and what you have left is what the directory needs to be. Table 25.2 details different domain formats and the corresponding directory name you need to make.

Table 25.2. Converting a Domain into a Parameters Directory

DOMAIN

DIRECTORY

www.familypets.com

/parameters/familypets/

dogs.familypets.com

/parameters/dogs.familypets/

cats.familypets.co.uk

/parameters/cats.familypets/

forums.familypets.com

/parameters/forums.familypets/

www.familycats.com

/parameters/familycats/

dogs.familydogs.org

/parameters/dogs.familydogs/


Setting Up whoisit.inc.php

There is a file in the Multisites directory called whoisit.inc.php that needs to be copied to the parameters directory. Copy it once, just to the main folder and not into any of your subfolders. It is found at

 /modules/NS-Multisites/installation/whoisit.inc.php 

Open the file in your editor. Look for the following lines:

 $serverName = $SERVER_NAME; $serverName = str_replace("www","",$serverName); $serverName = str_replace("essai","",$serverName); $serverName = str_replace(".org","",$serverName); $serverName = str_replace(".net","",$serverName); $serverName = str_replace(".com","",$serverName); 

The $SERVER_NAME variable is a global that contains the value of the site to which you are browsing. The preceding lines take the site domain and strip off all nonunique elements, just as you did to make those directories. So, if you have a user who is using www.familypets.com, the first string replace removes the "www" and the last replace removes the ".com" ending.

Tip

Depending on your server configuration and use of subdomain hostnames, the $SERVER_NAME variable might not return the correct name you need. Try $HTTP_HOST instead if you are having resolution problems.


Look at your list of domains and ensure any similar unneeded elements are accounted for in the lines. For example, if you have a country top-level domain, such as ".co.uk," a line for it needs to be created. You can remove unneeded lines if you want to tidy the file.

Duplicating config.php

Take the config.php original file in your site's root and place copies of it in each of the directories you created previously. Open each of the files in your editor and look for the database and table prefix assignments just after line 50:

 $pnconfig['dbname'] = 'familypets'; $pnconfig['prefix'] = 'nuke'; 

In the previous example, the database is called "familypets" and the default "nuke" prefix has been used for the tables. You can use different databases for each branch of your site, but the point of having a table prefix is that you can have duplicate tables in the same database without conflict. For our familypets.com website example, you can use the following settings:

 /parameters/familypets/config.php         $pnconfig['dbname'] = 'familypets';         $pnconfig['prefix'] = 'nuke'; /parameters/dogs.familypets/config.php         $pnconfig['dbname'] = 'familypets';         $pnconfig['prefix'] = 'dogs'; /parameters/forums.familypets/config.php         $pnconfig['dbname'] = 'familypets';         $pnconfig['prefix'] = 'forums'; 

The default table prefix was left on the main site for simplicity. Save all files and close them out of your editor.

Duplicating Tables

Now, it's time to duplicate the PostNuke tables you do not want shared between your sites. The table copies need to be renamed with the prefixes you chose while editing the config.php files. You might want to create a simple spreadsheet that outlines the exact tables with which you need to work.

Note

Some tables are populated with default data that should also be copied whenever duplicating them. It is especially important for the blocks, counter, groups, hooks, settings, modules, themes, and users tables.


Using the content in Table 25.1 to build Table 25.3, the module names have been expanded to show full table names and the shared/not-shared designations have been replaced with the needed prefixes.

Table 25.3. Documenting Table Prefixes

RESOURCE

TABLE

WWW

DOGS

FORUMS

Comments

_comments

nuke

nuke

nuke

FAQ

_faqanswer

nuke

dogs

nuke

FAQ

_faqcategories

nuke

dogs

nuke

Groups

_group_membership

nuke

nuke

nuke

Groups

_group_perms

nuke

nuke

nuke

Groups

_groups

nuke

nuke

nuke

News

_stories

nuke

nuke

nuke

News

_stories_cat

nuke

nuke

nuke

News

_topics

nuke

dogs

nuke

Permissions

_user_perms

nuke

dogs

forums

Settings

_module_vars

nuke

dogs

forums

Stats

_stats_date

nuke

nuke

nuke

Stats

_stats_hour

nuke

nuke

nuke

Stats

_stats_month

nuke

nuke

nuke

Stats

_stats_week

nuke

nuke

nuke

Themes

_theme_addons

nuke

dogs

forums

Themes

_theme_blcontrol

nuke

dogs

forums

Themes

_theme_cache

nuke

dogs

forums

Themes

_theme_config

nuke

dogs

forums

Themes

_theme_layout

nuke

dogs

forums

Themes

_theme_palette

nuke

dogs

forums

Themes

_theme_skins

nuke

dogs

forums

Themes

_theme_tplfile

nuke

dogs

forums

Themes

_theme_tplsource

nuke

dogs

forums

Themes

_theme_zones

nuke

dogs

forums

Users

_user_data

nuke

nuke

nuke

Users

_user_property

nuke

nuke

nuke

Users

_userblocks

nuke

nuke

nuke

Users

_users

nuke

nuke

nuke


The list might seem like quite a lot, but it does make it clear what needs to be changed. The tables are using "nuke" as the default extension already, so the only tables you need to make are those with different prefixes. That list is much shorter:

 _faqanswer _faqcategories _topics _user_perms _module_vars _theme_addons _theme_blcontrol _theme_cache _theme_config _theme_layout _theme_palette _theme_skins _theme_tplfile _theme_tplsource _theme_zones 

Use your database management tool of choice to duplicate the unshared tables with their appropriate prefixes. This can easily be done with a mysqldump to a file or using a command such as the following:

 CREATE TABLE dogs_faqanswer SELECT * FROM nuke_faqanswer; 

which duplicates both the table structure and content. When using the later CREATE command, be certain to check your table keys and indexes to ensure they are configured. Those tables that are unique to multiple domains need multiple copies.

Tip

Some third-party modules might have hard-coded references to their tables. Check the module source or tables after creation if you need to duplicate a noncore module's tables. It's possible to hack the module to make it work if needed, but check beforehand to plan for it.


Duplicating Folders and Module Files

Refer to the previous tables and note again which modules you do not plan to share. They might have files that now need to be copied into the respective /parameters/ folders you created earlier. An example is different themes for the different domains. Also, the /images/ directory likely contains unshared files such as topic icons and the logo.gif called from website settings.

The directories should be organized as follows:

 /parameters/familypets/images/topics/ /parameters/familypets/themes/pettheme1/ /parameters/familypets/themes/pettheme2/ /parameters/dogs.familypets/images/topics/ /parameters/dogs.familypets/themes/dogtheme1/ /parameters/dogs.familypets/themes/dogtheme2/ 

Copy over the data files to their respective domain folders.

Duplicating pntables.php

The pntables.php files mentioned in the earlier "Multisites Basics" section now come back into play. They define all of the tables for the given site, so each domain needs its own copies of the pntables.php files. Remember that not all tables are referenced in the root file, so unshared modules with their own table file, such as Themes, also need their files copied. Here's an example for pathing:

 /parameters/familypets/pntables.php /parameters/familypets/themes/pntables.php /parameters/dogs.familypets/pntables.php /parameters/dogs.familypets/themes/pntables.php 

Tip

If a pntables.php file is not found in the parameters directory, the default file in its normal location is used. So if your main site uses all the defaults, you do not need to copy the table files for it.


Now open all of the pntables.php files in your editor. Every table definition begins with a line like the following:

 $faqcategories = $prefix . '_faqcategories'; 

The prefix defined in your config.php file is applied to the tables. If you have changed the prefix to be unique, such as changing "nuke" to "dogs," you need to edit each shared table so the prefix "nuke" is hard-coded into the table reference as follows:

 $faqcategories = 'nuke_faqcategories'; 

If you used "nuke" in your config.php file, you can instead change only those that are unique, as follows:

 $faqcategories = 'dogs_faqcategories'; 

Fixing config.php

The root config.php file is universally referenced, and you now use it to initiate the config.php files in the separate parameters directories. Back up your root config.php file, and then edit the live copy. Replace all the code with these lines:

Note

A copy of a config.php file with the replacement code is also found in /modules/NS-Multisites/installation/ for your convenience.


 <?php include("parameters/whoisit.inc.php"); if (!(empty($serverName))) {     include("parameters/".$serverName."/config.php"); } define("WHERE_IS_PERSO","parameters/".$serverName."/"); ?> 

This pulls the domain name from the whoisit.inc.php file and uses it to call the correct config.php. The global WHERE_IS_PERSO variable is also defined for those modules that use it to access the correct path.

With this final change saved, your sites are now Multisites.



    PostNuke Content Management
    PostNuke Content Management
    ISBN: 0672326868
    EAN: 2147483647
    Year: 2003
    Pages: 207
    Authors: Kevin Hatch

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net