|
| 1 | +# Google Datastore PHP Sample Application |
| 2 | + |
| 3 | +A simple app to make calls to the Datastore API |
| 4 | + |
| 5 | +## Register your application |
| 6 | + |
| 7 | +- Go to |
| 8 | + [Google Developers Console](https://console.developers.google.com/project) |
| 9 | + and create a new project. This will automatically enable an App |
| 10 | + Engine application with the same ID as the project. |
| 11 | + |
| 12 | +- Enable the "Google Cloud Datastore API" under "APIs & auth > APIs." |
| 13 | + |
| 14 | +- edit `app.yaml` and change `MY_GCP_PROJECT_ID` to your App Engine project ID |
| 15 | + |
| 16 | +- For local development also follow the instructions below. |
| 17 | + |
| 18 | + - Go to "Credentials" and create a new Service Account. |
| 19 | + |
| 20 | + - Select "Generate new JSON key", then download a new JSON file. |
| 21 | + |
| 22 | + - Set the following environment variables: |
| 23 | + |
| 24 | + - `GOOGLE_APPLICATION_CREDENTIALS`: the file path to the downloaded JSON file. |
| 25 | + - `GCP_PROJECT_ID`: Your app engine project ID |
| 26 | + |
| 27 | +## Prerequisites |
| 28 | + |
| 29 | +- Install [`composer`](https://getcomposer.org) |
| 30 | +- Install Google API client library for PHP by running: |
| 31 | + |
| 32 | +```sh |
| 33 | +composer install |
| 34 | +``` |
| 35 | + |
| 36 | +## Run locally |
| 37 | + |
| 38 | +you can run locally using PHP's built-in web server: |
| 39 | + |
| 40 | +```sh |
| 41 | +cd php-docs-samples/datastore |
| 42 | +export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json |
| 43 | +export GCP_PROJECT_ID=my-project-id |
| 44 | +php -S localhost:8080 -t web/ |
| 45 | +``` |
| 46 | + |
| 47 | +Now you can view the app running at [http://localhost:8080](http://localhost:8080) |
| 48 | +in your browser. |
| 49 | + |
| 50 | +## Deploy to App Engine |
| 51 | + |
| 52 | +**Prerequisites** |
| 53 | + |
| 54 | +- Install the App Engine PHP SDK. |
| 55 | + We recommend you install |
| 56 | + [Cloud SDK](https://developers.google.com/cloud/sdk/) rather than |
| 57 | + just installing App Engine SDK. |
| 58 | + |
| 59 | +**Deploy with gcloud** |
| 60 | + |
| 61 | +``` |
| 62 | +$ gcloud preview app deploy app.yaml --set-default --project YOUR_GCP_PROJECT_ID |
| 63 | +``` |
| 64 | + |
| 65 | +Then access the following URL: |
| 66 | + https://{YOUR_GCP_PROJECT_ID}.appspot.com/ |
| 67 | + |
| 68 | +### Run for App Engine locally |
| 69 | + |
| 70 | +``` |
| 71 | +$ dev_appserver.py -A your-project-id . |
| 72 | +``` |
| 73 | + |
| 74 | +## Contributing changes |
| 75 | + |
| 76 | +* See [CONTRIBUTING.md](../CONTRIBUTING.md) |
| 77 | + |
| 78 | +## Licensing |
| 79 | + |
| 80 | +* See [LICENSE](../LICENSE) |
| 81 | + |
| 82 | + |
0 commit comments