MSU Masthead

Metlab CourseLib cl/site configuration

cl/site

The cl/site installation process creates a file site.php in the site root directory that is the main configuration file for a site.

Required Configurations

Site root

Set the value of the site root to a path on the server to the site root directory if the site is not at the root normally.

// The site root path. Set to different value if
// path to site is not in server root.
$site->root = '';

For example, if the site root is https://www.cse.msu.edu/~cse999, the value of $site->root would be set to '/~cse499'. A leading slash is included for any non-empty path. Do not include the trailing slash.

Site name

Set the siteName to a name for the site:

$site->siteName = 'CourseLib';

If the cl/course component is installed, the siteName is automatically set.

Database Configuration

// Database configuration
// The fields are:
// dbhost: Database host string, like 'mysql:host=127.0.0.1;dbname=cse999'
// dbname: Database name: like 'cse999'
// dbuser: Database user id, like 'cse999'
// dbpassword: Database password
// prefix: Prefix to add to table names (optional, but recommended)
$site->db->configure('',
	'',
	'',
	'',
	'');

Set the database configuration for the database in use by the site. For example:

	$site->db->configure('mysql:host=127.0.0.1;dbname=cse999',
		'cse999',
		'cse999',
		'password',
		'cse999_');

The database prefix will be prefixed on all table names and is useful to make the tables used by the system clear. For example, if the table prefix is set to

'cse999_', the user table will be named 'cse999_user'.

Database configuration is required only if a database is needed. The base cl/site system does not utilize the database for any functions other than logging and will function without a database installed. Most other subsystems, particularly cl/users and cl/course, are dependent on database functions and require a configured database.

Optional Configurations

Increased Error Reporting

It is common that web servers will disable some error reporting. Uncomment the following lines in site.php to increase the error reporting:

//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting(E_ALL);

Sandbox configuration

It is useful when developing a site to have a web server running locally so the site can be tested prior to pushing to an online site. This is commonly referred to as 'running in a sandbox'. Usually the hostname when running the sandbox will be something like 'localhost' or 'cse999.localhost'. Since the configuration in the sandbox may vary from the runtime installation, some conditional logic is required in site.php. For example:

$host = $_SERVER['HTTP_HOST'];
if(strpos($host, 'localhost') !== false) {
	$site->sandbox = true;
	$site->root = '';
	$site->db->configure('mysql:host=127.0.0.1;dbname=cse999',
		'cse999',
		'cse999',
		'local-password',
		'localprefix_');
} else {
	$site->root = '/~cse999';
	$site->db->configure('mysql:host=mysql.server.edu;dbname=cse999',
		'cse999',
		'cse999',
		'runtime-password',
		'runtimeprefix_');
}

Cookie prefix

An optional cookie prefix can be provided. If a web server is used for more than one site, cookiePrefix should be set to a unique value for each site. This prevents ambiquity as to what site the cookie is used for. A recommended cookie prefix is the course name as in 'cse999_'.

// Prefix to add to cookie names. Recommended if site has more than
// one course on it.
$site->cookiePrefix = 'cse999_';

Timezone

If the server PHP timezone is not set to local time by default, site.php is a good place to set it:

// Set the time zone
date_default_timezone_set('America/Detroit');

Config directory

The site config directory is where site configuration files other than site.php are stored. The default is 'site'. A common alternative is 'course':

$site->config = 'course';

Decor directory

Decor files are used to modify the appearance of standard site pages by adding content. By default, decor pages are stored in the directory site. It is common that these may be placed in a different directory, such as course/decor:

$site->decor = 'course/decor';

Custom Appearance

The appearance of CourseLib pages can be customized using an installed appearance component. An example installed appearance component is:

msu.zip

To install this example appearance, unzip it into the course root directory and require the file msu.php:

require __DIR__ . '/msu/msu.php';

Then add this line of code to utilize the installed appearance:

$site->appearance = new MSUAppearance();