How to deploy a Laravel web app on Google App Engine

Andrei Iordache
Dec 3, 2018 · 11 min read
Image for post
Image for post

Prerequisite reading (you can skip to Preparing for the deploy)

Preparing for the deploy

Preparing your project

TUTORIALDIR= C:/Code/updivision-laravel-demo/git clone https://github.com/Updivision/laravel-demo-google-cloud.git $TUTORIALDIRcd $TUTORIALDIRgit checkout phase0-helloworld
runtime: php  # language of the app
env: flex # let app engine know we use flexible environment
runtime_config:
document_root: public #folder where index.php is
# Ensure we skip ".env", which is only for local development
skip_files:
- .env #we want to skip this to make sure we don’t mess stuff up on the server
env_variables:
# Put production environment variables here.
APP_ENV: local # or production
APP_DEBUG : true # or false
APP_KEY: base64:FqwXmLtL6szdWqIVydb7nKs2eyvHib4lf6d5l6A/XW4=
#go to generate app key paragraf in this tutorial
CACHE_DRIVER: database# instead of putting the cache in the database I recommend using redis
SESSION_DRIVER: database #or file since both work
APP_LOG: daily
APP_TIMEZONE: UTC #your timezone of choice
# follow the part of the tutorial on setting up your SQL database
DB_CONNECTION: mysql
DB_HOST: localhost
DB_DATABASE: instance_id
DB_USERNAME: database_user_name
DB_PASSWORD: database_password
DB_SOCKET: /cloudsql/instance_name
QUEUE_DRIVER: database #in case you execute queued jobs MAIL_DRIVER: smtp
MAIL_HOST: smtp.sparkpostmail.com
MAIL_PORT: 587
MAIL_USERNAME: sparkpost_username
MAIL_PASSWORD: ****************
LOG_DELETE: true # this is a parameter added by us in the project .env file. You can add here any setting you would add to your .env file GOOGLE_VISION_PROJECT_ID : project_id#we need this for the flex environment
beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
# e.g. "project:region:cloudsql-instance"
cloud_sql_instances: project:cloudsql-instance
php artisan key:generate --show
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "7.1.*",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0",
"symfony/thanks": "^1.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"@php artisan optimize",
"chmod -R 755 bootstrap\/cache"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"@php artisan optimize"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
descriptor:      [\blog\app.yaml]
source: [\blog]
target project: [updivision-laravel-demo-197514]
target service: [default]
target version: [20180309t203424]
target url: [https://updivision-laravel-demo-197514.appspot.com]
Do you want to continue (Y/n)? Y
Image for post
Image for post

Setting up cron jobs

cron:
- description: "daily laravel cron"
url: /scheduler
schedule: every 1 mins
retry_parameters:
min_backoff_seconds: 2.5
max_doublings: 5
Route::get('scheduler', function (){
\Illuminate\Support\Facades\Artisan::call('schedule:run');
});

Setting up a SQL database

Image for post
Image for post
beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
# e.g. "project:region:cloudsql-instance"
cloud_sql_instances: instance_connection_name
DB_CONNECTION: mysql
DB_HOST: localhost
DB_PORT: 3306
DB_DATABASE: instance_id
DB_USERNAME: root
DB_PASSWORD: ***************
DB_SOCKET: /cloudsql/instance_connection_name
Image for post
Image for post

Importing a fully migrated database with data in it

mysqldump -uuser -p your_database > your_database_dump.sql
Image for post
Image for post
Image for post
Image for post

View data

Image for post
Image for post
Image for post
Image for post

Running migrations and seeders

cloud_sql_proxy_x64.exe -instances=your_instance_connection_nameive=tcp:3306 -credential_file=path/to/service_account_file &
php artisan migrate --seed
php artisan migrate db:seed --class=SeederClass

Setting up storage

'google' => [ 
'driver' => 's3',
'key' => 'xxx',
'secret' => 'xxx',
'bucket' => 'qrnotesfiles',
'base_url'=>'https://storage.googleapis.com' ]

HackerNoon.com

#BlackLivesMatter

Sign up for Get Better Tech Emails via HackerNoon.com

By HackerNoon.com

how hackers start their afternoons. the real shit is on hackernoon.com. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Andrei Iordache

Written by

CEO at UPDIVISION.com • We develop apps that can turn into beautiful unicorns.

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Andrei Iordache

Written by

CEO at UPDIVISION.com • We develop apps that can turn into beautiful unicorns.

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store