|
1 | 1 | # Cloud SQL on App Engine Standard for PHP 7.2
|
2 | 2 |
|
3 |
| -This sample application demonstrates how to use [Cloud SQL on App Engine for PHP 7.2](https://cloud.google.com/appengine/docs/standard/php7/using-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 [Second Generation Cloud SQL](https://cloud.google.com/sql/docs/create-instance) |
10 |
| - instance. You can do this from the [Cloud Console](https://console.developers.google.com) |
11 |
| - or via the [Cloud SDK](https://cloud.google.com/sdk). To create it via the |
12 |
| - SDK use the following command: |
13 |
| - |
14 |
| - $ gcloud sql instances create YOUR_INSTANCE_NAME |
15 |
| - |
16 |
| -1. Create a database for the sample, for instance `cloudsql_sample`: |
17 |
| - |
18 |
| - $ gcloud sql databases create cloudsql_sample --instance=YOUR_INSTANCE_NAME |
19 |
| - |
20 |
| -1. Set the root password on your Cloud SQL instance: |
21 |
| - |
22 |
| - $ gcloud sql users set-password root --host % --instance YOUR_INSTANCE_NAME --password YOUR_INSTANCE_ROOT_PASSWORD |
23 |
| - |
24 |
| -1. Clone the repository and CD into the directory for this sample |
25 |
| - |
26 |
| - git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git |
27 |
| - cd php-docs-samples/appengine/php72/cloudsql |
28 |
| - |
29 |
| -1. Update `app.yaml` (or if you're using CloudSQL with PostgreSQL, update `app-postgres.yaml`) |
30 |
| - with your configuration values. These values are used when the application is deployed: |
31 |
| - |
32 |
| - env_variables: |
33 |
| - # Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the |
34 |
| - # values obtained when configuring your Cloud SQL instance. |
35 |
| - CLOUDSQL_USER: USER |
36 |
| - CLOUDSQL_PASSWORD: PASSWORD |
37 |
| - CLOUDSQL_DSN: "mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME" |
38 |
| - |
39 |
| -## Deploy to App Engine |
40 |
| - |
41 |
| -**Prerequisites** |
42 |
| - |
43 |
| -- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/). |
44 |
| - |
45 |
| -**Deploy with gcloud** |
46 |
| - |
47 |
| -If you haven't already, authenticate gcloud using your Google account and |
48 |
| -configure gcloud to use your project ID: |
49 |
| - |
50 |
| -```sh |
51 |
| -gcloud auth login |
52 |
| -gcloud config set project YOUR_PROJECT_ID |
53 |
| -``` |
54 |
| - |
55 |
| -Next, deploy your application: |
56 |
| - |
57 |
| -```sh |
58 |
| -gcloud app deploy |
59 |
| -gcloud app browse |
60 |
| -``` |
61 |
| - |
62 |
| -The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/` |
63 |
| -in your browser. |
64 |
| - |
65 |
| -If your CloudSQL instance is running PostgreSQL instead of MySQL, deploy using |
66 |
| -`app-postgres.yaml` instead: |
67 |
| - |
68 |
| -```sh |
69 |
| -gcloud app deploy app-postgres.yaml |
70 |
| -``` |
71 |
| - |
72 |
| -## Run locally |
73 |
| - |
74 |
| -To run the sample locally, you will want to use the [CloudSQL proxy](https://cloud.google.com/sql/docs/mysql/sql-proxy#install). |
75 |
| -The CloudSQL proxy allows you to connect to your CloudSQL instance locally without |
76 |
| -having to set up firewall rules. |
77 |
| - |
78 |
| -```sh |
79 |
| -./cloud_sql_proxy \ |
80 |
| - -instances YOUR_INSTANCE_NAME \ |
81 |
| - -dir /cloudsql \ |
82 |
| - -credentials /path/to/your_service_account_credentials.json |
83 |
| -``` |
84 |
| - |
85 |
| -Then set your CloudSQL environment variables and run the PHP web server: |
86 |
| - |
87 |
| -```sh |
88 |
| -# set local connection parameters (but replace the uppercase words!) |
89 |
| -export CLOUDSQL_USERNAME=USER |
90 |
| -export CLOUDSQL_PASSWORD=PASSWORD |
91 |
| -export CLOUDSQL_DSN="mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME" |
92 |
| - |
93 |
| -php -S localhost:8080 |
94 |
| -``` |
95 |
| - |
96 |
| -Now you can view the app running at [http://localhost:8080](http://localhost:8080) |
97 |
| -in your browser. |
| 3 | +This sample has been moved to [cloud_sql](../../../cloud_sql). |
0 commit comments