#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')); 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__); $this->baseDirectory = dirname(__DIR__);
chdir($this->baseDirectory); chdir($this->baseDirectory);
putenv('HOME=' . $this->baseDirectory);
// Display errors so installer never gets a WSOD! // Display errors so installer never gets a WSOD!
ini_set('display_errors', true); ini_set('display_errors', true);
@ -25,19 +26,27 @@ class BlueTwilightInstaller
exit(); exit();
} }
?> ?>
<h1>Blue Twilight Setup</h1> <html>
<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> <head>
<p>We can do this for you - simply click the button below.</p> <title>Blue Twilight Setup</title>
<form method="post"> </head>
<button type="submit">Install Composer and dependencies for me</button> <body>
</form> <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" onclick="this.disabled = true;">Install Composer and dependencies for me</button>
</form>
<hr/> <hr/>
<h2>Got Composer?</h2> <h2>Got Composer?</h2>
<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>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> <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> <pre>cd <?php echo $this->baseDirectory; ?><br/>/path/to/composer.phar install</pre>
</body>
</html>
<?php <?php
} }
@ -50,11 +59,14 @@ class BlueTwilightInstaller
<ul> <ul>
<?php <?php
$steps = [ $steps = [
['Checking PHP modules', 'checkPhpModules'],
['Fetching Composer signature', 'fetchComposerSignature'], ['Fetching Composer signature', 'fetchComposerSignature'],
['Installing Composer', 'installComposer'], ['Installing Composer', 'installComposer'],
['Installing dependencies using Composer', 'runComposer'] ['Installing dependencies using Composer', 'runComposer'],
['Generating application key', 'generateAppKey']
]; ];
$successful = true;
foreach ($steps as $step) foreach ($steps as $step)
{ {
echo sprintf("<li>%s...</li>%s", $step[0], PHP_EOL); echo sprintf("<li>%s...</li>%s", $step[0], PHP_EOL);
@ -62,15 +74,49 @@ class BlueTwilightInstaller
if (!$result) if (!$result)
{ {
$successful = false;
break; break;
} }
} }
if ($successful)
{
header('Location: install/check');
exit();
}
?> ?>
</ul> </ul>
<?php <?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) private function echoError($message)
{ {
echo sprintf("<span style=\"color: #ff0000;\">%s.</span>%s", $message, PHP_EOL); echo sprintf("<span style=\"color: #ff0000;\">%s.</span>%s", $message, PHP_EOL);
@ -105,11 +151,42 @@ class BlueTwilightInstaller
return true; 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() private function installComposer()
{ {
$rc = -1; $rc = -1;
ob_start();
system('php -r "copy(\'https://getcomposer.org/installer\', \'composer-setup.php\');"', $rc); system('php -r "copy(\'https://getcomposer.org/installer\', \'composer-setup.php\');"', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0) if ($rc != 0)
{ {
$this->echoError('Failed to fetch Composer'); $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() }})"> <meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
<title>@yield('title') | @lang('global.app_name')</title> <title>@yield('title') | @lang('global.app_name')</title>
<base href="{{ url('/') }}"> <base href="{{ $appBaseUrl }}">
<meta name="csrf-token" content="{{ csrf_token() }}"> <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() }})"> <meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
<title>@yield('title') | {{ UserConfig::get('app_name') }}</title> <title>@yield('title') | {{ UserConfig::get('app_name') }}</title>
<base href="{{ url('/') }}"> <base href="{{ $appBaseUrl }}">
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">