|
| 1 | +# Cloud SQL & Google App Engine |
| 2 | + |
| 3 | +This sample application demonstrates how to use [Cloud SQL with Google App Engine](https://cloud.google.com/appengine/docs/php/cloud-sql/). |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +Before you can run or deploy the sample, you will need to do the following: |
| 8 | + |
| 9 | +1. Create a [Memorystore instance][memorystore_create]. You can do this from the |
| 10 | + [Cloud Console](https://console.developers.google.com) or via the |
| 11 | + [Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK use the |
| 12 | + following command: |
| 13 | + |
| 14 | + $ gcloud beta redis instances create YOUR_INSTANCE_NAME --region=REGION_ID |
| 15 | + |
| 16 | +1. Update the environment variables `REDIS_HOST` and `REDIS_PORT` in `app.yaml` |
| 17 | + with your configuration values. These values are used when the application is |
| 18 | + deployed. Run the following command to get the values for your isntance: |
| 19 | + |
| 20 | + $ gcloud beta redis instances describe YOUR_INSTANCE_NAME --region=REGION_ID |
| 21 | + |
| 22 | +[memorystore_create]: https://cloud.google.com/memorystore/docs/redis/creating-managing-instances |
| 23 | + |
| 24 | +## Run locally |
| 25 | + |
| 26 | +You can connect to a local database instance by setting the `REDIS_` environment |
| 27 | +variables to your local instance. Alternatively, you can set them to your Cloud |
| 28 | +Memorystore instance, but you will need to create a firewall rule for this, |
| 29 | +which may be a safety concern. |
| 30 | + |
| 31 | +```sh |
| 32 | +cd php-docs-samples/appengine/php72/memorystore |
| 33 | + |
| 34 | +# set local connection parameters |
| 35 | +export REDIS_HOST=127.0.0.1 |
| 36 | +export REDIS_PORT=6379 |
| 37 | + |
| 38 | +php -S localhost:8080 |
| 39 | +``` |
| 40 | + |
| 41 | +> be sure the `REDIS_` environment variables are appropriate for your Redis |
| 42 | + instance. |
| 43 | + |
| 44 | +Now you can view the app running at [http://localhost:8080](http://localhost:8080) |
| 45 | +in your browser. |
| 46 | + |
| 47 | +## Deploy to App Engine |
| 48 | + |
| 49 | +**Prerequisites** |
| 50 | + |
| 51 | +- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/). |
| 52 | + |
| 53 | +**Deploy with gcloud** |
| 54 | + |
| 55 | +``` |
| 56 | +gcloud config set project YOUR_PROJECT_ID |
| 57 | +gcloud app deploy |
| 58 | +gcloud app browse |
| 59 | +``` |
| 60 | + |
| 61 | +The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/` |
| 62 | +in your browser. |
0 commit comments