Bitrix Site Manager

Support for Multiple Sites

Multisite version features

The multisite version of the product allows the following two configuration modes.

The product distribution package is shipped configured to operate in the first configuration mode.

Creating the multiple site system using both configuration modes is considered in this topic. The example will explain how to create a system consisting of the two sites:

Mode 1. Single web server for all sites

The first mode presumes the use of a single Apache web server whose DocumentRoot configured to contain the sites in /home/www/allsites/.

Let us install the Bitrix Site Manager 4.0 in this catalog.

The first mode requires that each site resides in a separate subdirectory of the common directory, for example:

You can choose any other names for catalogs s1 and s2, for example shop and company, or en and de respectively. You can also make one of the sites to reside in the root directory, whereas the other will be placed in its subdirectory.

You have to keep in mind that it is extremely important to separate one site from the other and ensure that the file structure does not interfere.

The configuration file httpd.conf of an Apache web server should contain the following lines, which will reflect the selected configuration:

<VirtualHost *:80>
    ServerAdmin admin@site1.com
    DocumentRoot "/home/www/allsites/"
    ServerName www.site1.com
    ErrorLog logs/allsite.log
    CustomLog logs/allsite.log  common
</VirtualHost>

Please note that the record DocumentRoot value /home/www/allsites/ explicitly defines the directory containing the installed software. The variable DocumentRoot has common value for all sites.

The line <VirtualHost *:80> means that the web server will reply to requests for any domain name and any IP address. That is, having the DNS configured properly, the web server will support both www.site1.com and www.site2.com.

The next step requires that we properly configure and specify both sites in the installed Bitrix software.

You can customize your sites in the administrative section of any site, for example www.site1.com/bitrix/.

Select the menu System Settings -> Sites.

Click the link Modify of the site #1 (www.site1.com) and specify the following parameters:

It is always a good idea to specify the domain name without www. If the DNS is configured so that your site is accessible by the address http://site1.com, the Domain name should not www. You can specify as many as needed domain names that users can indicate in their browsers to access your site; each domain name in the list should start from the new line.

Please bear in mind that the values you specify in the field Domain name are used by the system to deliver the user information to these domains through the user transfer technology. It might be as well to specify a full list of registered domain names by which your site can be accessed.

Do not include in this list sites not running on the current instance of the Bitrix Site Manager. Invalid domains will slow down the system response to users; user information will not be transferred to sites running on other instances of the software.

The Site folder should indicate the existing path relative to the root directory containing the site public section. The Path to web server root folder is not used in this mode; this field should be blank for all sites.

Now set the preferences of the site #2 (www.site2.com):

The system is now almost ready to go. The only thing to do is customize the site selection preferences on the main portal page /index.php.

When site visitors type www.site1.com or www.site2.com in their browsers, they actually open the page /index.php which is located in the directory indicated in the DocumentRoot parameter of the web server. In the multiple site world, this file has slightly different function: it should contain the PHP code used to select one of the sites depending on the current domain name, rather than the index page content.

The following methods of the class CMainPage may help to solve this task:

The following is an example of the index page for the plural site configuration. The code resolves the site by the current domain name.

<?
// include file with CMainPage class
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");

// obtain current site ID by domain name
$site_id = CMainPage::GetSiteByHost();

// get absolute path to the site index page
$page = CMainPage::GetIncludeSitePage($site_id);

// if the site and index page are both defined...
if(strlen($site_id)>0 && strlen($page)>0) 
{
    // include page
    require_once($page);
}
else // if the site is not defined
{
    require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");
    // place code that will display if the site
    // is not defined
    ?>

    <?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");
}
?>

The above algorithm checks the domain name that the visitor typed in the browser to view the site by calling the function CMainPage::GetSiteByHost; searches the list of domain names (the field Domain name) for this domain name to get the site ID and includes the real code of the site index page by calling the function CMainPage::GetIncludeSitePage.

In our case, this means that a visitor who typed www.site1.com in the browser will get the document /s1/index.php without the redirect, whereas a visitor who typed www.site2.com in the browser will get /s2/index.php.

Note
The described algorithm allows to avoid using redirects for both visitors and search engine robots as well as makes handling multiple sites more convenient. This algorithm is recommended for use with multiple sites, though other variations are possible.

If your sites represent language mirrors of a single web resource, you may choose to determine the site by languages installed in the visitor browser.

The following is an example of the index page of the portal containing several sites. The code determines the required site by languages installed in the visitor browser.

<?
// include file with CMainPage class
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");

// get the site id by Accept-Language
$site_id = CMainPage::GetSiteByAcceptLanguage();

// if the site is defined...
if(strlen($site_id)>0) 
{
    // redirect to index page
    CMainPage::RedirectToSite($site_id);
}
else // if the site is not defined
{
    require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");
    // place code that will display if the site
    // is not defined
    ?>

    <?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");
}
?>

The function CMainPage::GetSiteByAcceptLanguage checks the variable Accept-Language in the client browser, compares it to the site language ID and returns the appropriate web site.

In the example above, the function CMainPage::RedirectToSite will perform redirect (HTTP response code 302) and take a visitor to the index page of a site, for example www.site1.com/en/ or www.site2.com/de/.

Create your index page or choose the code of one of the examples. Your sites are now ready to operate in the mode 1.

Mode 2. Separate web servers for each site

The second mode requires that you make special adjustments to both web server and the installed software.

We shall consider configuration of the two sites:

Each of the sites needs a separate virtual Apache web server to be configured. The sites will reside in the following direcories

The configuration file httpd.conf of an Apache web server should contain the following two records, each describing a separate virtual server:

<VirtualHost *:80>
    ServerAdmin admin@site1.com
    DocumentRoot "/home/www/site1/"
    ServerName site1.com
    ServerAlias *.site1.com
    ErrorLog logs/site1.log
    CustomLog logs/site1.log  common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin admin@site2.com
    DocumentRoot "/home/www/site2/"
    ServerName site2.com
    ServerAlias *.site2.com
    ErrorLog logs/site2.log
    CustomLog logs/site2.log  common
</VirtualHost>

Please note that the records DocumentRoot points to different directories containing the corresponding site.

Lines <VirtualHost *:80> denote that the web server will respond to any domain name and IP address. But the variable ServerAlias tells the web server to respond to a specific domain name only.

That is, requests to www.site1.com are processed by the web server instance working with the directory /home/www/site1/, but www.site2.com is managed by the web server that is responsible for the directory /home/www/site1/.

You can configure your web servers to serve specific IP addresses. Example below shows how to configure an Apache web server to support different IP addresses:

<VirtualHost 192.168.0.1:80>
    ServerAdmin admin@site1.com
    DocumentRoot "/home/www/site1/"
    ServerName site1.com
    ErrorLog logs/site1.log
    CustomLog logs/site1.log  common
    Options +FollowSymLinks
</VirtualHost>
<VirtualHost 192.168.0.2:80>
    ServerAdmin admin@site2.com
    DocumentRoot "/home/www/site2/"
    ServerName site2.com
    ErrorLog logs/site2.log
    CustomLog logs/site2.log  common
    Options +FollowSymLinks
</VirtualHost>

Having the DNS server properly configured for different domain names, each virtual web server will run on a separate IP address and respond to a specific domain name.

Next step is to install the product with this configuration. The commands rendered in green text illustrate how to install the system on UNIX-based systems.

  1. Install the Bitrix Site Manager 4.0 to the directory of the first site /home/www/site1/
  2. Create the folder /home/www/shared/. It will contain files common to all sites.
    mkdir /home/www/shared
  3. Move the entire directory /home/www/site1/bitrix/ to /home/www/shared/bitrix/:
    mv /home/www/site1/bitrix /home/www/shared/bitrix
  4. Move the entire directory /home/www/site1/upload/ to /home/www/shared/upload/:
    mv /home/www/site1/upload /home/www/shared/upload
  5. Create the symbolic link to the directory /bitrix/ for each site:
    1. ln -s /home/www/shared/bitrix /home/www/site1/
    2. ln -s /home/www/shared/upload /home/www/site1/
    3. ln -s /home/www/shared/bitrix /home/www/site2/
    4. ln -s /home/www/shared/upload /home/www/site2/
  6. Please ensure that the directory /home/www/shared/ of a web server (Apache, IIS) has write permissions. This is essential for the update system and image uploads.
  7. Copy the public pages of the second site to the directory/home/www/site2/

Note
Windows based web servers require third-party tools for the symbolic link creation. For example, Far Manager or Junction by Sysinternals.

Next step is to properly configure sites in the installed Bitrix software.

You can perform adjustments in the administrative section. Select the menu command System Settings -> Sites.

Click the link Modify of the site #1 (www.site1.com) and specify the following parameters:

If the DNS is configured so that your site is accessible by the address http://site1.com, the Domain name should not www. You can specify as many as needed domain names that users can indicate in their browsers to access your site; each domain name in the list should start from the new line.

Please bear in mind that the values you specify in the field Domain name are used by the system to deliver the user information to these domains through the user transfer technology. It might be as well to specify a full list of registered domain names by which your site can be accessed.

Do not include in this list sites not running on the current instance of the Bitrix Site Manager. Invalid domains will slow down the system response to users; user information will not be transferred to sites running on other instances of the software.

Now set the preferences of the site #2 (www.site2.com):

Please note that both sites has the same Site folder "/". This is possible due to the fact that the sites run on separate web servers with different physical files location.

An attention should be paid to the Path to web server root folder of this site parameter. For different sites, it has different values taken from the DocumentRoot parameter of the corresponding virtual server settings (see the example of the file httpd.cnf above).

Note
Please bear in mind that if you implement your multiple site environment using this model, you can use virtual servers of a single Apache web server instance as well as different instances of a web server. The same applies to other web severs: IIS, EServ etc.

The configuration is now ready to run.

Unlike the first configuration mode, this mode does not require any special site selection algorithm to be defined in the portal index page, as the site is unambiguously determined by the domain name.

Conclusion

The described recommendations allow configuring the Bitrix Site Manager to work in the multiple site mode.

The Bitrix Site Manager does not give preference to any of the versions. The first mode is generally used if you use the virtual hosting or feel uncertainty at configuring web servers. The second variant can be recommended if you use a dedicated server or the shared hosting allows several web server instances. This mode allows to exclude catalogs like /s1/ or /s2/ from URL's and start addresses from the root directory "/".