Adding VPC connector in Laravel with app engine – GCP

This article shows how to add a VPC (Virtual Private Cloud) connector to your Laravel project in App engine with Google Cloud Platform (GCP).

You must first create a Serverless VPC Access connector to handle communication to your VPC network. After creating it, you can configure your App Engine service to use the connector.

For detailed instructions on creating a Serverless VPC Access connectors, you can refer to the Official Google Cloud article here.

After you have created a Serverless VPC Access connector, you can configure it in your app engine service, which is your Laravel project.

Do the following changes in your app.yaml file present in your project source/app engine service account.

1. Add vpc_access_connector element

Add the following element in your Laravel project/app engine service’s app.yaml file:

vpc_access_connector: 
 name: projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]

PROJECT_ID = Google Cloud project ID

REGION = connector’s region 

CONNECTOR_NAME = VPC connector’s name.


2. Use private IP of your SQL in DB_HOST

Add/Replace the DB_HOST with private IP of your SQL’s instance. You can find the private IP under the instance properties in SQL page.

env_variables:
 DB_HOST: PRIVATE_IP



3. Remove DB_SOCKET if you are using it.

The connection will going to fail if you are trying to connect database with DB socket for VPC connection.

And here you go, its easy as fast to setup VPC connector in your Laravel project with Google cloud App engine service.



Post your queries if any in comment…

Leave a Comment

Your email address will not be published. Required fields are marked *