Google Cloud App Engine

Deploy Laravel on Google App Engine – Flexible

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Deploy Laravel on Google App Engine – Flexible and connect with Google Cloud SQL with Cloud SQL Proxy.

This guide demonstrates how to set up deploy your first Laravel app in App Engine Flexible Environment with Cloud SQL.

Not using App Engine? Choose a different Category:

App Engine – Flex


  1. Create a project in the Google Cloud Platform Console.
  2. Enable billing for your project.
  3. Install and initialize the Google Cloud SDK.
  4. Create a Cloud SQL Second Generation Instance.
  5. Composer installed on your local computer.

Local Laravel Set Up

Create a directory in your local computer and install the Laravel installer.

mkdir my-project
composer global require laravel/installer

Create a new Laravel application using the laravel new command.

cd my-project
laravel new my-app

Now Laravel will be installed inside the my-app directory.

You can verify the installation with the following command.

cd my-app
php artisan serve

Visit http://localhost:8000 on your web browser to see the Laravel Welcome page.

Set up Laravel for App Engine

01. Generate application key with the following command.

php artisan key:generate --show

02. Create an app.yaml file with the following contents:

Replace YOUR_APP_KEY with the application key you have generated in the above step.

runtime: php
env: flex

document_root: public

- .env

APP_LOG: errorlog

03. Add the following lines inside scripts in your composer.json

Edit the composer.json and add the below code before.

"post-install-cmd": [
"chmod -R 755 bootstrap\/cache",
"php artisan cache:clear"

So your composer.json scripts json object will look like this.

"scripts": {
"post-autoload-dump": [
"@php artisan package:discover --ansi"
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
"post-install-cmd": [
"chmod -R 755 bootstrap\/cache",
"php artisan cache:clear"

Enable APIs and Create New Service account

Go to APIs and Services and click Enable APIs and Services and enable Cloud SQL API and Cloud SQL Admin API

Go to IAM & Admin >> Service accounts and click Create service account

In step 1

Enter Service account Name

Click Create

In step 2

Select Role

Cloud SQL >> Cloud SQL Client
Project >> Editor

Click Continue

In step 3

Click Create Key

Choose Key type as JSON

Click Create

Install Cloud SQL Proxy in Local Machine

Follow the instructions to install the Cloud SQL proxy client on your local machine. The Cloud SQL proxy is used to connect to your Cloud SQL instance when running locally.

Start the Cloud SQL proxy and replace CLOUDSQL_CONNECTION_NAME with the connection name of your Cloud SQL Instance.

You can get the connection name from your Cloud SQL Dashboard.

Cloud SQL Connection Name
./cloud_sql_proxy -instances=CLOUDSQL_CONNECTION_NAME=tcp:3306

If you are using windows machine you need to update the ./cloud_sql_proxy with the path of the downloaded proxy.

Run Migrations for Laravel

Once the Proxy is started you will something similar to this.

2019/03/06 15:48:17 Listening on for CLOUDSQL_CONNECTION_NAME
2019/03/06 15:48:17 Ready for new connections

Now edit your .env file and update the database details.


Important: Open a new command prompt and navigate to your Laravel’s root directory and run the database migrations for Laravel.

php artisan session:table
php artisan migrate --force

If the migrations are completed successfully, you will see the output similar to the one below.

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrating: 2019_03_06_101455_create_sessions_table
Migrated: 2019_03_06_101455_create_sessions_table

Great! Now you can deploy your Laravel application to App Engine.

Deploy Laravel to App Engine

Edit your app.yaml and update the Cloud SQL details.

runtime: php
env: flex

document_root: public

- .env

APP_LOG: errorlog
CACHE_DRIVER: database
DB_HOST: localhost

Once done, run the below command to deploy the app on App Engine.

gcloud app deploy

Once the deployment is completed check this url ( to see the Laravel Welcome page.

Laravel Welcome Page


Now you have learned how to deploy your Laravel application on Google App Engine – Flexible Environment.

Thanks for your time. If you face any problem or any feedback, just leave a comment below.


  1. Dear Sir:
    Thanks for your article it’s very useful , I have one question, the app engine is flexible ,but the Cloud SQL is not , will the CLOUD SQL be the bottle neck for the performance in high loading ? thanks ~~

    • Cloudbooklet Reply

      You are welcome, you can enable high-availability in Cloud SQL and also increase the machine type in case of high traffic

  2. Jorge Garrido Reply

    Hi, great Article!!!! congratulations.

    I’ld like to know how to execute “php artisan passport:install” on deploying stage or to know the way to execute the above command, because I’ve read in diferents articles that the cloud sql is not accessible from de GAE on deployment stage. If I apply the “php artisan passport:install” command on a RUN sentence in Dockerfile I get “SQLSTATE[HY000] [2002] No such file or directory” error type. I also tried writing in the post-install-cmd section in the composer.json file. I get the same error. I think that during the building or deployment stage the Cloud SQL environment was not available. Then I read this an article here, , where I confirmed my assumption .

  3. I have followed all the steps listed here to deploy my laravel 5.4 application and i’m getting “Whoops, looks like something went wrong.” can someone help please.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.