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); 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 // Load database config
if(isset($_REQUEST['mysql'])) { if(isset($_REQUEST['mysql'])) {
$databaseConfig = $_REQUEST['mysql']; $databaseConfig = $_REQUEST['mysql'];
} else { } else {
$databaseConfig = array( $databaseConfig = array(
"server" => "localhost", "type" => "MySQLDatabase",
"username" => "root", "server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
"password" => "", "username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root",
"database" => "SS_mysite", "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')); $alreadyInstalled = (file_exists('mysite/_config.php') || file_exists('tutorial/_config.php'));
@ -60,14 +70,20 @@ if($databaseConfig) {
} }
// Actual processor // 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 // Confirm before reinstalling
if(!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) { if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) {
include('config-form.html'); include('config-form.html');
} else { } else {
$inst = new Installer(); $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 // Show the config form
@ -129,23 +145,23 @@ class InstallRequirements {
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null)); $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'])); $this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if($webserver == '') { if(function_exists('apache_get_modules')) {
$webserver = "I can't tell what webserver you are running"; $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 // Check for GD support
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) { 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.")); $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) { function requireMemory($min, $recommended, $testDetails) {
$_SESSION['forcemem'] = false; $_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); $this->testing($testDetails);
if($mem < $min && $mem > 0) { if($mem < $min && $mem > 0) {
@ -273,17 +289,17 @@ class InstallRequirements {
function requirePHPVersion($recommendedVersion, $requiredVersion, $testDetails) { function requirePHPVersion($recommendedVersion, $requiredVersion, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
list($recA, $recB, $recC) = explode('.', $recommendedVersion); list($recA, $recB, $recC) = explode('.', $recommendedVersion);
list($reqA, $reqB, $reqC) = explode('.', $requiredVersion); list($reqA, $reqB, $reqC) = explode('.', $requiredVersion);
list($a, $b, $c) = explode('.', phpversion()); list($a, $b, $c) = explode('.', phpversion());
$c = ereg_replace('-.*$','',$c); $c = ereg_replace('-.*$','',$c);
if($a > $recA || ($a == $recA && $b > $recB) || ($a == $reqA && $b == $reqB && $c >= $reqC)) { 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."; $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); $this->warning($testDetails);
return; return;
} }
if($a > $reqA) return true; if($a > $reqA) return true;
if($a == $reqA && $b > $reqB) return true; if($a == $reqA && $b > $reqB) return true;
@ -292,7 +308,7 @@ class InstallRequirements {
if(!$testDetails[2]) { if(!$testDetails[2]) {
if($a < $reqA) { 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."; $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."; $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) { function requireWriteable($filename, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$filename = $this->getBaseDir() . $filename; $filename = $this->getBaseDir() . $filename;
if(function_exists('posix_getgroups')) { if(function_exists('posix_getgroups')) {
if(!is_writeable($filename)) { if(!is_writeable($filename)) {
$user = posix_getpwuid(posix_geteuid()); $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"; $testDetails[2] .= "User '$user[name]' needs to write be able to write to this file:\n$filename";
$this->error($testDetails); $this->error($testDetails);
} }
} else { } else {
$testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable."; $testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable.";
$this->warning($testDetails); $this->warning($testDetails);
} }
} }
function requireTempFolder($testDetails) { function requireTempFolder($testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(function_exists('sys_get_temp_dir')) { if(function_exists('sys_get_temp_dir')) {
$sysTmp = sys_get_temp_dir(); $sysTmp = sys_get_temp_dir();
} elseif(isset($_ENV['TMP'])) { } elseif(isset($_ENV['TMP'])) {
$sysTmp = $_ENV['TMP']; $sysTmp = $_ENV['TMP'];
} else { } else {
@$tmpFile = tempnam('adfadsfdas',''); @$tmpFile = tempnam('adfadsfdas','');
@unlink($tmpFile); @unlink($tmpFile);
$sysTmp = dirname($tmpFile); $sysTmp = dirname($tmpFile);
} }
$worked = true; $worked = true;
$ssTmp = "$sysTmp/silverstripe-cache"; $ssTmp = "$sysTmp/silverstripe-cache";
if(!@file_exists($ssTmp)) { if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp); @$worked = mkdir($ssTmp);
if(!$worked) { if(!$worked) {
$ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache"; $ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache";
$worked = true; $worked = true;
if(!@file_exists($ssTmp)) { if(!@file_exists($ssTmp)) {
@$worked = mkdir($ssTmp); @$worked = mkdir($ssTmp);
} }
if(!$worked) { if(!$worked) {
$testDetails[2] = "Permission problem gaining access to a temp folder. " . $testDetails[2] = "Permission problem gaining access to a temp folder. " .
"Please create a folder named silverstripe-cache in the base folder " . "Please create a folder named silverstripe-cache in the base folder " .
"of the installation and ensure it has the adequate permissions"; "of the installation and ensure it has the adequate permissions";
$this->error($testDetails); $this->error($testDetails);
} }
} }
} }
} }
function requireApacheModule($moduleName, $testDetails) { function requireApacheModule($moduleName, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
@ -490,8 +506,12 @@ class InstallRequirements {
} }
protected $baseDir;
function getBaseDir() { 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) { function testing($testDetails) {
@ -533,39 +553,44 @@ class InstallRequirements {
} }
class Installer extends InstallRequirements { class Installer extends InstallRequirements {
function __construct() {
// Cache the baseDir value
$this->getBaseDir();
}
function install($config) { function install($config) {
?> ?>
<h1>Installing SilverStripe...</h1> <h1>Installing SilverStripe...</h1>
<p>I am now running through the installation steps (this should take about 30 seconds)</p> <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 <p>If you receive a fatal error, refresh this page to continue the installation
<?php <?php
flush(); flush();
if(isset($_POST['stats'])) { if(isset($_POST['stats'])) {
if(file_exists('sapphire/silverstripe_version')) { if(file_exists('sapphire/silverstripe_version')) {
$sapphireVersionFile = file_get_contents('sapphire/silverstripe_version'); $sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
if(strstr($sapphireVersionFile, "/sapphire/trunk")) { if(strstr($sapphireVersionFile, "/sapphire/trunk")) {
$silverstripe_version = "trunk"; $silverstripe_version = "trunk";
} else { } else {
preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches); preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches);
$silverstripe_version = $matches[1]; $silverstripe_version = $matches[1];
} }
} else { } else {
$silverstripe_version = "unknown"; $silverstripe_version = "unknown";
} }
$phpVersion = urlencode(phpversion()); $phpVersion = urlencode(phpversion());
$conn = @mysql_connect($config['mysql']['server'], null, null); $conn = @mysql_connect($config['mysql']['server'], null, null);
$databaseVersion = urlencode('MySQL ' . mysql_get_server_info()); $databaseVersion = urlencode('MySQL ' . mysql_get_server_info());
$webserver = urlencode($_SERVER['SERVER_SOFTWARE']); $webserver = urlencode($_SERVER['SERVER_SOFTWARE']);
$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver"; $url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver";
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) { if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url .= '&ID=' . $_SESSION['StatsID']; $url .= '&ID=' . $_SESSION['StatsID'];
} }
@$_SESSION['StatsID'] = file_get_contents($url); @$_SESSION['StatsID'] = file_get_contents($url);
} }
// Delete old _config.php files // Delete old _config.php files
@ -579,26 +604,26 @@ class Installer extends InstallRequirements {
// Write the config file // Write the config file
$template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite'; $template = $_POST['template'] == 'tutorial' ? 'tutorial' : 'mysite';
$theme = ''; $theme = '';
if($_POST['template'] == 'default') { if($_POST['template'] != 'tutorial') {
$theme = <<<PHP $theme = <<<PHP
// This line set's the current theme. More themes can be // This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/cms-themes-and-skin // downloaded from http://www.silverstripe.com/cms-themes-and-skin
SSViewer::set_theme('blackcandy'); SSViewer::set_theme('blackcandy');
PHP; PHP;
} }
echo "<li>Creating '$template/_config.php'...</li>"; echo "<li>Creating '$template/_config.php'...</li>";
flush(); flush();
$devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites'])); $devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites']));
$escapedPassword = addslashes($config['mysql']['password']); $escapedPassword = addslashes($config['mysql']['password']);
$this->createFile("$template/_config.php", <<<PHP $this->createFile("$template/_config.php", <<<PHP
<?php <?php
$mem $mem
global \$project; global \$project;
@ -613,13 +638,13 @@ global \$databaseConfig;
"database" => "{$config['mysql']['database']}", "database" => "{$config['mysql']['database']}",
); );
// Sites running on the following servers will be // Sites running on the following servers will be
// run in development mode. See // run in development mode. See
// http://doc.silverstripe.com/doku.php?id=devmode // http://doc.silverstripe.com/doku.php?id=devmode
// for a description of what dev mode does. // for a description of what dev mode does.
Director::set_dev_servers($devServers); Director::set_dev_servers($devServers);
$theme $theme
?> ?>
PHP PHP
@ -631,31 +656,32 @@ PHP
$this->createHtaccess(); $this->createHtaccess();
// Load the sapphire runtime // 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'); chdir('sapphire');
require_once('core/Core.php'); require_once('core/Core.php');
require_once('core/ManifestBuilder.php'); require_once('core/ManifestBuilder.php');
require_once('core/ClassInfo.php'); require_once('core/ClassInfo.php');
require_once('core/Object.php'); require_once('core/Object.php');
require_once('core/control/Director.php'); require_once('core/control/Director.php');
require_once('core/ViewableData.php'); require_once('core/ViewableData.php');
require_once('core/Session.php'); require_once('core/Session.php');
require_once('core/control/Controller.php'); require_once('core/control/Controller.php');
require_once('filesystem/Filesystem.php'); require_once('filesystem/Filesystem.php');
echo "<li>Building database schema...</li>"; echo "<li>Building database schema...</li>";
flush(); flush();
// Build database // Build database
$_GET['flush'] = true; $_GET['flush'] = true;
$con = new Controller(); $con = new Controller();
$con->pushCurrent(); $con->pushCurrent();
ManifestBuilder::compileManifest(); ManifestBuilder::compileManifest();
require(MANIFEST_FILE);
$dbAdmin = new DatabaseAdmin(); $dbAdmin = new DatabaseAdmin();
$dbAdmin->init(); $dbAdmin->init();
$_REQUEST['username'] = $_REQUEST['admin']['username']; $_REQUEST['username'] = $_REQUEST['admin']['username'];
$_REQUEST['password'] = $_REQUEST['admin']['password']; $_REQUEST['password'] = $_REQUEST['admin']['password'];
$dbAdmin->doBuild(true); $dbAdmin->doBuild(true);
@ -671,15 +697,11 @@ PHP
$_SESSION['username'] = $_REQUEST['admin']['username']; $_SESSION['username'] = $_REQUEST['admin']['username'];
$_SESSION['password'] = $_REQUEST['admin']['password']; $_SESSION['password'] = $_REQUEST['admin']['password'];
if($this->checkModRewrite()) { if($this->checkModRewrite()) {
if($this->errors) { if($this->errors) {
} else { } else {
echo "<p>Installed SilverStripe successfully. I will now try and direct you to 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> <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> <script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
@ -728,6 +750,7 @@ PHP
function createFile($filename, $content) { function createFile($filename, $content) {
$base = $this->getBaseDir(); $base = $this->getBaseDir();
echo "<li>Creating $base$filename\n";
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) { if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
return true; return true;
@ -738,13 +761,14 @@ PHP
function createHtaccess() { function createHtaccess() {
$start = "### SILVERSTRIPE START ###\n"; $start = "### SILVERSTRIPE START ###\n";
$end = "\n### SILVERSTRIPE END ###"; $end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']); $base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
else $baseClause = "";
$rewrite = <<<TEXT $rewrite = <<<TEXT
RewriteEngine On RewriteEngine On
RewriteBase $base $baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$ RewriteCond %{REQUEST_URI} ^(.*)$
@ -771,24 +795,23 @@ TEXT
function createHtaccessAlternative() { function createHtaccessAlternative() {
$start = "### SILVERSTRIPE START ###\n"; $start = "### SILVERSTRIPE START ###\n";
$end= "\n### SILVERSTRIPE END ###"; $end= "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n";
$rewrite = <<<TEXT $rewrite = <<<TEXT
RewriteEngine On RewriteEngine On
RewriteBase $base $baseClause
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$ RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L] RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT TEXT;
;
if(file_exists('.htaccess')) { if(file_exists($this->getBaseDir() . '.htaccess')) {
$htaccess = file_get_contents('.htaccess'); $htaccess = file_get_contents($this->getBaseDir() . '.htaccess');
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) { if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n"; $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); $this->createFile('.htaccess', $start . $rewrite . $end);
} }
@ -844,6 +869,11 @@ TEXT
} }
function performModRewriteTest() { 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']); $baseURL = dirname($_SERVER['SCRIPT_NAME']);
if($baseURL == "/") { if($baseURL == "/") {
$baseURL = ""; $baseURL = "";
@ -851,6 +881,7 @@ TEXT
// Check if mod_rewrite works properly // 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'; $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); @$testrewriting = file_get_contents($location);
if($testrewriting == 'OK') { if($testrewriting == 'OK') {
@ -860,8 +891,8 @@ TEXT
// Workaround for 'URL file-access is disabled in the server configuration' using curl // Workaround for 'URL file-access is disabled in the server configuration' using curl
if(function_exists('curl_init')) { if(function_exists('curl_init')) {
$ch = curl_init($location); $ch = curl_init($location);
$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w"); $fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
if($fp) { if($fp) {
curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
@ -872,22 +903,22 @@ TEXT
unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest'); unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
if($testrewriting == 'OK') { if($testrewriting == 'OK') {
return true; return true;
} }
} }
} }
return false; return false;
} }
function var_export_array_nokeys($array) { function var_export_array_nokeys($array) {
$retval = "array(\n"; $retval = "array(\n";
foreach($array as $item) { foreach($array as $item) {
$retval .= "\t'"; $retval .= "\t'";
$retval .= trim($item); $retval .= trim($item);
$retval .= "',\n"; $retval .= "',\n";
} }
$retval .= ")"; $retval .= ")";
return $retval; return $retval;
} }
} }