I am now running through the installation steps (this should take about 30 seconds)
If you receive a fatal error, refresh this page to continue the installation
installHeader();
$isIIS = $this->isIIS();
$isApache = $this->isApache();
$projectDir = $this->getProjectDir();
$projectSrcDir = $this->getProjectSrcDir();
flush();
// Send install stats
if (!empty($config['stats'])) {
$this->sendInstallStats($config);
}
// Cleanup _config.php
$basePath = $this->getBaseDir();
$appConfigPath = $basePath . "{$projectDir}/_config.php";
if (file_exists($appConfigPath)) {
// 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($appConfigPath, 'wb');
fclose($fh);
}
// Write all files
$this->writeIndexPHP();
$this->writeConfigPHP($config);
$this->writeConfigYaml($config);
$this->writeConfigEnv($config);
// Write other stuff
if (!$this->checkModuleExists('cms')) {
$rootURLControllerPath = $basePath . "{$projectSrcDir}/RootURLController.php";
$this->writeToFile($rootURLControllerPath, <<Your site is now set up. Start adding controllers to app/src to get started.";
}
}
PHP
);
}
// Write the appropriate web server configuration file for rewriting support
if ($this->hasRewritingCapability()) {
if ($isApache) {
$this->createHtaccess();
} elseif ($isIIS) {
$this->createWebConfig();
}
}
// Build request
$request = HTTPRequestBuilder::createFromEnvironment();
// Install kernel (fix to dev)
$kernel = new CoreKernel(Path::normalise($basePath));
$kernel->setEnvironment(Kernel::DEV);
$app = new HTTPApplication($kernel);
// Build db within HTTPApplication
$app->execute($request, function (HTTPRequest $request) use ($config) {
// Suppress cookie errors on install
Cookie::config()->set('report_errors', false);
// Start session and execute
$request->getSession()->init($request);
// Output status
$this->statusMessage("Building database schema...");
// Setup DB
$dbAdmin = new DatabaseAdmin();
$dbAdmin->setRequest($request);
$dbAdmin->pushCurrent();
$dbAdmin->doInit();
$dbAdmin->doBuild(true);
// Create default administrator user and group in database
// (not using Security::setDefaultAdmin())
$username = $config['admin']['username'];
$password = $config['admin']['password'];
$adminMember = DefaultAdminService::singleton()
->findOrCreateAdmin(
$username,
_t('SilverStripe\\Security\\DefaultAdminService.DefaultAdminFirstname', 'Default Admin')
);
$adminMember->Email = $username;
$adminMember->Password = $password;
$adminMember->PasswordEncryption = Security::config()->get('encryption_algorithm');
try {
$this->statusMessage('Creating default CMS admin account...');
$adminMember->write();
} catch (Exception $e) {
$this->statusMessage(
sprintf('Warning: Default CMS admin account could not be created (error: %s)', $e->getMessage())
);
}
$request->getSession()->set('username', $username);
$request->getSession()->set('password', $password);
$request->getSession()->save($request);
}, true);
// Check result of install
if (!$this->errors) {
// switch the session to Dev mode so that
// flush does not require authentication
// for the first time after installation
$request['isDev'] = '1';
$this->setSessionEnvType($request);
unset($request['isDev']);
$request->getSession()->save($request);
if (isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) {
$this->statusMessage("Checking that friendly URLs work...");
$this->checkRewrite();
} else {
$params = http_build_query($request->getVars() + ['flush' => '']);
$destinationURL = 'index.php/' .
($this->checkModuleExists('cms') ? "home/successfullyinstalled?$params" : "?$params");
echo <<SilverStripe successfully installed; I am now redirecting you to your SilverStripe site...
HTML;
}
} else {
// Output all errors
$this->statusMessage('Encountered ' . count($this->errors) . ' errors during install:');
echo "
";
foreach ($this->errors as $error) {
$this->statusMessage($error);
}
echo "
";
$this->statusMessage('Please Click here to return to the installer.');
}
return $this->errors;
}
protected function writeIndexPHP()
{
$content = <<<'PHP'
handle($request);
$response->output();
PHP;
$path = $this->getPublicDir() . 'index.php';
$this->writeToFile($path, $content, true);
}
/**
* Write all .env files
*
* @param $config
*/
protected function writeConfigEnv($config)
{
if (!$config['usingEnv']) {
return;
}
$path = $this->getBaseDir() . '.env';
$vars = [];
// Retain existing vars
$env = new EnvironmentLoader();
if (file_exists($path)) {
$vars = $env->loadFile($path) ?: [];
}
// Set base URL
if (!isset($vars['SS_BASE_URL']) && isset($_SERVER['HTTP_HOST'])) {
$vars['SS_BASE_URL'] = 'http://' . $_SERVER['HTTP_HOST'] . BASE_URL;
}
// Set DB env
if (empty($config['db']['database'])) {
$vars['SS_DATABASE_CHOOSE_NAME'] = true;
} else {
$vars['SS_DATABASE_NAME'] = $config['db']['database'];
}
$vars['SS_DATABASE_CLASS'] = $config['db']['type'];
if (isset($config['db']['server'])) {
$vars['SS_DATABASE_SERVER'] = $config['db']['server'];
}
if (isset($config['db']['username'])) {
$vars['SS_DATABASE_USERNAME'] = $config['db']['username'];
}
if (isset($config['db']['password'])) {
$vars['SS_DATABASE_PASSWORD'] = $config['db']['password'];
}
if (isset($config['db']['path'])) {
$vars['SS_DATABASE_PATH'] = $config['db']['path'];
// sqlite compat
$vars['SS_SQLITE_DATABASE_PATH'] = $config['db']['path'];
}
if (isset($config['db']['key'])) {
$vars['SS_DATABASE_KEY'] = $config['db']['key'];
// sqlite compat
$vars['SS_SQLITE_DATABASE_KEY'] = $config['db']['key'];
}
// Write all env vars
$lines = [
'# Generated by SilverStripe Installer'
];
ksort($vars);
foreach ($vars as $key => $value) {
$lines[] = $key . '="' . addcslashes($value, '"') . '"';
}
$this->writeToFile('.env', implode("\n", $lines));
// Re-load env vars for installer access
$env->loadFile($path);
}
/**
* Write all *.php files
*
* @param array $config
*/
protected function writeConfigPHP($config)
{
$configPath = $this->getProjectDir() . DIRECTORY_SEPARATOR . "_config.php";
if ($config['usingEnv']) {
$this->writeToFile($configPath, " $value) {
$lines[] = sprintf(
" '%s' => '%s'",
addslashes($key),
addslashes($value)
);
}
$databaseConfigContent = implode(",\n", $lines);
$this->writeToFile($configPath, <<ymlString($config['locale']);
$projectDir = $this->getProjectDir();
// Set either specified, or no theme
if ($config['theme'] && $config['theme'] !== 'tutorial') {
$theme = $this->ymlString($config['theme']);
$themeYML = <<writeToFile("{$projectDir}/_config/theme.yml", <<getBaseDir()))]
: [
$this->getBaseDir() . $filename,
$filename
];
$this->statusMessage("Setting up $relativePath");
if ((@$fh = fopen($absolutePath, 'wb')) && fwrite($fh, $content) && fclose($fh)) {
// Set permissions to writable
@chmod($absolutePath, 0775);
return true;
}
$this->error("Couldn't write to file $relativePath");
return false;
}
/**
* Ensure root .htaccess is setup
*/
public function createHtaccess()
{
$start = "### SILVERSTRIPE START ###\n";
$end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']);
$base = Convert::slashes($base, '/');
if ($base != '.') {
$baseClause = "RewriteBase '$base'\n";
} else {
$baseClause = "";
}
if (strpos(strtolower(php_sapi_name()), "cgi") !== false) {
$cgiClause = "RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n";
} else {
$cgiClause = "";
}
$rewrite = <<
Order deny,allow
Deny from all
Allow from 127.0.0.1
# Deny access to IIS configuration
Order deny,allow
Deny from all
# Deny access to YAML configuration files which might include sensitive information
Order allow,deny
Deny from all
# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
# Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
DirectoryIndex disabled
DirectorySlash On
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
$baseClause
$cgiClause
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule ^\.env - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteRule (error|silverstripe|debug)\.log - [F,L,NC]
# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
# Try finding framework in the vendor folder first
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
TEXT;
$htaccessPath = $this->getPublicDir() . '.htaccess';
if (file_exists($htaccessPath)) {
$htaccess = file_get_contents($htaccessPath);
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 ###'));
}
}
$this->writeToFile($htaccessPath, $start . $rewrite . $end, true);
}
/**
* Writes basic configuration to the web.config for IIS
* so that rewriting capability can be use.
*/
public function createWebConfig()
{
$content = <<
TEXT;
$path = $this->getPublicDir() . 'web.config';
$this->writeToFile($path, $content, true);
}
public function checkRewrite()
{
$params = http_build_query(['flush' => '']);
$destinationURL = rtrim(BASE_URL, '/') . '/' . (
$this->checkModuleExists('cms')
? "home/successfullyinstalled?$params"
: "?$params"
);
echo <<Testing...
HTML;
}
/**
* Show an installation status message.
* The output differs depending on whether this is CLI or web based
*
* @param string $msg
*/
public function statusMessage($msg)
{
echo "