Skip to content

Commit fb83eda

Browse files
committed
Laravel 5.7.* Google App Engine Standard Support
Setup Laravel correctly to run in a production environment on Google App Engine Standard. Changes: - Change cached framework files directory from bootstrap/cache to /tmp. This is required as /tmp is the only writable directory in the system - Exclude local bootstrap/cache files from deployment - Tweak useStoragePath() call to only be used when ENV var is present
1 parent 83cbbeb commit fb83eda

File tree

6 files changed

+344
-3
lines changed

6 files changed

+344
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
# PHP Composer dependencies:
17+
/vendor/
18+
/node_modules/
19+
20+
# Ignore local laravel cache:
21+
/bootstrap/cache/*.php

appengine/php72/laravel-framework/app.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ env_variables:
55
APP_KEY: YOUR_APP_KEY
66
APP_STORAGE: /tmp
77
VIEW_COMPILED_PATH: /tmp
8+
APP_BOOTSTRAP_PATH: /tmp
89

910
## To use Stackdriver logging in your Laravel application, copy
1011
## "app/Logging/CreateStackdriverLogger.php" and "config/logging.php"
1112
## into your Laravel application. Then uncomment the following line:
1213
# LOG_CHANNEL: stackdriver
14+
15+
APP_SERVICES_CACHE: /tmp/services.php
16+
APP_PACKAGES_CACHE: /tmp/packages.php
17+
APP_CONFIG_CACHE: /tmp/config.php
18+
APP_ROUTES_CACHE: /tmp/routes.php
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App;
4+
5+
class Application extends \Illuminate\Foundation\Application
6+
{
7+
/**
8+
* Get the path to the bootstrap directory.
9+
*
10+
* @param string $path Optionally, a path to append to the bootstrap path
11+
* @return string
12+
*/
13+
public function bootstrapPath($path = '')
14+
{
15+
return $_ENV['APP_BOOTSTRAP_PATH'] ?? parent::bootstrapPath($path);
16+
}
17+
18+
/**
19+
* Get the path to the cached services.php file.
20+
*
21+
* @return string
22+
*/
23+
public function getCachedServicesPath()
24+
{
25+
if (isset($_ENV['APP_BOOTSTRAP_PATH'])) {
26+
return $this->bootstrapPath().'/services.php';
27+
} else {
28+
return parent::getCachedServicesPath();
29+
}
30+
}
31+
/**
32+
* Get the path to the cached packages.php file.
33+
*
34+
* @return string
35+
*/
36+
public function getCachedPackagesPath()
37+
{
38+
if (isset($_ENV['APP_BOOTSTRAP_PATH'])) {
39+
return $this->bootstrapPath().'/packages.php';
40+
} else {
41+
return parent::getCachedPackagesPath();
42+
}
43+
}
44+
45+
/**
46+
* Get the path to the configuration cache file.
47+
*
48+
* @return string
49+
*/
50+
public function getCachedConfigPath()
51+
{
52+
if (isset($_ENV['APP_BOOTSTRAP_PATH'])) {
53+
return $this->bootstrapPath().'/config.php';
54+
} else {
55+
return parent::getCachedConfigPath();
56+
}
57+
}
58+
59+
/**
60+
* Get the path to the routes cache file.
61+
*
62+
* @return string
63+
*/
64+
public function getCachedRoutesPath()
65+
{
66+
if (isset($_ENV['APP_BOOTSTRAP_PATH'])) {
67+
return $this->bootstrapPath().'/routes.php';
68+
} else {
69+
return parent::getCachedRoutesPath();
70+
}
71+
}
72+
}

appengine/php72/laravel-framework/bootstrap/app.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
|
1212
*/
1313

14-
$app = new Illuminate\Foundation\Application(
15-
realpath(__DIR__ . '/../')
14+
$app = new \App\Application(
15+
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
1616
);
1717

1818
/*
@@ -53,7 +53,9 @@
5353
|
5454
*/
5555

56-
$app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));
56+
if (isset($_ENV['APP_STORAGE'])) {
57+
$app->useStoragePath($_ENV['APP_STORAGE']);
58+
}
5759
# [END google-app-engine-deployment]
5860

5961
/*
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Application Name
8+
|--------------------------------------------------------------------------
9+
|
10+
| This value is the name of your application. This value is used when the
11+
| framework needs to place the application's name in a notification or
12+
| any other location as required by the application or its packages.
13+
|
14+
*/
15+
16+
'name' => env('APP_NAME', 'Laravel'),
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Application Environment
21+
|--------------------------------------------------------------------------
22+
|
23+
| This value determines the "environment" your application is currently
24+
| running in. This may determine how you prefer to configure various
25+
| services the application utilizes. Set this in your ".env" file.
26+
|
27+
*/
28+
29+
'env' => env('APP_ENV', 'production'),
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Application Storage Path
34+
|--------------------------------------------------------------------------
35+
|
36+
|
37+
|
38+
*/
39+
'app_storage' => env('APP_STORAGE', storage_path()),
40+
41+
/*
42+
|--------------------------------------------------------------------------
43+
| Application Debug Mode
44+
|--------------------------------------------------------------------------
45+
|
46+
| When your application is in debug mode, detailed error messages with
47+
| stack traces will be shown on every error that occurs within your
48+
| application. If disabled, a simple generic error page is shown.
49+
|
50+
*/
51+
52+
'debug' => env('APP_DEBUG', false),
53+
54+
/*
55+
|--------------------------------------------------------------------------
56+
| Application URL
57+
|--------------------------------------------------------------------------
58+
|
59+
| This URL is used by the console to properly generate URLs when using
60+
| the Artisan command line tool. You should set this to the root of
61+
| your application so that it is used when running Artisan tasks.
62+
|
63+
*/
64+
65+
'url' => env('APP_URL', 'http://localhost'),
66+
67+
'asset_url' => env('ASSET_URL', null),
68+
69+
/*
70+
|--------------------------------------------------------------------------
71+
| Application Timezone
72+
|--------------------------------------------------------------------------
73+
|
74+
| Here you may specify the default timezone for your application, which
75+
| will be used by the PHP date and date-time functions. We have gone
76+
| ahead and set this to a sensible default for you out of the box.
77+
|
78+
*/
79+
80+
'timezone' => 'UTC',
81+
82+
/*
83+
|--------------------------------------------------------------------------
84+
| Application Locale Configuration
85+
|--------------------------------------------------------------------------
86+
|
87+
| The application locale determines the default locale that will be used
88+
| by the translation service provider. You are free to set this value
89+
| to any of the locales which will be supported by the application.
90+
|
91+
*/
92+
93+
'locale' => 'en',
94+
95+
/*
96+
|--------------------------------------------------------------------------
97+
| Application Fallback Locale
98+
|--------------------------------------------------------------------------
99+
|
100+
| The fallback locale determines the locale to use when the current one
101+
| is not available. You may change the value to correspond to any of
102+
| the language folders that are provided through your application.
103+
|
104+
*/
105+
106+
'fallback_locale' => 'en',
107+
108+
/*
109+
|--------------------------------------------------------------------------
110+
| Faker Locale
111+
|--------------------------------------------------------------------------
112+
|
113+
| This locale will be used by the Faker PHP library when generating fake
114+
| data for your database seeds. For example, this will be used to get
115+
| localized telephone numbers, street address information and more.
116+
|
117+
*/
118+
119+
'faker_locale' => 'en_US',
120+
121+
/*
122+
|--------------------------------------------------------------------------
123+
| Encryption Key
124+
|--------------------------------------------------------------------------
125+
|
126+
| This key is used by the Illuminate encrypter service and should be set
127+
| to a random, 32 character string, otherwise these encrypted strings
128+
| will not be safe. Please do this before deploying an application!
129+
|
130+
*/
131+
132+
'key' => env('APP_KEY'),
133+
134+
'cipher' => 'AES-256-CBC',
135+
136+
/*
137+
|--------------------------------------------------------------------------
138+
| Autoloaded Service Providers
139+
|--------------------------------------------------------------------------
140+
|
141+
| The service providers listed here will be automatically loaded on the
142+
| request to your application. Feel free to add your own services to
143+
| this array to grant expanded functionality to your applications.
144+
|
145+
*/
146+
147+
'providers' => [
148+
149+
/*
150+
* Laravel Framework Service Providers...
151+
*/
152+
Illuminate\Auth\AuthServiceProvider::class,
153+
Illuminate\Broadcasting\BroadcastServiceProvider::class,
154+
Illuminate\Bus\BusServiceProvider::class,
155+
Illuminate\Cache\CacheServiceProvider::class,
156+
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
157+
Illuminate\Cookie\CookieServiceProvider::class,
158+
Illuminate\Database\DatabaseServiceProvider::class,
159+
Illuminate\Encryption\EncryptionServiceProvider::class,
160+
Illuminate\Filesystem\FilesystemServiceProvider::class,
161+
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
162+
Illuminate\Hashing\HashServiceProvider::class,
163+
Illuminate\Mail\MailServiceProvider::class,
164+
Illuminate\Notifications\NotificationServiceProvider::class,
165+
Illuminate\Pagination\PaginationServiceProvider::class,
166+
Illuminate\Pipeline\PipelineServiceProvider::class,
167+
Illuminate\Queue\QueueServiceProvider::class,
168+
Illuminate\Redis\RedisServiceProvider::class,
169+
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
170+
Illuminate\Session\SessionServiceProvider::class,
171+
Illuminate\Translation\TranslationServiceProvider::class,
172+
Illuminate\Validation\ValidationServiceProvider::class,
173+
Illuminate\View\ViewServiceProvider::class,
174+
175+
/*
176+
* Package Service Providers...
177+
*/
178+
179+
/*
180+
* Application Service Providers...
181+
*/
182+
App\Providers\AppServiceProvider::class,
183+
App\Providers\AuthServiceProvider::class,
184+
// App\Providers\BroadcastServiceProvider::class,
185+
App\Providers\EventServiceProvider::class,
186+
App\Providers\RouteServiceProvider::class,
187+
188+
],
189+
190+
/*
191+
|--------------------------------------------------------------------------
192+
| Class Aliases
193+
|--------------------------------------------------------------------------
194+
|
195+
| This array of class aliases will be registered when this application
196+
| is started. However, feel free to register as many as you wish as
197+
| the aliases are "lazy" loaded so they don't hinder performance.
198+
|
199+
*/
200+
201+
'aliases' => [
202+
203+
'App' => Illuminate\Support\Facades\App::class,
204+
'Artisan' => Illuminate\Support\Facades\Artisan::class,
205+
'Auth' => Illuminate\Support\Facades\Auth::class,
206+
'Blade' => Illuminate\Support\Facades\Blade::class,
207+
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
208+
'Bus' => Illuminate\Support\Facades\Bus::class,
209+
'Cache' => Illuminate\Support\Facades\Cache::class,
210+
'Config' => Illuminate\Support\Facades\Config::class,
211+
'Cookie' => Illuminate\Support\Facades\Cookie::class,
212+
'Crypt' => Illuminate\Support\Facades\Crypt::class,
213+
'DB' => Illuminate\Support\Facades\DB::class,
214+
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
215+
'Event' => Illuminate\Support\Facades\Event::class,
216+
'File' => Illuminate\Support\Facades\File::class,
217+
'Gate' => Illuminate\Support\Facades\Gate::class,
218+
'Hash' => Illuminate\Support\Facades\Hash::class,
219+
'Lang' => Illuminate\Support\Facades\Lang::class,
220+
'Log' => Illuminate\Support\Facades\Log::class,
221+
'Mail' => Illuminate\Support\Facades\Mail::class,
222+
'Notification' => Illuminate\Support\Facades\Notification::class,
223+
'Password' => Illuminate\Support\Facades\Password::class,
224+
'Queue' => Illuminate\Support\Facades\Queue::class,
225+
'Redirect' => Illuminate\Support\Facades\Redirect::class,
226+
'Redis' => Illuminate\Support\Facades\Redis::class,
227+
'Request' => Illuminate\Support\Facades\Request::class,
228+
'Response' => Illuminate\Support\Facades\Response::class,
229+
'Route' => Illuminate\Support\Facades\Route::class,
230+
'Schema' => Illuminate\Support\Facades\Schema::class,
231+
'Session' => Illuminate\Support\Facades\Session::class,
232+
'Storage' => Illuminate\Support\Facades\Storage::class,
233+
'URL' => Illuminate\Support\Facades\URL::class,
234+
'Validator' => Illuminate\Support\Facades\Validator::class,
235+
'View' => Illuminate\Support\Facades\View::class,
236+
237+
],
238+
239+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*.php

0 commit comments

Comments
 (0)