|
1 | 1 | # WordPress on App Engine Standard for PHP 7.2 |
2 | 2 |
|
3 | | -This is a simple command-line tool for downloading and configuring |
4 | | -WordPress on App Engine Standard for PHP 7.2. |
5 | | - |
6 | | -## Common Prerequisites |
7 | | - |
8 | | -* Create a new Cloud Project using the [Cloud Console][cloud-console] |
9 | | -* Enable Billing on that project |
10 | | -* Install [Google Cloud SDK][gcloud-sdk] |
11 | | -* [Enable Cloud SQL API][cloud-sql-api-enable] |
12 | | -* Install [Composer][composer] |
13 | | - |
14 | | -### Create and configure a Cloud SQL for MySQL instance |
15 | | - |
16 | | -> **Note**: In this guide, we use `wordpress` for the instance name and the database |
17 | | -name. We use `root` for the database user name. |
18 | | - |
19 | | -1. Create a new Cloud SQL for MySQL Second Generation instance with the following |
20 | | -command: |
21 | | - ```sh |
22 | | - $ gcloud sql instances create wordpress \ |
23 | | - --activation-policy=ALWAYS \ |
24 | | - --tier=db-n1-standard-1 |
25 | | - ``` |
26 | | - > **Note**: you can choose `db-f1-micro` or `db-g1-small` instead of |
27 | | - `db-n1-standard-1` for the Cloud SQL machine type, especially for the |
28 | | - development or testing purpose. However, those machine types are not |
29 | | - recommended for production use and are not eligible for Cloud SQL SLA |
30 | | - coverage. See our [Cloud SQL SLA](https://cloud.google.com/sql/sla) |
31 | | - for more details. |
32 | | - |
33 | | -1. Next, create the database you want your WordPress site to use: |
34 | | - ```sh |
35 | | - $ gcloud sql databases create wordpress --instance wordpress |
36 | | - ``` |
37 | | -1. Finally, change the root password for your instance: |
38 | | - ```sh |
39 | | - $ gcloud sql users set-password root \ |
40 | | - --host=% \ |
41 | | - --instance wordpress \ |
42 | | - --password=YOUR_INSTANCE_ROOT_PASSWORD # Don't use this password! |
43 | | - ``` |
44 | | - |
45 | | -## Create or Update a WordPress project for App Engine |
46 | | - |
47 | | -The `wp-gae` command provides a convenient way for you to either create |
48 | | -a new WordPress project or add the required configuration to an existing one. |
49 | | - |
50 | | -### Setup |
51 | | - |
52 | | -1. Download this repository and `cd` into the `appengine/php72/wordpress` directory |
53 | | - ```sh |
54 | | - $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git |
55 | | - $ cd php-docs-samples/appengine/php72/wordpress |
56 | | - ``` |
57 | | -1. Install the dependencies in this directory using composer |
58 | | - ```sh |
59 | | - $ composer install |
60 | | - ``` |
61 | | - > **Note** If you receive an error about extensions, install `phar` and `zip` PHP |
62 | | - extensions and retry. |
63 | | - |
64 | | -### Create a new WordPress Project |
65 | | - |
66 | | -To download WordPress and set it up for Google Cloud, run the `create` command: |
67 | | - |
68 | | -```sh |
69 | | -$ php vendor/bin/wp-gae create |
70 | | -``` |
71 | | - |
72 | | -The command asks you several questions, please answer them. Then you'll have a |
73 | | -new WordPress project. By default it will create `my-wordpress-project` in the |
74 | | -current directory. |
75 | | -
|
76 | | -> **Note**: To determine the region your database is in, run `gcloud sql instances describe wordpress` |
77 | | -
|
78 | | -### Update an existing WordPress Project |
79 | | -
|
80 | | -If you are migrating an existing project to Google Cloud, you can use the |
81 | | -`update` command: |
82 | | -
|
83 | | -```sh |
84 | | -$ php vendor/bin/wp-gae update path/to/your-wordpress-site |
85 | | -``` |
86 | | -
|
87 | | -The command asks you several questions, please answer them. This will copy |
88 | | -[a few files][wp-gcp-files] and write the proper configuration. Then your |
89 | | -WordPress project will be ready to deploy to Google Cloud! |
90 | | -
|
91 | | -## Deploy to Google Cloud |
92 | | -
|
93 | | -`cd` into the root of your WordPress project. |
94 | | -
|
95 | | -```sh |
96 | | -$ cd my-wordpress-project |
97 | | -``` |
98 | | -
|
99 | | -Run the following command to deploy your project to App Engine: |
100 | | -
|
101 | | -```sh |
102 | | -$ gcloud app deploy app.yaml cron.yaml |
103 | | -``` |
104 | | -
|
105 | | -Now you can access your site, and continue the installation step! The URL is |
106 | | -https://PROJECT_ID.appspot.com/ |
107 | | -
|
108 | | -### Enable the Google Cloud Storage plugin |
109 | | -
|
110 | | -To use the [Google Cloud Storage plugin][gcs-plugin] for media uploads, follow |
111 | | -these steps. |
112 | | -
|
113 | | -1. Configure the App Engine default GCS bucket for later use. The default App |
114 | | - Engine bucket is named YOUR_PROJECT_ID.appspot.com. Change the default Access |
115 | | - Control List (ACL) of that bucket as follows: |
116 | | - ``` |
117 | | - $ gsutil defacl ch -u AllUsers:R gs://YOUR_PROJECT_ID.appspot.com |
118 | | - ``` |
119 | | -1. Go to the Dashboard at https://PROJECT_ID.appspot.com/wp-admin. On the |
120 | | - Plugins page, activate the `Google Cloud Storage plugin`. |
121 | | -1. In the plugins Settings page, set your Bucket name to the bucket you |
122 | | - configured in Step 1. |
123 | | -
|
124 | | -After activating the plugin, try uploading a media object in a new post |
125 | | -and confirm the image is uploaded to the GCS bucket by visiting the |
126 | | -[Google Cloud console's Storage page][cloud-storage-console]. |
127 | | - |
128 | | -## Local Development |
129 | | - |
130 | | -To access this MySQL instance, use Cloud SQL Proxy. [Download][cloud-sql-proxy-download] |
131 | | -it to your local computer and make it executable. |
132 | | - |
133 | | -Go to the [the Credentials section][credentials-section] of your project in the |
134 | | -Console. Click 'Create credentials' and then click 'Service account key.' For |
135 | | -the Service account, select 'App Engine app default service account.' Then |
136 | | -click 'Create' to create and download the JSON service account key to your |
137 | | -local machine. Save it to a safe place. |
138 | | -
|
139 | | -Run the proxy by the following command: |
140 | | -
|
141 | | -```sh |
142 | | -$ cloud_sql_proxy \ |
143 | | - -dir /cloudsql \ |
144 | | - -instances=YOUR_PROJECT_ID:us-central1:wordpress \ |
145 | | - -credential_file=/path/to/YOUR_SERVICE_ACCOUNT_JSON_FILE.json |
146 | | -``` |
147 | | -
|
148 | | -> **Note**: Make sure to run the command under a user with write access in the `/cloudsql` directory. This proxy will use this folder to create a unix socket. |
149 | | -
|
150 | | -Now you can access the Cloud SQL instance with the MySQL client in a separate |
151 | | -command line tab. |
152 | | -
|
153 | | -``` |
154 | | -$ mysql --socket /cloudsql/YOUR_PROJECT_ID:us-central1:wordpress -u root -p |
155 | | -mysql> use database wordpress; |
156 | | -mysql> show tables; |
157 | | -mysql> exit |
158 | | -``` |
159 | | -
|
160 | | -## Various Workflows |
161 | | -
|
162 | | -### Install and Update WordPress, Plugins, and Themes |
163 | | -
|
164 | | -Because the `wp-content` directory on the server is read-only, you have |
165 | | -to perform all code updates locally. Run WordPress locally and update the |
166 | | -plugins and themes in the local Dashboard, deploy the code to production, then |
167 | | -activate them in the production Dashboard. You can also use the `wp-cli` utility |
168 | | -as follows (be sure to keep the Cloud SQL proxy running): |
169 | | -
|
170 | | -``` |
171 | | -# Install the wp-cli utility |
172 | | -$ composer require wp-cli/wp-cli-bundle |
173 | | -# Now you can run the "wp" command to update Wordpress itself |
174 | | -$ vendor/bin/wp core update --path=wordpress |
175 | | -# You can also update all the plugins and themes |
176 | | -$ vendor/bin/wp plugin update --all |
177 | | -$ vendor/bin/wp theme update --all |
178 | | -``` |
179 | | -
|
180 | | -If you get the following error: |
181 | | -
|
182 | | -```sh |
183 | | -Failed opening required 'google/appengine/api/urlfetch_service_pb.php' |
184 | | -``` |
185 | | -
|
186 | | -You can set a `WP_CLI_PHP_ARGS` environment variable to add |
187 | | -`include_path` PHP configuration for wp-cli. |
188 | | -
|
189 | | -```sh |
190 | | -$ export WP_CLI_PHP_ARGS='-d include_path=vendor/google/appengine-php-sdk' |
191 | | -``` |
192 | | -
|
193 | | -Then try the above commands again. |
194 | | -
|
195 | | -### Remove Plugins and Themes |
196 | | -
|
197 | | -First deactivate them in the production Dashboard, then remove them |
198 | | -completely locally. The next deployment will remove those files from |
199 | | -the production environment. |
200 | | -
|
201 | | -[sql-settings]: https://console.cloud.google.com/sql/instances |
202 | | -[mysql-client]: https://dev.mysql.com/doc/refman/5.7/en/mysql.html |
203 | | -[composer]: https://getcomposer.org/ |
204 | | -[cloud-console]: https://console.cloud.google.com/ |
205 | | -[cloud-storage-console]: https://console.cloud.google.com/storage |
206 | | -[cloud-sql-api-enable]: https://console.cloud.google.com/flows/enableapi?apiid=sqladmin |
207 | | -[app-engine-setting]: https://console.cloud.google.com/appengine/settings |
208 | | -[gcloud-sdk]: https://cloud.google.com/sdk/ |
209 | | -[cloud-sql-proxy-download]: https://cloud.google.com/sql/docs/mysql/connect-external-app#install |
210 | | -[credentials-section]: https://console.cloud.google.com/apis/credentials/ |
211 | | -[gcs-plugin]: https://wordpress.org/plugins/gcs/ |
212 | | -[wp-gcp-files]: https://github.com/GoogleCloudPlatform/php-tools/tree/master/src/Utils/WordPress/files |
| 3 | +Please refer to [the official tutorial](https://cloud.google.com/community/tutorials/run-wordpress-on-appengine-standard) for running the code in this sample. |
0 commit comments