2010-10-13 04:26:57 +02:00
< ? php
/************************************************************************************
************************************************************************************
** **
** If you can read this text in your browser then you don ' t have PHP installed . **
** Please install PHP 5.0 or higher , preferably PHP 5.2 . **
** **
************************************************************************************
************************************************************************************/
/**
* SilverStripe CMS Installer
* This installer doesn 't use any of the fancy Sapphire stuff in case it' s unsupported .
* It ' s also PHP4 syntax compatable
*/
// speed up mysql_connect timeout if the server can't be found
ini_set ( 'mysql.connect_timeout' , 5 );
ini_set ( 'max_execution_time' , 0 );
error_reporting ( E_ALL ^ E_NOTICE );
session_start ();
$majorVersion = strtok ( phpversion (), '.' );
if ( $majorVersion < 5 ) {
header ( " HTTP/1.1 500 Server Error " );
echo str_replace ( '$PHPVersion' , phpversion (), file_get_contents ( " sapphire/dev/install/php5-required.html " ));
die ();
}
// Include environment files
$usingEnv = false ;
2010-10-13 04:42:08 +02:00
$envFileExists = false ;
2010-10-13 04:26:57 +02:00
$envFiles = array ( '_ss_environment.php' , '../_ss_environment.php' , '../../_ss_environment.php' );
foreach ( $envFiles as $envFile ) {
2010-10-13 04:42:08 +02:00
if ( @ file_exists ( $envFile )) {
include_once ( $envFile );
$envFileExists = true ;
$usingEnv = true ;
break ;
}
2010-10-13 04:26:57 +02:00
}
2010-10-13 04:42:08 +02:00
if ( $envFileExists ) {
if ( ! empty ( $_REQUEST [ 'useEnv' ])) {
$usingEnv = true ;
} else {
$usingEnv = false ;
}
}
2010-10-13 04:26:57 +02:00
2010-10-13 06:24:26 +02:00
include_once ( 'sapphire/core/Object.php' );
2011-04-06 03:22:34 +02:00
include_once ( 'sapphire/i18n/i18n.php' );
2010-10-13 04:47:16 +02:00
include_once ( 'sapphire/dev/install/DatabaseConfigurationHelper.php' );
2010-10-13 06:24:00 +02:00
include_once ( 'sapphire/dev/install/DatabaseAdapterRegistry.php' );
2010-10-13 06:24:26 +02:00
// Set default locale, but try and sniff from the user agent
$locales = i18n :: $common_locales ;
2010-10-13 06:25:07 +02:00
$defaultLocale = i18n :: get_locale ();
if ( isset ( $_SERVER [ 'HTTP_USER_AGENT' ])) {
2010-10-13 06:24:26 +02:00
foreach ( $locales as $code => $details ) {
$bits = explode ( '_' , $code );
2010-10-13 06:25:07 +02:00
if ( preg_match ( " / { $bits [ 0 ] } . { $bits [ 1 ] } / " , $_SERVER [ 'HTTP_USER_AGENT' ])) {
2010-10-13 06:24:26 +02:00
$defaultLocale = $code ;
break ;
}
}
}
2010-10-13 06:25:36 +02:00
// Discover which databases are available
2010-10-13 06:24:00 +02:00
DatabaseAdapterRegistry :: autodiscover ();
// Determine which external database modules are USABLE
2010-10-13 06:25:30 +02:00
foreach ( DatabaseAdapterRegistry :: get_adapters () as $class => $details ) {
2010-10-13 06:24:00 +02:00
$databaseClasses [ $class ] = $details ;
if ( file_exists ( $details [ 'helperPath' ])) {
$databaseClasses [ $class ][ 'hasModule' ] = true ;
include_once ( $details [ 'helperPath' ]);
} else {
$databaseClasses [ $class ][ 'hasModule' ] = false ;
2010-10-13 04:47:16 +02:00
}
}
2010-10-13 04:26:57 +02:00
// Load database config
2010-10-13 04:42:08 +02:00
if ( isset ( $_REQUEST [ 'db' ])) {
2010-10-13 06:28:30 +02:00
if ( isset ( $_REQUEST [ 'db' ][ 'type' ])) $type = $_REQUEST [ 'db' ][ 'type' ];
else $type = $_REQUEST [ 'db' ][ 'type' ] = defined ( 'SS_DATABASE_CLASS' ) ? SS_DATABASE_CLASS : 'MySQLDatabase' ;
2010-10-13 04:42:08 +02:00
// Disabled inputs don't submit anything - we need to use the environment (except the database name)
if ( $usingEnv ) {
2010-10-13 06:26:06 +02:00
$_REQUEST [ 'db' ][ $type ] = $databaseConfig = array (
" type " => defined ( 'SS_DATABASE_CLASS' ) ? SS_DATABASE_CLASS : $type ,
2010-10-13 04:42:08 +02:00
" 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 : " " ,
2010-10-13 06:26:06 +02:00
" database " => $_REQUEST [ 'db' ][ $type ][ 'database' ],
2010-10-13 04:42:08 +02:00
);
2010-10-13 06:28:30 +02:00
2010-10-13 04:42:08 +02:00
} else {
// Normal behaviour without the environment
2010-10-13 06:26:06 +02:00
$databaseConfig = $_REQUEST [ 'db' ][ $type ];
$databaseConfig [ 'type' ] = $type ;
2010-10-13 04:42:08 +02:00
}
2010-10-13 04:26:57 +02:00
} else {
2010-10-15 03:16:43 +02:00
$type = $_REQUEST [ 'db' ][ 'type' ] = defined ( 'SS_DATABASE_CLASS' ) ? SS_DATABASE_CLASS : 'MySQLDatabase' ;
2010-10-13 06:26:06 +02:00
$_REQUEST [ 'db' ][ $type ] = $databaseConfig = array (
2010-10-15 03:16:43 +02:00
" type " => $type ,
2010-10-13 04:26:57 +02:00
" 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' ])) {
2010-10-13 04:42:08 +02:00
// Disabled inputs don't submit anything - we need to use the environment (except the database name)
if ( $usingEnv ) {
$_REQUEST [ 'admin' ] = $adminConfig = array (
'username' => defined ( 'SS_DEFAULT_ADMIN_USERNAME' ) ? SS_DEFAULT_ADMIN_USERNAME : 'admin' ,
2010-10-13 06:21:56 +02:00
'password' => defined ( 'SS_DEFAULT_ADMIN_PASSWORD' ) ? SS_DEFAULT_ADMIN_PASSWORD : '' ,
2010-10-13 04:42:08 +02:00
);
} else {
$adminConfig = $_REQUEST [ 'admin' ];
}
2010-10-13 04:26:57 +02:00
} else {
$_REQUEST [ 'admin' ] = $adminConfig = array (
2010-10-13 04:42:08 +02:00
'username' => defined ( 'SS_DEFAULT_ADMIN_USERNAME' ) ? SS_DEFAULT_ADMIN_USERNAME : 'admin' ,
2010-10-13 06:21:56 +02:00
'password' => defined ( 'SS_DEFAULT_ADMIN_PASSWORD' ) ? SS_DEFAULT_ADMIN_PASSWORD : '' ,
2010-10-13 04:26:57 +02:00
);
}
$alreadyInstalled = false ;
if ( file_exists ( 'mysite/_config.php' )) {
// Find the $database variable in the relevant config file without having to execute the config file
if ( preg_match ( " / \\ \$ database \ s*= \ s*[^ \n \r ]+[ \n \r ]/ " , file_get_contents ( " mysite/_config.php " ), $parts )) {
eval ( $parts [ 0 ]);
if ( $database ) $alreadyInstalled = true ;
// Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has
// already gone ahead
} else if ( preg_match ( " / \\ \$ databaseConfig \ s*= \ s*[^ \n \r ]+[ \n \r ]/ " , file_get_contents ( " mysite/_config.php " ), $parts )) {
$alreadyInstalled = true ;
}
}
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 " ;
}
// Check requirements
$req = new InstallRequirements ();
$req -> check ();
2010-10-15 03:14:53 +02:00
$webserverConfigFile = '' ;
if ( $req -> isIIS ()) {
$webserverConfigFile = 'web.config' ;
} else {
$webserverConfigFile = '.htaccess' ;
}
2010-10-13 04:26:57 +02:00
if ( $req -> hasErrors ()) {
$hasErrorOtherThanDatabase = true ;
}
if ( $databaseConfig ) {
$dbReq = new InstallRequirements ();
2010-10-15 03:14:28 +02:00
$dbReq -> checkDatabase ( $databaseConfig );
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:21:56 +02:00
if ( $adminConfig ) {
$adminReq = new InstallRequirements ();
$adminReq -> checkAdminConfig ( $adminConfig );
}
2010-10-13 04:26:57 +02:00
// Actual processor
$installFromCli = ( isset ( $_SERVER [ 'argv' ][ 1 ]) && $_SERVER [ 'argv' ][ 1 ] == 'install' );
// CLI-install error message. exit(1) will halt any makefile.
if ( $installFromCli && ( $req -> hasErrors () || $dbReq -> hasErrors ())) {
echo " Cannot install due to errors: \n " ;
$req -> listErrors ();
$dbReq -> listErrors ();
exit ( 1 );
}
if (( isset ( $_REQUEST [ 'go' ]) || $installFromCli ) && ! $req -> hasErrors () && ! $dbReq -> hasErrors () && $adminConfig [ 'username' ] && $adminConfig [ 'password' ]) {
// Confirm before reinstalling
2010-10-15 03:16:31 +02:00
if ( ! $installFromCli && $alreadyInstalled ) {
2010-10-13 04:26:57 +02:00
include ( 'sapphire/dev/install/config-form.html' );
} else {
$inst = new Installer ();
if ( $_REQUEST ) $inst -> install ( $_REQUEST );
else $inst -> install ( array (
2010-10-13 04:42:08 +02:00
'db' => $databaseConfig ,
2010-10-13 04:26:57 +02:00
'admin' => $adminConfig ,
));
}
// Show the config form
} else {
include ( 'sapphire/dev/install/config-form.html' );
}
/**
* This class checks requirements
2010-10-13 06:22:35 +02:00
* Each of the requireXXX functions takes an argument which gives a user description of the test .
* It ' s an array of 3 parts :
2010-10-13 04:26:57 +02:00
* $description [ 0 ] - The test catetgory
* $description [ 1 ] - The test title
* $description [ 2 ] - The test error to show , if it goes wrong
*/
class InstallRequirements {
2010-10-13 04:47:16 +02:00
var $errors , $warnings , $tests ;
2010-10-13 04:26:57 +02:00
/**
2010-10-13 04:51:12 +02:00
* Check the database configuration . These are done one after another
* starting with checking the database function exists in PHP , and
* continuing onto more difficult checks like database permissions .
2010-10-13 04:26:57 +02:00
*/
2010-10-15 03:14:28 +02:00
function checkDatabase ( $databaseConfig ) {
2010-10-13 04:47:16 +02:00
if ( $this -> requireDatabaseFunctions (
2010-10-13 04:42:08 +02:00
$databaseConfig ,
2010-10-13 04:26:57 +02:00
array (
2010-10-13 04:42:08 +02:00
" Database Configuration " ,
" Database support " ,
2010-10-15 03:22:10 +02:00
" Database support in PHP " ,
$this -> getDatabaseTypeNice ( $databaseConfig [ 'type' ])
2010-10-13 04:26:57 +02:00
)
2010-10-15 03:22:04 +02:00
)) {
2010-10-13 04:42:08 +02:00
if ( $this -> requireDatabaseServer (
$databaseConfig ,
2010-10-13 04:26:57 +02:00
array (
2010-10-13 04:42:08 +02:00
" Database Configuration " ,
2010-10-15 03:16:09 +02:00
" Database server " ,
2010-10-15 03:18:52 +02:00
$databaseConfig [ 'type' ] == 'SQLiteDatabase' ? " I couldn't write to path ' $databaseConfig[path] ' " : " I couldn't find a database server on ' $databaseConfig[server] ' " ,
$databaseConfig [ 'type' ] == 'SQLiteDatabase' ? $databaseConfig [ 'path' ] : $databaseConfig [ 'server' ]
2010-10-13 04:26:57 +02:00
)
)) {
2010-10-15 03:14:48 +02:00
if ( $this -> requireDatabaseConnection (
2010-10-13 04:42:08 +02:00
$databaseConfig ,
2010-10-13 04:26:57 +02:00
array (
2010-10-15 03:14:44 +02:00
" Database Configuration " ,
2010-10-15 03:14:48 +02:00
" Database access credentials correct " ,
" That username/password doesn't work "
2010-10-13 04:26:57 +02:00
)
)) {
2010-10-15 03:14:48 +02:00
if ( $this -> requireDatabaseVersion (
2010-10-13 04:51:12 +02:00
$databaseConfig ,
2010-10-13 04:26:57 +02:00
array (
2010-10-13 04:51:12 +02:00
" Database Configuration " ,
2010-10-15 03:14:48 +02:00
" Database server meets required version " ,
2010-10-15 03:22:04 +02:00
'' ,
2010-10-15 03:22:10 +02:00
'Version ' . $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]) -> getDatabaseVersion ( $databaseConfig )
2010-10-13 04:26:57 +02:00
)
2010-10-15 03:13:50 +02:00
)) {
$this -> requireDatabaseOrCreatePermissions (
$databaseConfig ,
array (
" Database Configuration " ,
" Can I access/create the database " ,
" I can't create new databases and the database ' $databaseConfig[database] ' doesn't exist "
)
);
}
2010-10-13 04:26:57 +02:00
}
}
}
}
2010-10-13 06:21:56 +02:00
function checkAdminConfig ( $adminConfig ) {
if ( ! $adminConfig [ 'username' ]) {
$this -> error ( array ( '' , 'Please enter a username!' ));
}
if ( ! $adminConfig [ 'password' ]) {
$this -> error ( array ( '' , 'Please enter a password!' ));
}
}
2010-10-13 06:22:35 +02:00
/**
* Check if the web server is IIS .
* @ return boolean
*/
2010-10-15 03:18:00 +02:00
function isIIS ( $version = 7 ) {
if ( strpos ( $this -> findWebserver (), 'IIS/' . $version ) !== false ) {
2010-10-15 03:17:42 +02:00
return true ;
} else {
return false ;
2010-10-13 06:22:35 +02:00
}
}
2010-10-15 03:17:42 +02:00
2010-10-13 06:22:35 +02:00
function isApache () {
2010-10-15 03:17:42 +02:00
if ( strpos ( $this -> findWebserver (), 'Apache' ) !== false ) {
2010-10-13 06:28:14 +02:00
return true ;
} else {
return false ;
2010-10-13 06:22:35 +02:00
}
}
2010-10-15 03:17:42 +02:00
/**
* Find the webserver software running on the PHP host .
2010-10-15 03:17:53 +02:00
* @ return string | boolean Server software or boolean FALSE
2010-10-15 03:17:42 +02:00
*/
2010-10-13 06:22:35 +02:00
function findWebserver () {
2010-10-15 03:17:42 +02:00
// Try finding from SERVER_SIGNATURE or SERVER_SOFTWARE
$webserver = @ $_SERVER [ 'SERVER_SIGNATURE' ];
if ( ! $webserver ) $webserver = @ $_SERVER [ 'SERVER_SOFTWARE' ];
2010-10-15 03:17:53 +02:00
if ( $webserver ) return strip_tags ( trim ( $webserver ));
else return false ;
2010-10-13 06:22:35 +02:00
}
2010-10-13 06:21:56 +02:00
2010-10-13 04:26:57 +02:00
/**
* Check everything except the database
*/
function check () {
$this -> errors = null ;
2010-10-13 06:22:35 +02:00
$isApache = $this -> isApache ();
2010-10-15 03:18:00 +02:00
$isIIS = $this -> isIIS ( 7 );
2010-10-13 06:22:35 +02:00
$webserver = $this -> findWebserver ();
2010-10-13 04:26:57 +02:00
2010-10-13 06:23:49 +02:00
$this -> requirePHPVersion ( '5.2.0' , '5.1.0' , array ( " PHP Configuration " , " PHP5 installed " , null , " PHP version " . phpversion ()));
2010-10-13 04:26:57 +02:00
// Check that we can identify the root folder successfully
$this -> requireFile ( 'sapphire/dev/install/config-form.html' , array ( " File permissions " ,
" Does the webserver know where files are stored? " ,
" The webserver isn't letting me identify where files are stored. " ,
$this -> getBaseDir ()
2010-10-13 06:22:35 +02:00
));
2010-11-22 00:53:50 +01:00
$this -> requireModule ( 'mysite' , array ( " File permissions " , " mysite/ directory exists? " ));
$this -> requireModule ( 'sapphire' , array ( " File permissions " , " sapphire/ directory exists? " ));
$this -> requireModule ( 'cms' , array ( " File permissions " , " cms/ directory exists? " ));
2010-10-13 06:22:35 +02:00
if ( $isApache ) {
$this -> requireWriteable ( '.htaccess' , array ( " File permissions " , " Is the .htaccess file writeable? " , null ));
} elseif ( $isIIS ) {
$this -> requireWriteable ( 'web.config' , array ( " File permissions " , " Is the web.config file writeable? " , null ));
}
2010-10-13 04:26:57 +02:00
$this -> requireWriteable ( 'mysite/_config.php' , array ( " File permissions " , " Is the mysite/_config.php file writeable? " , null ));
2010-11-22 00:53:50 +01:00
$this -> requireWriteable ( 'assets' , array ( " File permissions " , " Is the assets/ directory writeable? " , null ));
2010-10-13 04:26:57 +02:00
2010-11-22 00:53:50 +01:00
$tempFolder = $this -> getTempFolder ();
$this -> requireTempFolder ( array ( 'File permissions' , 'Is a temporary directory available?' , null , $tempFolder ));
if ( $tempFolder ) {
// in addition to the temp folder being available, check it is writable
$this -> requireWriteable ( $tempFolder , array ( " File permissions " , sprintf ( " Is the temporary directory writeable? " , $tempFolder ), null ), true );
}
2010-10-13 04:26:57 +02:00
// Check for web server, unless we're calling the installer from the command-line
2010-10-13 06:22:35 +02:00
if ( ! isset ( $_SERVER [ 'argv' ]) || ! $_SERVER [ 'argv' ]) {
2010-10-15 03:18:39 +02:00
$this -> isRunningWebServer ( array ( " Webserver Configuration " , " Server software " , " Unknown " , $webserver ));
2010-10-13 06:22:35 +02:00
if ( $isApache ) {
2010-10-13 06:26:57 +02:00
$this -> requireApacheRewriteModule ( 'mod_rewrite' , array ( " Webserver Configuration " , " URL rewriting support " , " You need mod_rewrite to use friendly URLs with SilverStripe, but it is not enabled. " ));
2010-10-13 06:22:35 +02:00
} elseif ( $isIIS ) {
2010-10-13 06:26:57 +02:00
$this -> requireIISRewriteModule ( 'IIS_UrlRewriteModule' , array ( " Webserver Configuration " , " URL rewriting support " , " You need to enable the IIS URL Rewrite Module to use friendly URLs with SilverStripe, but it is not installed or enabled. Download it for IIS 7 from http://www.iis.net/expand/URLRewrite " ));
2010-10-13 04:26:57 +02:00
} else {
2010-10-13 06:26:57 +02:00
$this -> warning ( array ( " Webserver Configuration " , " URL rewriting support " , " I can't tell whether any rewriting module is running. You may need to configure a rewriting rule yourself. " ));
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:22:35 +02:00
2010-10-13 04:26:57 +02:00
$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 " , " GD support for PHP not included. " ));
}
// Check for XML support
$this -> requireFunction ( 'xml_set_object' , array ( " PHP Configuration " , " XML support " , " XML support not included in PHP. " ));
2010-10-13 06:28:45 +02:00
$this -> requireClass ( 'DOMDocument' , array ( " PHP Configuration " , " DOM/XML support " , " DOM/XML support not included in PHP. " ));
2010-10-13 04:26:57 +02:00
// Check for token_get_all
$this -> requireFunction ( 'token_get_all' , array ( " PHP Configuration " , " PHP Tokenizer " , " PHP tokenizer support not included in PHP. " ));
2010-10-15 03:21:45 +02:00
// Check for session support
$this -> requireFunction ( 'session_start' , array ( 'PHP Configuration' , 'Session support' , 'Session support not included in PHP.' ));
2010-10-15 03:21:21 +02:00
// Check for iconv support
$this -> requireFunction ( 'iconv' , array ( 'PHP Configuration' , 'iconv support' , 'iconv support not included in PHP.' ));
2010-10-13 04:26:57 +02:00
2010-10-15 03:21:45 +02:00
// Check for hash support
$this -> requireFunction ( 'hash' , array ( 'PHP Configuration' , 'hash support' , 'hash support not included in PHP.' ));
2010-12-05 01:04:05 +01:00
if ( version_compare ( PHP_VERSION , '5.3.0' , '>=' )) {
$this -> requireDateTimezone ( array ( 'PHP Configuration' , 'date.timezone set and valid' , 'date.timezone option in php.ini must be set in PHP 5.3.0+' , ini_get ( 'date.timezone' )));
}
2010-12-11 07:02:51 +01:00
$this -> suggestPHPSetting ( 'asp_tags' , array ( '' ), array ( 'PHP Configuration' , 'asp_tags option turned off' , 'This should be turned off as it can cause issues with SilverStripe' ));
2010-12-21 10:28:28 +01:00
$this -> suggestPHPSetting ( 'magic_quotes_gpc' , array ( '' ), array ( 'PHP Configuration' , 'magic_quotes_gpc option turned off' , 'This should be turned off, as it can cause issues with cookies. More specifically, unserializing data stored in cookies.' ));
2010-12-11 07:02:51 +01:00
2010-10-13 04:26:57 +02:00
// Check memory allocation
$this -> requireMemory ( 32 * 1024 * 1024 , 64 * 1024 * 1024 , array ( " PHP Configuration " , " Memory allocated (PHP config option 'memory_limit') " , " SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M. " , ini_get ( " memory_limit " )));
return $this -> errors ;
}
function suggestPHPSetting ( $settingName , $settingValues , $testDetails ) {
$this -> testing ( $testDetails );
$val = ini_get ( $settingName );
if ( ! in_array ( $val , $settingValues ) && $val != $settingValues ) {
$testDetails [ 2 ] = " $settingName is set to ' $val ' in php.ini. $testDetails[2] " ;
$this -> warning ( $testDetails );
}
}
2010-12-05 01:04:05 +01:00
function requireDateTimezone ( $testDetails ) {
$this -> testing ( $testDetails );
$result = ini_get ( 'date.timezone' ) && in_array ( ini_get ( 'date.timezone' ), timezone_identifiers_list ());
if ( ! $result ) {
$this -> error ( $testDetails );
}
}
2010-10-13 04:26:57 +02:00
function requireMemory ( $min , $recommended , $testDetails ) {
$_SESSION [ 'forcemem' ] = false ;
$mem = $this -> getPHPMemory ();
if ( $mem < ( 64 * 1024 * 1024 )) {
ini_set ( 'memory_limit' , '64M' );
$mem = $this -> getPHPMemory ();
$testDetails [ 3 ] = ini_get ( " memory_limit " );
}
$this -> testing ( $testDetails );
if ( $mem < $min && $mem > 0 ) {
$testDetails [ 2 ] .= " You only have " . ini_get ( " memory_limit " ) . " allocated " ;
$this -> error ( $testDetails );
} else if ( $mem < $recommended && $mem > 0 ) {
$testDetails [ 2 ] .= " You only have " . ini_get ( " memory_limit " ) . " allocated " ;
$this -> warning ( $testDetails );
} elseif ( $mem == 0 ) {
$testDetails [ 2 ] .= " We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least 20 MB. " ;
$this -> warning ( $testDetails );
}
}
function getPHPMemory () {
$memString = ini_get ( " memory_limit " );
switch ( strtolower ( substr ( $memString , - 1 ))) {
case " k " :
return round ( substr ( $memString , 0 , - 1 ) * 1024 );
case " m " :
return round ( substr ( $memString , 0 , - 1 ) * 1024 * 1024 );
case " g " :
return round ( substr ( $memString , 0 , - 1 ) * 1024 * 1024 * 1024 );
default :
return round ( $memString );
}
}
function listErrors () {
if ( $this -> errors ) {
echo " <p>The following problems are preventing me from installing SilverStripe CMS:</p> \n \n " ;
foreach ( $this -> errors as $error ) {
echo " <li> " . htmlentities ( implode ( " , " , $error )) . " </li> \n " ;
}
}
}
function showTable ( $section = null ) {
if ( $section ) {
$tests = $this -> tests [ $section ];
2010-10-13 04:42:08 +02:00
$id = strtolower ( str_replace ( ' ' , '_' , $section ));
echo " <table id= \" { $id } _results \" class= \" testResults \" width= \" 100% \" > " ;
2010-10-13 04:26:57 +02:00
foreach ( $tests as $test => $result ) {
echo " <tr class= \" $result[0] \" ><td> $test </td><td> " . nl2br ( htmlentities ( $result [ 1 ])) . " </td></tr> " ;
}
echo " </table> " ;
} else {
foreach ( $this -> tests as $section => $tests ) {
2010-10-13 06:27:56 +02:00
$failedRequirements = 0 ;
$warningRequirements = 0 ;
$output = " " ;
2010-10-13 04:26:57 +02:00
foreach ( $tests as $test => $result ) {
2010-10-13 06:27:56 +02:00
if ( isset ( $result [ '0' ])) {
switch ( $result [ '0' ]) {
case 'error' :
$failedRequirements ++ ;
break ;
case 'warning' :
$warningRequirements ++ ;
break ;
}
}
$output .= " <tr class= \" $result[0] \" ><td> $test </td><td> " . nl2br ( htmlentities ( $result [ 1 ])) . " </td></tr> " ;
}
$className = " good " ;
$text = " All Requirements Pass " ;
$pluralWarnings = ( $warningRequirements == 1 ) ? 'Warning' : 'Warnings' ;
if ( $failedRequirements > 0 ) {
$className = " error " ;
$pluralWarnings = ( $warningRequirements == 1 ) ? 'Warning' : 'Warnings' ;
$text = $failedRequirements . ' Failed and ' . $warningRequirements . ' ' . $pluralWarnings ;
}
else if ( $warningRequirements > 0 ) {
$className = " warning " ;
$text = " All Requirements Pass but " . $warningRequirements . ' ' . $pluralWarnings ;
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:27:56 +02:00
2010-10-13 06:28:09 +02:00
echo " <h5 class='requirement $className '><em class='inlineBarText'> $section </em> <a href='#'>See All Requirements</a> <span> $text </span></h5> " ;
2010-10-13 06:27:56 +02:00
echo " <table class= \" testResults \" > " ;
echo $output ;
2010-10-13 04:26:57 +02:00
echo " </table> " ;
}
}
}
function requireFunction ( $funcName , $testDetails ) {
$this -> testing ( $testDetails );
if ( ! function_exists ( $funcName )) $this -> error ( $testDetails );
else return true ;
}
2010-10-13 06:28:45 +02:00
function requireClass ( $className , $testDetails ) {
$this -> testing ( $testDetails );
if ( ! class_exists ( $className )) $this -> error ( $testDetails );
else return false ;
}
2010-10-13 04:26:57 +02:00
/**
* Require that the given class doesn ' t exist
*/
function requireNoClasses ( $classNames , $testDetails ) {
$this -> testing ( $testDetails );
$badClasses = array ();
foreach ( $classNames as $className ) {
if ( class_exists ( $className )) $badClasses [] = $className ;
}
if ( $badClasses ) {
$testDetails [ 2 ] .= " . The following classes are at fault: " . implode ( ', ' , $badClasses );
$this -> error ( $testDetails );
}
else return true ;
}
function requirePHPVersion ( $recommendedVersion , $requiredVersion , $testDetails ) {
$this -> testing ( $testDetails );
$installedVersion = phpversion ();
if ( version_compare ( $installedVersion , $requiredVersion , '<' )) {
$testDetails [ 2 ] = " SilverStripe requires PHP version $requiredVersion or later. \n
PHP version $installedVersion is currently installed . \n
While SilverStripe requires at least PHP version $requiredVersion , upgrading to $recommendedVersion or later is recommended . \n
If you are installing SilverStripe on a shared web server , please ask your web hosting provider to upgrade PHP for you . " ;
$this -> error ( $testDetails );
return ;
}
if ( version_compare ( $installedVersion , $recommendedVersion , '<' )) {
$testDetails [ 2 ] = " PHP version $installedVersion is currently installed. \n
Upgrading to at least PHP version $recommendedVersion is recommended . \n
SilverStripe should run , but you may run into issues . Future releases may require a later version of PHP . \n " ;
$this -> warning ( $testDetails );
return ;
}
return true ;
}
2010-11-22 00:53:50 +01:00
/**
* The same as { @ link requireFile ()} but does additional checks
* to ensure the module directory is intact .
*/
function requireModule ( $dirname , $testDetails ) {
$this -> testing ( $testDetails );
$path = $this -> getBaseDir () . $dirname ;
if ( ! file_exists ( $path )) {
$testDetails [ 2 ] .= " Directory ' $path ' not found. Please make sure you have uploaded the SilverStripe files to your webserver correctly. " ;
$this -> error ( $testDetails );
2010-12-19 23:18:05 +01:00
} elseif ( ! file_exists ( $path . '/_config.php' ) && $dirname != 'mysite' ) {
2010-11-22 00:53:50 +01:00
$testDetails [ 2 ] .= " Directory ' $path ' exists, but is missing files. Please make sure you have uploaded the SilverStripe files to your webserver correctly. " ;
$this -> error ( $testDetails );
}
}
2010-10-13 04:26:57 +02:00
function requireFile ( $filename , $testDetails ) {
$this -> testing ( $testDetails );
$filename = $this -> getBaseDir () . $filename ;
if ( ! file_exists ( $filename )) {
$testDetails [ 2 ] .= " (file ' $filename ' not found) " ;
$this -> error ( $testDetails );
}
}
2010-11-22 00:53:50 +01:00
function requireWriteable ( $filename , $testDetails , $absolute = false ) {
2010-10-13 04:26:57 +02:00
$this -> testing ( $testDetails );
2010-11-22 00:53:50 +01:00
if ( $absolute ) {
$filename = str_replace ( '/' , DIRECTORY_SEPARATOR , $filename );
} else {
$filename = $this -> getBaseDir () . str_replace ( '/' , DIRECTORY_SEPARATOR , $filename );
}
2010-10-13 04:26:57 +02:00
2010-10-15 03:16:31 +02:00
if ( file_exists ( $filename )) $isWriteable = is_writeable ( $filename );
else $isWriteable = is_writeable ( dirname ( $filename ));
if ( ! $isWriteable ) {
2010-10-13 04:26:57 +02:00
if ( function_exists ( 'posix_getgroups' )) {
$userID = posix_geteuid ();
$user = posix_getpwuid ( $userID );
2010-10-15 03:16:31 +02:00
$currentOwnerID = fileowner ( file_exists ( $filename ) ? $filename : dirname ( $filename ) );
2010-10-13 04:26:57 +02:00
$currentOwner = posix_getpwuid ( $currentOwnerID );
$testDetails [ 2 ] .= " User ' $user[name] ' needs to be able to write to this file: \n $filename\n\nThe file is currently owned by ' $currentOwner[name] '. " ;
if ( $user [ 'name' ] == $currentOwner [ 'name' ]) {
$testDetails [ 2 ] .= " We recommend that you make the file writeable. " ;
} else {
$groups = posix_getgroups ();
2010-11-22 00:53:50 +01:00
$groupList = array ();
2010-10-13 04:26:57 +02:00
foreach ( $groups as $group ) {
$groupInfo = posix_getgrgid ( $group );
if ( in_array ( $currentOwner [ 'name' ], $groupInfo [ 'members' ])) $groupList [] = $groupInfo [ 'name' ];
}
if ( $groupList ) {
$testDetails [ 2 ] .= " We recommend that you make the file group-writeable and change the group to one of these groups: \n - " . implode ( " \n - " , $groupList )
. " \n \n For example: \n chmod g+w $filename\nchgrp " . $groupList [ 0 ] . " $filename " ;
} else {
$testDetails [ 2 ] .= " There is no user-group that contains both the web-server user and the owner of this file. Change the ownership of the file, create a new group, or temporarily make the file writeable by everyone during the install process. " ;
}
}
} else {
$testDetails [ 2 ] .= " The webserver user needs to be able to write to this file: \n $filename " ;
}
$this -> error ( $testDetails );
}
}
2010-11-22 00:53:50 +01:00
function getTempFolder () {
if ( file_exists ( $this -> getBaseDir () . 'silverstripe-cache' )) {
$sysTmp = $this -> getBaseDir ();
} elseif ( 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 . DIRECTORY_SEPARATOR . 'silverstripe-cache' ;
if ( !@ file_exists ( $ssTmp )) {
@ $worked = mkdir ( $ssTmp );
if ( ! $worked ) {
$ssTmp = dirname ( $_SERVER [ 'SCRIPT_FILENAME' ]) . DIRECTORY_SEPARATOR . 'silverstripe-cache' ;
$worked = true ;
if ( !@ file_exists ( $ssTmp )) {
@ $worked = mkdir ( $ssTmp );
}
}
}
if ( $worked ) return $ssTmp ;
else return false ;
}
2010-10-13 04:26:57 +02:00
function requireTempFolder ( $testDetails ) {
$this -> testing ( $testDetails );
2010-11-22 00:53:50 +01:00
$tempFolder = $this -> getTempFolder ();
if ( ! $tempFolder ) {
$testDetails [ 2 ] = " Permission problem gaining access to a temp directory. " .
" Please create a folder named silverstripe-cache in the base directory " .
" of the installation and ensure it has the adequate permissions " ;
$this -> error ( $testDetails );
2010-10-13 04:26:57 +02:00
}
}
function requireApacheModule ( $moduleName , $testDetails ) {
$this -> testing ( $testDetails );
2010-10-13 06:26:40 +02:00
if ( ! in_array ( $moduleName , apache_get_modules ())) {
$this -> error ( $testDetails );
return false ;
} else {
return true ;
}
}
function testApacheRewriteExists ( $moduleName = 'mod_rewrite' ) {
2010-10-13 06:27:51 +02:00
if ( function_exists ( 'apache_get_modules' ) && in_array ( $moduleName , apache_get_modules ())) {
2010-10-13 06:26:40 +02:00
return true ;
2010-11-18 06:08:12 +01:00
} elseif ( isset ( $_SERVER [ 'HTTP_MOD_REWRITE' ]) && $_SERVER [ 'HTTP_MOD_REWRITE' ] == 'On' ) {
return true ;
2010-10-13 06:26:40 +02:00
} else {
return false ;
}
}
function testIISRewriteModuleExists ( $moduleName = 'IIS_UrlRewriteModule' ) {
if ( isset ( $_SERVER [ $moduleName ]) && $_SERVER [ $moduleName ]) {
return true ;
} else {
return false ;
}
}
function requireApacheRewriteModule ( $moduleName , $testDetails ) {
$this -> testing ( $testDetails );
if ( $this -> testApacheRewriteExists ()) {
return true ;
} else {
$this -> warning ( $testDetails );
return false ;
}
}
/**
* Determines if the web server has any rewriting capability .
* @ return boolean
*/
function hasRewritingCapability () {
return ( $this -> testApacheRewriteExists () || $this -> testIISRewriteModuleExists ());
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:22:35 +02:00
2010-10-13 04:26:57 +02:00
function requireIISRewriteModule ( $moduleName , $testDetails ) {
$this -> testing ( $testDetails );
2010-10-13 06:26:40 +02:00
if ( $this -> testIISRewriteModuleExists ()) {
2010-10-13 04:26:57 +02:00
return true ;
} else {
2010-10-13 06:26:40 +02:00
$this -> warning ( $testDetails );
2010-10-13 04:26:57 +02:00
return false ;
}
}
2010-10-15 03:22:04 +02:00
function getDatabaseTypeNice ( $databaseClass ) {
return substr ( $databaseClass , 0 , - 8 );
}
2010-10-13 04:47:16 +02:00
/**
* Get an instance of a helper class for the specific database .
* @ param string $databaseClass e . g . MySQLDatabase or MSSQLDatabase
*/
function getDatabaseConfigurationHelper ( $databaseClass ) {
2010-10-13 06:25:30 +02:00
$adapters = DatabaseAdapterRegistry :: get_adapters ();
2010-10-13 06:25:12 +02:00
if ( isset ( $adapters [ $databaseClass ])) {
$helperPath = $adapters [ $databaseClass ][ 'helperPath' ];
$class = str_replace ( '.php' , '' , basename ( $helperPath ));
}
2010-10-13 06:21:40 +02:00
return ( class_exists ( $class )) ? new $class () : new MySQLDatabaseConfigurationHelper ();
2010-10-13 04:47:16 +02:00
}
function requireDatabaseFunctions ( $databaseConfig , $testDetails ) {
2010-10-13 04:26:57 +02:00
$this -> testing ( $testDetails );
2010-10-13 04:47:16 +02:00
$helper = $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]);
$result = $helper -> requireDatabaseFunctions ( $databaseConfig );
if ( $result ) {
2010-10-13 04:26:57 +02:00
return true ;
2010-10-13 04:47:16 +02:00
} else {
2010-10-13 04:48:17 +02:00
$this -> error ( $testDetails );
2010-10-13 04:47:16 +02:00
return false ;
2010-10-13 04:42:08 +02:00
}
}
function requireDatabaseConnection ( $databaseConfig , $testDetails ) {
$this -> testing ( $testDetails );
2010-10-13 06:26:06 +02:00
$helper = $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]);
2010-10-13 04:47:16 +02:00
$result = $helper -> requireDatabaseConnection ( $databaseConfig );
2010-10-13 04:48:46 +02:00
if ( $result [ 'success' ]) {
2010-10-13 04:47:16 +02:00
return true ;
} else {
$testDetails [ 2 ] .= " : " . $result [ 'error' ];
$this -> error ( $testDetails );
return false ;
2010-10-13 04:26:57 +02:00
}
}
2010-10-15 03:13:50 +02:00
function requireDatabaseVersion ( $databaseConfig , $testDetails ) {
$this -> testing ( $testDetails );
$helper = $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]);
if ( method_exists ( $helper , 'requireDatabaseVersion' )) {
$result = $helper -> requireDatabaseVersion ( $databaseConfig );
if ( $result [ 'success' ]) {
return true ;
} else {
2010-10-15 03:14:57 +02:00
$testDetails [ 2 ] .= $result [ 'error' ];
2010-10-15 03:14:48 +02:00
$this -> warning ( $testDetails );
2010-10-15 03:13:50 +02:00
return false ;
}
}
// Skipped test because this database has no required version
return true ;
}
2010-10-13 04:42:08 +02:00
function requireDatabaseServer ( $databaseConfig , $testDetails ) {
2010-10-13 04:26:57 +02:00
$this -> testing ( $testDetails );
2010-10-13 04:47:16 +02:00
$helper = $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]);
$result = $helper -> requireDatabaseServer ( $databaseConfig );
2010-10-13 04:48:46 +02:00
if ( $result [ 'success' ]) {
2010-10-13 04:47:16 +02:00
return true ;
} else {
$testDetails [ 2 ] .= " : " . $result [ 'error' ];
$this -> error ( $testDetails );
return false ;
}
}
function requireDatabaseOrCreatePermissions ( $databaseConfig , $testDetails ) {
$this -> testing ( $testDetails );
$helper = $this -> getDatabaseConfigurationHelper ( $databaseConfig [ 'type' ]);
$result = $helper -> requireDatabaseOrCreatePermissions ( $databaseConfig );
2010-10-13 04:48:46 +02:00
if ( $result [ 'success' ]) {
2010-10-15 03:16:09 +02:00
if ( $result [ 'alreadyExists' ]) $testDetails [ 3 ] = " Database $databaseConfig[database] " ;
2010-10-13 04:47:16 +02:00
else $testDetails [ 3 ] = " Able to create a new database " ;
$this -> testing ( $testDetails );
return true ;
} else {
2010-10-13 05:01:31 +02:00
if ( !@ $result [ 'cannotCreate' ]) {
$testDetails [ 2 ] .= " . Please create the database manually. " ;
} else {
$testDetails [ 2 ] .= " (user ' $databaseConfig[username] ' doesn't have CREATE DATABASE permissions.) " ;
}
2010-10-13 04:47:16 +02:00
$this -> error ( $testDetails );
return false ;
2010-10-13 04:26:57 +02:00
}
}
function requireServerVariables ( $varNames , $errorMessage ) {
//$this->testing($testDetails);
foreach ( $varNames as $varName ) {
if ( ! $_SERVER [ $varName ]) $missing [] = '$_SERVER[' . $varName . ']' ;
}
if ( ! isset ( $missing )) {
return true ;
} else {
$testDetails [ 2 ] .= " (the following PHP variables are missing: " . implode ( " , " , $missing ) . " ) " ;
$this -> error ( $testDetails );
}
}
2010-10-15 03:17:53 +02:00
2010-10-13 04:26:57 +02:00
function isRunningWebServer ( $testDetails ) {
$this -> testing ( $testDetails );
2010-10-15 03:17:53 +02:00
if ( $testDetails [ 3 ]) {
2010-10-13 04:26:57 +02:00
return true ;
} else {
$this -> warning ( $testDetails );
return false ;
}
}
// Must be PHP4 compatible
var $baseDir ;
function getBaseDir () {
// 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' ])) . DIRECTORY_SEPARATOR ;
return $this -> baseDir ;
}
function testing ( $testDetails ) {
if ( ! $testDetails ) return ;
$section = $testDetails [ 0 ];
$test = $testDetails [ 1 ];
$message = " OK " ;
if ( isset ( $testDetails [ 3 ])) $message .= " ( $testDetails[3] ) " ;
$this -> tests [ $section ][ $test ] = array ( " good " , $message );
}
function error ( $testDetails ) {
$section = $testDetails [ 0 ];
$test = $testDetails [ 1 ];
$this -> tests [ $section ][ $test ] = array ( " error " , $testDetails [ 2 ]);
$this -> errors [] = $testDetails ;
}
2010-10-13 06:22:35 +02:00
2010-10-13 04:26:57 +02:00
function warning ( $testDetails ) {
$section = $testDetails [ 0 ];
$test = $testDetails [ 1 ];
$this -> tests [ $section ][ $test ] = array ( " warning " , $testDetails [ 2 ]);
$this -> warnings [] = $testDetails ;
}
function hasErrors () {
return sizeof ( $this -> errors );
}
2010-10-13 06:22:35 +02:00
2010-10-13 04:26:57 +02:00
function hasWarnings () {
return sizeof ( $this -> warnings );
}
}
class Installer extends InstallRequirements {
function __construct () {
// Cache the baseDir value
$this -> getBaseDir ();
}
function install ( $config ) {
if ( isset ( $_SERVER [ 'HTTP_HOST' ])) {
?>
< html >
< head >
2010-10-15 03:14:39 +02:00
< title > Installing SilverStripe ...</ title >
2010-10-13 04:26:57 +02:00
< link rel = " stylesheet " type = " text/css " href = " themes/blackcandy/css/layout.css " />
< link rel = " stylesheet " type = " text/css " href = " themes/blackcandy/css/typography.css " />
< link rel = " stylesheet " type = " text/css " href = " themes/blackcandy/css/form.css " />
< link rel = " stylesheet " type = " text/css " href = " sapphire/dev/install/install.css " />
< script src = " sapphire/thirdparty/jquery/jquery.js " ></ script >
</ head >
< body >
< div id = " BgContainer " >
< div id = " Container " >
< div id = " Header " >
< h1 > SilverStripe CMS Installation </ h1 >
</ div >
< div id = " Navigation " >& nbsp ; </ div >
< div class = " clear " ><!-- --></ div >
< div id = " Layout " >
< div class = " typography " >
< 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 </ p >
< ul >
< ? php
} else {
echo " SILVERSTRIPE COMMAND-LINE INSTALLATION \n \n " ;
}
2010-10-13 06:22:35 +02:00
$webserver = $this -> findWebserver ();
$isIIS = $this -> isIIS ();
$isApache = $this -> isApache ();
2010-10-13 04:26:57 +02:00
flush ();
2010-10-15 03:15:04 +02:00
if ( isset ( $config [ 'stats' ])) {
2010-10-13 04:26:57 +02:00
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 ());
2010-10-13 06:22:40 +02:00
$encWebserver = urlencode ( $webserver );
2010-10-15 03:15:10 +02:00
$dbType = $config [ 'db' ][ 'type' ];
// Try to determine the database version from the helper
2010-10-15 03:15:14 +02:00
$databaseVersion = $config [ 'db' ][ 'type' ];
2010-10-15 03:15:10 +02:00
$helper = $this -> getDatabaseConfigurationHelper ( $dbType );
if ( $helper && method_exists ( $helper , 'getDatabaseVersion' )) {
$databaseVersion = urlencode ( $dbType . ': ' . $helper -> getDatabaseVersion ( $config [ 'db' ][ $dbType ]));
2010-10-13 04:43:05 +02:00
}
2010-10-13 06:22:40 +02:00
$url = " http://ss2stat.silverstripe.com/Installation/add?SilverStripe= $silverstripe_version &PHP= $phpVersion &Database= $databaseVersion &WebServer= $encWebserver " ;
2010-10-13 04:26:57 +02:00
if ( isset ( $_SESSION [ 'StatsID' ]) && $_SESSION [ 'StatsID' ]) {
$url .= '&ID=' . $_SESSION [ 'StatsID' ];
}
2010-10-15 03:17:42 +02:00
2010-10-13 04:26:57 +02:00
@ $_SESSION [ 'StatsID' ] = file_get_contents ( $url );
}
if ( file_exists ( 'mysite/_config.php' )) {
2010-10-13 04:44:34 +02:00
// Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly
// differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them
$fh = fopen ( 'mysite/_config.php' , 'wb' );
fclose ( $fh );
2010-10-13 04:26:57 +02:00
}
$theme = isset ( $_POST [ 'template' ]) ? $_POST [ 'template' ] : 'blackcandy' ;
2010-10-13 06:24:26 +02:00
$locale = isset ( $_POST [ 'locale' ]) ? $_POST [ 'locale' ] : 'en_US' ;
2010-10-13 06:26:31 +02:00
$type = $config [ 'db' ][ 'type' ];
$dbConfig = $config [ 'db' ][ $type ];
2010-10-13 06:28:30 +02:00
if ( ! $dbConfig ) {
echo " <p style= \" color: red \" >Bad config submitted</p><pre> " ;
print_r ( $config );
echo " </pre> " ;
die ();
}
2010-10-13 06:26:31 +02:00
2010-10-13 04:26:57 +02:00
// Write the config file
global $usingEnv ;
if ( $usingEnv ) {
2010-10-13 06:28:30 +02:00
2010-10-13 04:44:34 +02:00
$this -> statusMessage ( " Setting up 'mysite/_config.php' for use with _ss_environment.php... " );
$this -> writeToFile ( " mysite/_config.php " , <<< PHP
2010-10-13 04:26:57 +02:00
< ? php
global \ $project ;
\ $project = 'mysite' ;
global \ $database ;
2010-10-13 06:26:11 +02:00
\ $database = '{$dbConfig[' database ']}' ;
2010-10-13 04:26:57 +02:00
2010-10-13 06:26:01 +02:00
require_once ( 'conf/ConfigureFromEnv.php' );
2010-10-13 04:26:57 +02:00
MySQLDatabase :: set_connection_charset ( 'utf8' );
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer :: set_theme ( '$theme' );
2010-10-13 06:24:26 +02:00
// Set the site locale
2010-10-13 06:24:39 +02:00
i18n :: set_locale ( '$locale' );
2010-10-13 06:24:26 +02:00
2010-10-13 04:26:57 +02:00
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree :: enable_nested_urls ();
PHP
);
} else {
2010-10-13 04:44:34 +02:00
$this -> statusMessage ( " Setting up 'mysite/_config.php'... " );
2010-10-13 06:26:11 +02:00
$escapedPassword = addslashes ( $dbConfig [ 'password' ]);
2010-10-13 04:44:34 +02:00
$this -> writeToFile ( " mysite/_config.php " , <<< PHP
2010-10-13 04:26:57 +02:00
< ? php
global \ $project ;
\ $project = 'mysite' ;
global \ $databaseConfig ;
\ $databaseConfig = array (
2010-10-13 06:26:06 +02:00
" type " => '{$type}' ,
2010-10-15 03:22:20 +02:00
" server " => '{$dbConfig[' server ']}' ,
" username " => '{$dbConfig[' username ']}' ,
" password " => '{$escapedPassword}' ,
2010-10-13 06:26:11 +02:00
" database " => '{$dbConfig[' database ']}' ,
" path " => '{$dbConfig[' path ']}' ,
2010-10-13 04:26:57 +02:00
);
2010-10-13 04:57:56 +02:00
MySQLDatabase :: set_connection_charset ( 'utf8' );
2010-10-13 04:26:57 +02:00
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer :: set_theme ( '$theme' );
2010-10-13 06:24:26 +02:00
// Set the site locale
i18n :: set_locale ( '$locale' );
2010-10-13 04:26:57 +02:00
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree :: enable_nested_urls ();
PHP
);
}
2010-10-13 06:26:40 +02:00
// Write the appropriate web server configuration file for rewriting support
if ( $this -> hasRewritingCapability ()) {
if ( $isApache ) {
$this -> statusMessage ( " Setting up '.htaccess' file... " );
$this -> createHtaccess ();
} elseif ( $isIIS ) {
$this -> statusMessage ( " Setting up 'web.config' file... " );
$this -> createWebConfig ();
}
2010-10-13 06:22:35 +02:00
}
2010-10-13 04:26:57 +02:00
// Load the sapphire runtime
$_SERVER [ 'SCRIPT_FILENAME' ] = dirname ( realpath ( $_SERVER [ 'SCRIPT_FILENAME' ])) . '/sapphire/main.php' ;
chdir ( 'sapphire' );
// Rebuild the manifest
$_GET [ 'flush' ] = true ;
// Show errors as if you're in development mode
$_SESSION [ 'isDev' ] = 1 ;
require_once ( 'core/Core.php' );
$this -> statusMessage ( " Building database schema... " );
// Build database
$con = new Controller ();
$con -> pushCurrent ();
global $databaseConfig ;
DB :: connect ( $databaseConfig );
$dbAdmin = new DatabaseAdmin ();
$dbAdmin -> init ();
$dbAdmin -> doBuild ( true );
2010-10-13 04:29:22 +02:00
// Create default administrator user and group in database
// (not using Security::setDefaultAdmin())
$adminMember = Security :: findAnAdministrator ();
$adminMember -> Email = $config [ 'admin' ][ 'username' ];
$adminMember -> Password = $config [ 'admin' ][ 'password' ];
$adminMember -> PasswordEncryption = Security :: get_password_encryption_algorithm ();
2010-10-13 06:26:27 +02:00
// @todo Exception thrown if database with admin already exists with same Email
2010-10-13 06:26:20 +02:00
try {
$adminMember -> write ();
} catch ( Exception $e ) {
}
2010-10-13 04:26:57 +02:00
// Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266)
2010-10-13 06:26:16 +02:00
Filesystem :: sync ();
2010-10-13 04:26:57 +02:00
$_SESSION [ 'username' ] = $config [ 'admin' ][ 'username' ];
$_SESSION [ 'password' ] = $config [ 'admin' ][ 'password' ];
if ( ! $this -> errors ) {
2010-10-13 06:26:40 +02:00
if ( isset ( $_SERVER [ 'HTTP_HOST' ]) && $this -> hasRewritingCapability ()) {
2010-10-13 04:26:57 +02:00
$this -> statusMessage ( " Checking that friendly URLs work... " );
2010-10-13 06:22:35 +02:00
$this -> checkRewrite ();
2010-10-13 04:26:57 +02:00
} else {
2010-10-13 06:26:40 +02:00
echo <<< HTML
< li > SilverStripe successfully installed ; I am now redirecting you to your SilverStripe site ...</ li >
< script >
setTimeout ( function () {
window . location = " index.php/home/successfullyinstalled?flush=1 " ;
}, 2000 );
</ script >
< noscript >
< li >< a href = " index.php/home/successfullyinstalled?flush=1 " > Click here to access your site .</ li >
</ noscript >
HTML ;
2010-10-13 04:26:57 +02:00
}
}
return $this -> errors ;
}
2010-10-13 04:44:34 +02:00
function writeToFile ( $filename , $content ) {
2010-10-13 04:26:57 +02:00
$base = $this -> getBaseDir ();
2010-10-13 04:44:34 +02:00
$this -> statusMessage ( " Setting up $base $filename " );
2010-10-13 04:26:57 +02:00
2010-10-13 04:27:21 +02:00
if (( @ $fh = fopen ( $base . $filename , 'wb' )) && fwrite ( $fh , $content ) && fclose ( $fh )) {
2010-10-13 04:26:57 +02:00
return true ;
} else {
$this -> error ( " Couldn't write to file $base $filename " );
}
}
function createHtaccess () {
$start = " ### SILVERSTRIPE START ### \n " ;
$end = " \n ### SILVERSTRIPE END ### " ;
$base = dirname ( $_SERVER [ 'SCRIPT_NAME' ]);
if ( defined ( 'DIRECTORY_SEPARATOR' )) $base = str_replace ( DIRECTORY_SEPARATOR , '/' , $base );
else $base = str_replace ( " \\ " , '/' , $base );
if ( $base != '.' ) $baseClause = " RewriteBase $base\n " ;
else $baseClause = " " ;
$rewrite = <<< TEXT
< Files *. ss >
2010-10-13 04:56:09 +02:00
Order deny , allow
Deny from all
Allow from 127.0 . 0.1
</ Files >
< Files web . config >
Order deny , allow
Deny from all
2010-10-13 04:26:57 +02:00
</ Files >
2010-10-15 03:18:46 +02:00
ErrorDocument 404 / assets / error - 404. html
ErrorDocument 500 / assets / error - 500. html
2010-10-15 03:19:01 +02:00
< IfModule mod_alias . c >
RedirectMatch 403 / silverstripe - cache ( /| $ )
</ IfModule >
2010-10-13 06:26:40 +02:00
< IfModule mod_rewrite . c >
2010-11-22 00:53:50 +01:00
SetEnv HTTP_MOD_REWRITE On
2010-10-13 06:26:40 +02:00
RewriteEngine On
$baseClause
RewriteCond % { REQUEST_URI } ^ ( .* ) $
RewriteCond % { REQUEST_FILENAME } !- f
RewriteRule .* sapphire / main . php ? url =% 1 &% { QUERY_STRING } [ L ]
</ IfModule >
2010-10-13 06:22:35 +02:00
TEXT ;
2010-10-13 04:26:57 +02:00
if ( file_exists ( '.htaccess' )) {
$htaccess = file_get_contents ( '.htaccess' );
if ( strpos ( $htaccess , '### SILVERSTRIPE START ###' ) === false && strpos ( $htaccess , '### SILVERSTRIPE END ###' ) === false ) {
$htaccess .= " \n ### SILVERSTRIPE START ### \n ### SILVERSTRIPE END ### \n " ;
}
if ( strpos ( $htaccess , '### SILVERSTRIPE START ###' ) !== false && strpos ( $htaccess , '### SILVERSTRIPE END ###' ) !== false ) {
$start = substr ( $htaccess , 0 , strpos ( $htaccess , '### SILVERSTRIPE START ###' )) . " ### SILVERSTRIPE START ### \n " ;
$end = " \n " . substr ( $htaccess , strpos ( $htaccess , '### SILVERSTRIPE END ###' ));
}
}
2010-10-13 04:44:34 +02:00
$this -> writeToFile ( '.htaccess' , $start . $rewrite . $end );
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:22:35 +02:00
/**
* Writes basic configuration to the web . config for IIS
* so that rewriting capability can be use .
*/
function createWebConfig () {
$content = <<< TEXT
< ? xml version = " 1.0 " encoding = " utf-8 " ?>
< configuration >
< system . webServer >
2010-10-15 03:19:01 +02:00
< security >
< requestFiltering >
< hiddenSegments applyToWebDAV = " false " >
< add segment = " silverstripe-cache " />
</ hiddenSegments >
</ requestFiltering >
</ security >
2010-10-13 06:22:35 +02:00
< rewrite >
< rules >
< rule name = " SilverStripe Clean URLs " stopProcessing = " true " >
< match url = " ^(.*) $ " />
< conditions >
< add input = " { REQUEST_FILENAME} " matchType = " IsFile " negate = " true " />
</ conditions >
< action type = " Rewrite " url = " sapphire/main.php?url= { R:1} " appendQueryString = " true " />
</ rule >
</ rules >
</ rewrite >
</ system . webServer >
</ configuration >
TEXT ;
2010-10-13 04:26:57 +02:00
2010-10-13 06:22:35 +02:00
$this -> writeToFile ( 'web.config' , $content );
2010-10-13 04:26:57 +02:00
}
2010-10-13 06:22:35 +02:00
function checkRewrite () {
2010-10-13 04:26:57 +02:00
if ( ! isset ( $_SERVER [ 'HTTP_HOST' ]) || ! $_SERVER [ 'HTTP_HOST' ]) {
$this -> statusMessage ( " Installer seems to be called from command-line, we're going to assume that rewriting is working. " );
return true ;
}
echo <<< HTML
< li id = " ModRewriteResult " > Testing ...</ li >
< script >
if ( typeof $ == 'undefined' ) {
document . getElemenyById ( 'ModeRewriteResult' ) . innerHTML = " I can't run jQuery ajax to set rewriting; I will redirect you to the homepage to see if everything is working. " ;
setTimeout ( function () {
window . location = " home/successfullyinstalled?flush=1 " ;
}, 10000 );
} else {
$ . ajax ({
method : 'get' ,
url : 'InstallerTest/testrewrite' ,
complete : function ( response ) {
if ( response . responseText == 'OK' ) {
$ ( '#ModRewriteResult' ) . html ( " Friendly URLs set up successfully; I am now redirecting you to your SilverStripe site... " )
setTimeout ( function () {
window . location = " home/successfullyinstalled?flush=1 " ;
}, 2000 );
} else {
2010-11-18 06:08:12 +01:00
$ ( '#ModRewriteResult' ) . html ( " Friendly URLs are not working. This is most likely because a rewrite module isn't configured "
+ " correctly on your site. You may need to get your web host or server administrator to do this for you: "
+ " <ul> "
+ " <li><strong>mod_rewrite</strong> or other rewrite module is enabled on your web server</li> "
+ " <li><strong>AllowOverride All</strong> is set for the directory where SilverStripe is installed</li> "
+ " </ul> " );
2010-10-13 04:26:57 +02:00
}
}
});
}
</ script >
< noscript >
2010-11-18 06:08:12 +01:00
< li >< a href = " home/successfullyinstalled?flush=1 " > Click here </ a > to check friendly URLs are working . If you get a 404 then something is wrong .</ li >
2010-10-13 04:26:57 +02:00
</ noscript >
HTML ;
}
function var_export_array_nokeys ( $array ) {
$retval = " array( \n " ;
foreach ( $array as $item ) {
$retval .= " \t ' " ;
$retval .= trim ( $item );
$retval .= " ', \n " ;
}
$retval .= " ) " ;
return $retval ;
}
/**
* Show an installation status message .
* The output differs depending on whether this is CLI or web based
*/
function statusMessage ( $msg ) {
2010-10-15 03:17:34 +02:00
echo " <li> $msg </li> \n " ;
2010-10-13 04:26:57 +02:00
flush ();
}
2010-10-15 03:14:57 +02:00
}