Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the ACTIVE_SITE via the environment. #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions doc/mw/multisite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,42 @@ To setup Multisite, you must first enable it in the config/kurogo.ini file.
ACTIVE_SITES[] = "es"

This would enable only the *en* and *es* sites on this server.

============================================
Setting the active-site from the environment
============================================

There are some cases where there is a need to host multiple Kurogo sites from the same
webserver, but where one cannot use MultiSite mode due to its dependency on subpaths.
An example is serving each Kurogo site under a different host-name or domain name,
e.g. students.example.edu and faculty.example.edu.

To accomplish this switching, Kurogo supports the specification of the ``ACTIVE_SITE``
parameter via an environmental variable set by your webserver. Kurogo will only look for the ``ACTIVE_SITE`` in the environment when *not* in MultiSite mode and when the ``ACTIVE_SITE`` parameter has no value.

Example ``kurogo.ini``:

.. code-block:: ini

[kurogo]
MULTI_SITE = 0
ACTIVE_SITE = ""

The ``ACTIVE_SITE`` environmental parameter can be set in a number of ways, but one of
the easiest is in your Apache configuration:

::

<VirtualHost *:80>
ServerName students.example.edu
DocumentRoot /var/www/kurogo/www/

SetEnv ACTIVE_SITE Students
</VirtualHost>

<VirtualHost *:80>
ServerName faculty.example.edu
DocumentRoot /var/www/kurogo/www/

SetEnv ACTIVE_SITE Faculty
</VirtualHost>
15 changes: 15 additions & 0 deletions lib/Kurogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,21 @@ private function initSite(&$path) {
define('SITE_NAME', $site);

} else {
// If there is no active site configured and there is one set in the environment
// (such as set by a VirtualHost SetEnv entry), then set the active site to the one
// defined in the environment.
try {
$activeSite = $siteConfig->getVar('ACTIVE_SITE', 'kurogo');
if (empty($activeSite)) {
throw new KurogoKeyNotFoundException('ACTIVE_SITE is empty');
}
} catch (KurogoKeyNotFoundException $e) {
$activeSite = getenv('ACTIVE_SITE');
if (!empty($activeSite)) {
$siteConfig->setVar('kurogo', 'ACTIVE_SITE', $activeSite, $changed);
}
}

$site = '';
if (PHP_SAPI == 'cli') {

Expand Down