Allow calling of installer by running 'make install' from an environment with an _ss_environment.php file. This is important for continuous integration.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/phpinstaller/trunk@48125 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
sminnee 2008-01-16 23:47:23 +00:00
parent 1fe1614bce
commit 5ed785dc71
2 changed files with 236 additions and 185 deletions

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# This makefile is a secondary way of installing SilverStripe.
# It is used for things like continuous integration
#
# Most users should simply visit the site root in your web browser.
#
install: mysite/_config.php
mysite/_config.php:
php install.php install SS_testdatabase
test: clean install
$(MAKE) -C sapphire test
clean:
if [ -f .htaccess ]; then rm .htaccess; fi
touch .htaccess
if [ -f mysite/_config.php ]; then rm mysite/_config.php; fi

View File

@ -6,30 +6,40 @@
*/
ini_set('max_execution_time', 300);
session_start();
session_start();
// Include environment files
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php');
foreach($envFiles as $envFile) {
if(@file_exists($envFile)) {
include($envFile);
break;
}
}
// Load database config
if(isset($_REQUEST['mysql'])) {
$databaseConfig = $_REQUEST['mysql'];
} else {
$databaseConfig = array(
"server" => "localhost",
"username" => "root",
"password" => "",
"database" => "SS_mysite",
"type" => "MySQLDatabase",
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
"username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root",
"password" => defined('SS_DATABASE_PASSWORD') ? SS_DATABASE_PASSWORD : "",
"database" => isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : "SS_mysite",
);
}
if(isset($_REQUEST['admin'])) {
$adminConfig = $_REQUEST['admin'];
} else {
$adminConfig = array(
'username' => 'admin',
'password' => 'password',
'firstname' => '',
'surname' => ''
);
}
if(isset($_REQUEST['admin'])) {
$adminConfig = $_REQUEST['admin'];
} else {
$adminConfig = array(
'username' => 'admin',
'password' => 'password',
'firstname' => '',
'surname' => ''
);
}
$alreadyInstalled = (file_exists('mysite/_config.php') || file_exists('tutorial/_config.php'));
@ -60,14 +70,20 @@ if($databaseConfig) {
}
// Actual processor
if(isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
$installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install');
if(isset($_REQUEST['go']) || $installFromCli && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling
if(!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) {
include('config-form.html');
} else {
$inst = new Installer();
$inst->install($_REQUEST);
if($_REQUEST) $inst->install($_REQUEST);
else $inst->install(array(
'database' => $databaseConfig['type'],
'mysql' => $databaseConfig,
'admin' => $adminConfig,
));
}
// Show the config form
@ -129,23 +145,23 @@ class InstallRequirements {
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null));
// Check for rewriting
// Check for web server, unless we're calling the installer from the command-line
if(!$_SERVER['argv']) {
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
if($webserver == '') {
$webserver = "I can't tell what webserver you are running";
}
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
if($webserver == '') {
$webserver = "I can't tell what webserver you are running";
$this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if(function_exists('apache_get_modules')) {
$this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled."));
} else {
$this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself."));
}
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
}
$this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if(function_exists('apache_get_modules')) {
$this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled."));
} else {
$this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself."));
}
// Check for $_SERVER configuration
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
// Check for GD support
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) {
$this->requireFunction("imagecreate", array("PHP Configuration", "GD2 support", "GD2 support", "GD support for PHP not included."));
@ -177,16 +193,16 @@ class InstallRequirements {
}
}
function requireMemory($min, $recommended, $testDetails) {
$_SESSION['forcemem'] = false;
function requireMemory($min, $recommended, $testDetails) {
$_SESSION['forcemem'] = false;
$mem = $this->getPHPMemory();
if($mem < (32 * 1024 * 1024)) {
ini_set('memory_limit', '32M');
$mem = $this->getPHPMemory();
$testDetails[3] = ini_get("memory_limit");
}
$mem = $this->getPHPMemory();
if($mem < (32 * 1024 * 1024)) {
ini_set('memory_limit', '32M');
$mem = $this->getPHPMemory();
$testDetails[3] = ini_get("memory_limit");
}
$this->testing($testDetails);
if($mem < $min && $mem > 0) {
@ -273,17 +289,17 @@ class InstallRequirements {
function requirePHPVersion($recommendedVersion, $requiredVersion, $testDetails) {
$this->testing($testDetails);
list($recA, $recB, $recC) = explode('.', $recommendedVersion);
list($reqA, $reqB, $reqC) = explode('.', $requiredVersion);
list($a, $b, $c) = explode('.', phpversion());
$c = ereg_replace('-.*$','',$c);
if($a > $recA || ($a == $recA && $b > $recB) || ($a == $reqA && $b == $reqB && $c >= $reqC)) {
$testDetails[2] = "SilverStripe recommends PHP version $recommendedVersion or later, only $a.$b.$c is installed. While SilverStripe should run, you may run into issues, and future versions of SilverStripe may require a later version. Upgrading PHP is recommended.";
$this->warning($testDetails);
return;
}
if($a > $recA || ($a == $recA && $b > $recB) || ($a == $reqA && $b == $reqB && $c >= $reqC)) {
$testDetails[2] = "SilverStripe recommends PHP version $recommendedVersion or later, only $a.$b.$c is installed. While SilverStripe should run, you may run into issues, and future versions of SilverStripe may require a later version. Upgrading PHP is recommended.";
$this->warning($testDetails);
return;
}
if($a > $reqA) return true;
if($a == $reqA && $b > $reqB) return true;
@ -292,7 +308,7 @@ class InstallRequirements {
if(!$testDetails[2]) {
if($a < $reqA) {
$testDetails[2] = "You need PHP version $version or later, only $a.$b.$c is installed. Unfortunately PHP$a and PHP$reqA have some incompatabilities, so if you are on a your web-host may need to move you to a different server. Some software doesn't work with PHP5 and so upgrading a shared server could be problematic.";
} else {
} else {
$testDetails[2] = "You need PHP version $requiredVersion or later, only $a.$b.$c is installed. Please upgrade your server, or ask your web-host to do so.";
}
}
@ -328,7 +344,7 @@ class InstallRequirements {
function requireWriteable($filename, $testDetails) {
$this->testing($testDetails);
$filename = $this->getBaseDir() . $filename;
if(function_exists('posix_getgroups')) {
if(!is_writeable($filename)) {
$user = posix_getpwuid(posix_geteuid());
@ -341,47 +357,47 @@ class InstallRequirements {
$testDetails[2] .= "User '$user[name]' needs to write be able to write to this file:\n$filename";
$this->error($testDetails);
}
} else {
$testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable.";
$this->warning($testDetails);
}
} else {
$testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable.";
$this->warning($testDetails);
}
}
function requireTempFolder($testDetails) {
$this->testing($testDetails);
if(function_exists('sys_get_temp_dir')) {
$sysTmp = sys_get_temp_dir();
} elseif(isset($_ENV['TMP'])) {
$sysTmp = $_ENV['TMP'];
} else {
@$tmpFile = tempnam('adfadsfdas','');
@unlink($tmpFile);
$sysTmp = dirname($tmpFile);
}
$worked = true;
$ssTmp = "$sysTmp/silverstripe-cache";
if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp);
if(!$worked) {
$ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache";
$worked = true;
if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp);
}
if(!$worked) {
$testDetails[2] = "Permission problem gaining access to a temp folder. " .
"Please create a folder named silverstripe-cache in the base folder " .
"of the installation and ensure it has the adequate permissions";
$this->error($testDetails);
}
}
}
}
}
function requireTempFolder($testDetails) {
$this->testing($testDetails);
if(function_exists('sys_get_temp_dir')) {
$sysTmp = sys_get_temp_dir();
} elseif(isset($_ENV['TMP'])) {
$sysTmp = $_ENV['TMP'];
} else {
@$tmpFile = tempnam('adfadsfdas','');
@unlink($tmpFile);
$sysTmp = dirname($tmpFile);
}
$worked = true;
$ssTmp = "$sysTmp/silverstripe-cache";
if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp);
if(!$worked) {
$ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache";
$worked = true;
if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp);
}
if(!$worked) {
$testDetails[2] = "Permission problem gaining access to a temp folder. " .
"Please create a folder named silverstripe-cache in the base folder " .
"of the installation and ensure it has the adequate permissions";
$this->error($testDetails);
}
}
}
}
function requireApacheModule($moduleName, $testDetails) {
$this->testing($testDetails);
@ -490,8 +506,12 @@ class InstallRequirements {
}
protected $baseDir;
function getBaseDir() {
return dirname($_SERVER['SCRIPT_FILENAME']) . '/';
// Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method
// still returns the correct value.
if(!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/';
return $this->baseDir;
}
function testing($testDetails) {
@ -533,39 +553,44 @@ class InstallRequirements {
}
class Installer extends InstallRequirements {
function __construct() {
// Cache the baseDir value
$this->getBaseDir();
}
function install($config) {
?>
<h1>Installing SilverStripe...</h1>
<p>I am now running through the installation steps (this should take about 30 seconds)</p>
<p>If you receive a fatal error, refresh this page to continue the installation
<?php
flush();
if(isset($_POST['stats'])) {
if(file_exists('sapphire/silverstripe_version')) {
$sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
if(strstr($sapphireVersionFile, "/sapphire/trunk")) {
$silverstripe_version = "trunk";
} else {
preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches);
$silverstripe_version = $matches[1];
}
} else {
$silverstripe_version = "unknown";
}
$phpVersion = urlencode(phpversion());
$conn = @mysql_connect($config['mysql']['server'], null, null);
$databaseVersion = urlencode('MySQL ' . mysql_get_server_info());
$webserver = urlencode($_SERVER['SERVER_SOFTWARE']);
$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver";
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url .= '&ID=' . $_SESSION['StatsID'];
}
@$_SESSION['StatsID'] = file_get_contents($url);
flush();
if(isset($_POST['stats'])) {
if(file_exists('sapphire/silverstripe_version')) {
$sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
if(strstr($sapphireVersionFile, "/sapphire/trunk")) {
$silverstripe_version = "trunk";
} else {
preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches);
$silverstripe_version = $matches[1];
}
} else {
$silverstripe_version = "unknown";
}
$phpVersion = urlencode(phpversion());
$conn = @mysql_connect($config['mysql']['server'], null, null);
$databaseVersion = urlencode('MySQL ' . mysql_get_server_info());
$webserver = urlencode($_SERVER['SERVER_SOFTWARE']);
$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver";
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url .= '&ID=' . $_SESSION['StatsID'];
}
@$_SESSION['StatsID'] = file_get_contents($url);
}
// Delete old _config.php files
@ -579,26 +604,26 @@ class Installer extends InstallRequirements {
// Write the config file
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
$theme = '';
if($_POST['template'] == 'default') {
$theme = <<<PHP
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
SSViewer::set_theme('blackcandy');
PHP;
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
$theme = '';
if($_POST['template'] != 'tutorial') {
$theme = <<<PHP
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
SSViewer::set_theme('blackcandy');
PHP;
}
echo "<li>Creating '$template/_config.php'...</li>";
flush();
$devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites']));
flush();
$devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites']));
$escapedPassword = addslashes($config['mysql']['password']);
$this->createFile("$template/_config.php", <<<PHP
<?php
$mem
global \$project;
@ -613,13 +638,13 @@ global \$databaseConfig;
"database" => "{$config['mysql']['database']}",
);
// Sites running on the following servers will be
// run in development mode. See
// http://doc.silverstripe.com/doku.php?id=devmode
// for a description of what dev mode does.
// Sites running on the following servers will be
// run in development mode. See
// http://doc.silverstripe.com/doku.php?id=devmode
// for a description of what dev mode does.
Director::set_dev_servers($devServers);
$theme
$theme
?>
PHP
@ -631,31 +656,32 @@ PHP
$this->createHtaccess();
// Load the sapphire runtime
$_SERVER['SCRIPT_FILENAME'] = dirname($_SERVER['SCRIPT_FILENAME']) . '/sapphire/main.php';
$_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/sapphire/main.php';
chdir('sapphire');
require_once('core/Core.php');
require_once('core/ManifestBuilder.php');
require_once('core/ClassInfo.php');
require_once('core/Object.php');
require_once('core/control/Director.php');
require_once('core/ViewableData.php');
require_once('core/Session.php');
require_once('core/control/Controller.php');
require_once('core/Core.php');
require_once('core/ManifestBuilder.php');
require_once('core/ClassInfo.php');
require_once('core/Object.php');
require_once('core/control/Director.php');
require_once('core/ViewableData.php');
require_once('core/Session.php');
require_once('core/control/Controller.php');
require_once('filesystem/Filesystem.php');
echo "<li>Building database schema...</li>";
flush();
// Build database
$_GET['flush'] = true;
$con = new Controller();
// Build database
$_GET['flush'] = true;
$con = new Controller();
$con->pushCurrent();
ManifestBuilder::compileManifest();
require(MANIFEST_FILE);
$dbAdmin = new DatabaseAdmin();
$dbAdmin->init();
$_REQUEST['username'] = $_REQUEST['admin']['username'];
$_REQUEST['username'] = $_REQUEST['admin']['username'];
$_REQUEST['password'] = $_REQUEST['admin']['password'];
$dbAdmin->doBuild(true);
@ -671,15 +697,11 @@ PHP
$_SESSION['username'] = $_REQUEST['admin']['username'];
$_SESSION['password'] = $_REQUEST['admin']['password'];
if($this->checkModRewrite()) {
if($this->errors) {
} else {
echo "<p>Installed SilverStripe successfully. I will now try and direct you to
<a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a> to confirm that the installation was successful.</p>
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
@ -728,6 +750,7 @@ PHP
function createFile($filename, $content) {
$base = $this->getBaseDir();
echo "<li>Creating $base$filename\n";
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
return true;
@ -738,13 +761,14 @@ PHP
function createHtaccess() {
$start = "### SILVERSTRIPE START ###\n";
$end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
$end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
else $baseClause = "";
$rewrite = <<<TEXT
RewriteEngine On
RewriteBase $base
$baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
@ -771,24 +795,23 @@ TEXT
function createHtaccessAlternative() {
$start = "### SILVERSTRIPE START ###\n";
$end= "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
$end= "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
$rewrite = <<<TEXT
RewriteEngine On
RewriteBase $base
$baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT
;
TEXT;
if(file_exists('.htaccess')) {
$htaccess = file_get_contents('.htaccess');
if(file_exists($this->getBaseDir() . '.htaccess')) {
$htaccess = file_get_contents($this->getBaseDir() . '.htaccess');
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
@ -800,6 +823,8 @@ TEXT
}
}
echo "\n\nRewrite is $rewrite\n";
$this->createFile('.htaccess', $start . $rewrite . $end);
}
@ -844,6 +869,11 @@ TEXT
}
function performModRewriteTest() {
if(!$_SERVER['HTTP_HOST']) {
echo "<li>Installer seems to be called from command-line, we're going to assume that rewriting is working.\n";
return true;
}
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
if($baseURL == "/") {
$baseURL = "";
@ -851,6 +881,7 @@ TEXT
// Check if mod_rewrite works properly
$location = 'http://' . (isset($_SERVER['PHP_AUTH_USER']) ? "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@" : '') . $_SERVER['HTTP_HOST'] . $baseURL . '/InstallerTest/testRewrite';
echo $location;
@$testrewriting = file_get_contents($location);
if($testrewriting == 'OK') {
@ -860,8 +891,8 @@ TEXT
// Workaround for 'URL file-access is disabled in the server configuration' using curl
if(function_exists('curl_init')) {
$ch = curl_init($location);
$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
if($fp) {
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
@ -872,22 +903,22 @@ TEXT
unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
if($testrewriting == 'OK') {
return true;
}
}
}
}
return false;
}
function var_export_array_nokeys($array) {
$retval = "array(\n";
foreach($array as $item) {
$retval .= "\t'";
$retval .= trim($item);
$retval .= "',\n";
}
$retval .= ")";
return $retval;
function var_export_array_nokeys($array) {
$retval = "array(\n";
foreach($array as $item) {
$retval .= "\t'";
$retval .= trim($item);
$retval .= "',\n";
}
$retval .= ")";
return $retval;
}
}