@@ -10,33 +10,28 @@ Before you can run or deploy the sample, you will need to do the following:
1010
1111 $ gcloud sql instances create YOUR_INSTANCE_NAME
1212
13- 1 . Set the root password on your Cloud SQL instance:
13+ 1 . Create a database for the sample, for instance ` cloudsql_sample ` :
1414
15- $ gcloud sql instances set-root-password YOUR_INSTANCE_NAME --password YOUR_INSTANCE_ROOT_PASSWORD
15+ $ gcloud sql databases create cloudsql_sample --instance=YOUR_INSTANCE_NAME
1616
17- 1 . Update the connection string in ` app.yaml ` with your configuration values. These values are used when the application is deployed.
17+ 1 . Set the root password on your Cloud SQL instance:
1818
19- ## Run locally
19+ $ gcloud sql users set-password root --host % --instance YOUR_INSTANCE_NAME --password YOUR_INSTANCE_ROOT_PASSWORD
2020
21- You can connect to a local database instance by setting the ` CLOUDSQL_ ` environment variables
22- to your local instance. Alternatively, you can set them to your Cloud instances, but you will need
23- to create a firewall rule for this, which may be a safety concern.
21+ 1 . Clone the repository and CD into the directory for this sample
2422
25- ``` sh
26- cd php-docs-samples/appengine/php72/cloudsql
23+ git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git
24+ cd php-docs-samples/appengine/php72/cloudsql
2725
28- # set local connection parameters
29- export CLOUDSQL_USERNAME=root
30- export CLOUDSQL_PASSWORD=
31- export CLOUDSQL_DSN=" mysql:host=localhost;dbname=guestbook"
26+ 1 . Update ` app.yaml ` (or if you're using CloudSQL with PostgreSQL, update ` app-postgres.yaml ` )
27+ with your configuration values. These values are used when the application is deployed:
3228
33- php -S localhost:8080
34- ```
35-
36- > be sure the ` CLOUDSQL_ ` environment variables are appropriate for your MySQL or PostgreSQL instance.
37-
38- Now you can view the app running at [ http://localhost:8080 ] ( http://localhost:8080 )
39- in your browser.
29+ env_variables:
30+ # Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the
31+ # values obtained when configuring your Cloud SQL instance.
32+ CLOUDSQL_USER: USER
33+ CLOUDSQL_PASSWORD: PASSWORD
34+ CLOUDSQL_DSN: "mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME"
4035
4136## Deploy to App Engine
4237
@@ -46,11 +41,54 @@ in your browser.
4641
4742** Deploy with gcloud**
4843
49- ```
44+ If you haven't already, authenticate gcloud using your Google account and
45+ configure gcloud to use your project ID:
46+
47+ ``` sh
48+ gcloud auth login
5049gcloud config set project YOUR_PROJECT_ID
50+ ```
51+
52+ Next, deploy your application:
53+
54+ ``` sh
5155gcloud app deploy
5256gcloud app browse
5357```
5458
5559The last command will open ` https://{YOUR_PROJECT_ID}.appspot.com/ `
5660in your browser.
61+
62+ If your CloudSQL instance is running PostgreSQL instead of MySQL, deploy using
63+ ` app-postgres.yaml ` instead:
64+
65+ ``` sh
66+ gcloud app deploy app-postgres.yaml
67+ ```
68+
69+ ## Run locally
70+
71+ To run the sample locally, you will want to use the [ CloudSQL proxy] ( https://cloud.google.com/sql/docs/mysql/sql-proxy#install ) .
72+ The CloudSQL proxy allows you to connect to your CloudSQL instance locally without
73+ having to set up firewall rules.
74+
75+ ``` sh
76+ ./cloud_sql_proxy \
77+ -instances YOUR_INSTANCE_NAME \
78+ -dir /cloudsql \
79+ -credentials /path/to/your_service_account_credentials.json
80+ ```
81+
82+ Then set your CloudSQL environment variables and run the PHP web server:
83+
84+ ``` sh
85+ # set local connection parameters (but replace the uppercase words!)
86+ export CLOUDSQL_USERNAME=USER
87+ export CLOUDSQL_PASSWORD=PASSWORD
88+ export CLOUDSQL_DSN=" mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME"
89+
90+ php -S localhost:8080
91+ ```
92+
93+ Now you can view the app running at [ http://localhost:8080 ] ( http://localhost:8080 )
94+ in your browser.
0 commit comments