#25: Updated the installer to work with a brand-new system with just PHP installed. Changed the way the base URL is determined to work with systems that have to access the app using /public.

This commit is contained in:
Andy Heathershaw 2017-09-06 10:33:22 +01:00
parent 0c1ff083f6
commit 34b2ff6ea4
4 changed files with 100 additions and 14 deletions

View File

@ -53,6 +53,15 @@ class AppServiceProvider extends ServiceProvider
{
LengthAwarePaginator::defaultView($themeHelper->viewName('partials.pager_links'));
}
// Set base URL variable (used in both the main app and the installer)
$baseUrl = url('/');
if (!substr($baseUrl, strlen($baseUrl) - 1, 1) != '/')
{
$baseUrl .= '/';
}
View::share('appBaseUrl', $baseUrl);
}
/**

View File

@ -11,6 +11,7 @@ class BlueTwilightInstaller
{
$this->baseDirectory = dirname(__DIR__);
chdir($this->baseDirectory);
putenv('HOME=' . $this->baseDirectory);
// Display errors so installer never gets a WSOD!
ini_set('display_errors', true);
@ -25,11 +26,17 @@ class BlueTwilightInstaller
exit();
}
?>
<html>
<head>
<title>Blue Twilight Setup</title>
</head>
<body>
<h1>Blue Twilight Setup</h1>
<p>We need to download a few things - namely <a href="http://getcomposer.org" target="_blank">Composer</a> and related packages - before we can kick off the Blue Twilight installer.</p>
<p>We can do this for you - simply click the button below.</p>
<p style="font-weight: bold; color: #ff0000;">This can take a few minutes so please be patient!</p>
<form method="post">
<button type="submit">Install Composer and dependencies for me</button>
<button type="submit" onclick="this.disabled = true;">Install Composer and dependencies for me</button>
</form>
<hr/>
@ -38,6 +45,8 @@ class BlueTwilightInstaller
<p>If you already have Composer installed, however, you may want to use that instead. Just run the below commands on your server, changing the path to Composer as appropriate:</p>
<p><em>Please note: &quot;composer.phar&quot; may actually be &quot;composer&quot; on your system.</em></p>
<pre>cd <?php echo $this->baseDirectory; ?><br/>/path/to/composer.phar install</pre>
</body>
</html>
<?php
}
@ -50,11 +59,14 @@ class BlueTwilightInstaller
<ul>
<?php
$steps = [
['Checking PHP modules', 'checkPhpModules'],
['Fetching Composer signature', 'fetchComposerSignature'],
['Installing Composer', 'installComposer'],
['Installing dependencies using Composer', 'runComposer']
['Installing dependencies using Composer', 'runComposer'],
['Generating application key', 'generateAppKey']
];
$successful = true;
foreach ($steps as $step)
{
echo sprintf("<li>%s...</li>%s", $step[0], PHP_EOL);
@ -62,15 +74,49 @@ class BlueTwilightInstaller
if (!$result)
{
$successful = false;
break;
}
}
if ($successful)
{
header('Location: install/check');
exit();
}
?>
</ul>
<?php
}
private function checkPhpModules()
{
$requiredModules = [
'simplexml',
'curl',
'mbstring',
'dom'
];
$invalidModules = [];
foreach ($requiredModules as $module)
{
if (!extension_loaded($module))
{
$invalidModules[] = $module;
}
}
if (count($invalidModules) > 0)
{
$this->echoError(sprintf('The following PHP modules are missing and need to be installed to continue: %s', join(', ', $invalidModules)));
return false;
}
return true;
}
private function echoError($message)
{
echo sprintf("<span style=\"color: #ff0000;\">%s.</span>%s", $message, PHP_EOL);
@ -105,11 +151,42 @@ class BlueTwilightInstaller
return true;
}
private function generateAppKey()
{
if (!file_exists('.env') && file_exists('.env.example'))
{
copy('.env.example', '.env');
}
ob_start();
system('touch .env', $rc);
$result = ob_get_clean();
echo nl2br($result);
ob_start();
system('php artisan key:generate', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
$this->echoError('Failed to generate application key');
return false;
}
$this->echoOK();
return true;
}
private function installComposer()
{
$rc = -1;
ob_start();
system('php -r "copy(\'https://getcomposer.org/installer\', \'composer-setup.php\');"', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
$this->echoError('Failed to fetch Composer');

View File

@ -7,7 +7,7 @@
<meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
<title>@yield('title') | @lang('global.app_name')</title>
<base href="{{ url('/') }}">
<base href="{{ $appBaseUrl }}">
<meta name="csrf-token" content="{{ csrf_token() }}">

View File

@ -7,7 +7,7 @@
<meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
<title>@yield('title') | {{ UserConfig::get('app_name') }}</title>
<base href="{{ url('/') }}">
<base href="{{ $appBaseUrl }}">
<meta name="csrf-token" content="{{ csrf_token() }}">