Skip navigation.
Home

PHP List Hack: Shared Codebase

This is a trick to allow you to run one copy of the PHPList software on your server, and have separate configurations for each domain. The main advantage is that you don't have a bunch of copies of the same software all over the place. (PHPList takes up around 5 megs of disk. Using a similar technique with Drupal [which takes up 6 megs], we can install Drupal and PHPList in 260k of space, not including databases.)

At the top of index.php and admin/index.php, there's some code that looks for the config.php file. This new code snippet allowed me to create a config file named "phplist.config.php" in the user's root (or the ftp root) instead of the usual places.

The lists/ directory, which contains all the code, was moved to /usr/local, and the directory symlinked to the document root.

The code at the top does a little bit of guessing about the domain name. We also have a preview link (to let us work on the site before it's launched), and we can detect the domain name from the URI if they're using the preview.

The config file should be generated from a template, for the user.

// johnk - shared codebase needs some info
$domain = $_SERVER['SERVER_NAME'];
$domain = preg_replace('/^www/i','',$domain);
if ($domain=='zanon.slaptech.net') {
preg_match( '#/preview/(.+?)/#', $_SERVER["REQUEST_URI"], $matches );
$domain = $matches[1];
}

if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
print '<!-- using '.$_SERVER["ConfigFile"].'-->'."\n";
include $_SERVER["ConfigFile"];
} elseif (isset($cline["c"]) && is_file($cline["c"])) {
print '<!-- using '.$cline["c"].' -->'."\n";
include $cline["c"];
} elseif (isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
# print '<!-- using '.$_ENV["CONFIG"].'-->'."\n";
include $_ENV["CONFIG"];
} elseif (is_file("/www/$domain/phplist.config.php")) {
print '<!-- using /www/$domain/phplist.config.php -->'."\n";
include "/www/$domain/phplist.config.php";
} elseif (is_file("../config/config.php")) {
print '<!-- using ../config/config.php -->'."\n";
include "../config/config.php";
} else {
print "Error, cannot find config file\n";
exit;
}

In connect.php, a little hack enables staging:

function Redirect($page) {
if ($GLOBALS['staging']) {
Header("Location: " . $GLOBALS['staging_url'] . $GLOBALS["adminpages"] . "/?page=$page");
exit;
} else {
$website = getConfig("website");
Header("Location: " . $GLOBALS['scheme'] . "://" . $website . $GLOBALS["adminpages"] . "/?page=$page");
exit;
}
}

And, in the config file, there's new definitions:

$staging = 1;
$staging_url = "http://zanon.slaptech.net/preview/myhdomaind.com";