Skip to content

Commit df71c40

Browse files
author
Takashi Matsuo
committed
Fixes for WordPress on App Engine standard.
1 parent a5fff75 commit df71c40

File tree

5 files changed

+48
-30
lines changed

5 files changed

+48
-30
lines changed

appengine/wordpress/README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,14 @@ name, the database name, and the user name.
5151

5252
### Create and configure a Cloud SQL 1st generation instance(for standard environment)
5353

54-
You can create a new Cloud SQL First Generation instance with the
55-
following command:
56-
57-
```
58-
$ gcloud sql instances create wp
59-
```
60-
61-
Then change the root password for your instance:
62-
63-
```
64-
$ gcloud sql instances set-root-password wp \
65-
--password YOUR_INSTANCE_ROOT_PASSWORD # Don't use this password!
66-
```
67-
6854
Go to the [SQL settings in the Cloud Console][sql-settings] and create
69-
a database named `wp`. Also create the `wp` database in the local
70-
mysql server. The local mysql instance is required to run `wp-cli`
71-
tool for installing/upgrading plugins and themes.
55+
an instance `wp` and database named `wp`. Go to the Access Control ->
56+
Users, then change the password for `root@localhost`. You will use
57+
this password for accessing from App Engine application.
58+
59+
Also create the `wp` database in the local mysql server. The local
60+
mysql instance is required to run `wp-cli` tool for
61+
installing/upgrading plugins and themes.
7262

7363
### Create and configure a Cloud SQL 2nd generation instance(for flexible environment)
7464

appengine/wordpress/src/WordPressSetup.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ protected function configure()
9898
'Cloud SQL database password',
9999
''
100100
)
101+
->addOption(
102+
'local_db_user',
103+
null,
104+
InputOption::VALUE_OPTIONAL,
105+
'Local SQL database username',
106+
''
107+
)
108+
->addOption(
109+
'local_db_password',
110+
null,
111+
InputOption::VALUE_OPTIONAL,
112+
'Local SQL database password',
113+
''
114+
)
101115
->addOption(
102116
'wordpress_url',
103117
null,
@@ -155,7 +169,7 @@ protected function askParameters(
155169
}
156170
$q = new Question(
157171
'Please enter ' . $key . $note . ': ', $default);
158-
if ($key === 'db_password') {
172+
if (strpos($key, 'password') !== false) {
159173
$q->setHidden(true);
160174
$q->setHiddenFallback(false);
161175
}
@@ -249,12 +263,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
249263
$dir . '/wordpress/wp-content/object-cache.php'
250264
);
251265

252-
$configKeys = array(
266+
$keys = array(
253267
'project_id' => '',
254268
'db_instance' => 'wp',
255269
'db_name' => 'wp',
256270
'db_user' => 'wp',
257-
'db_password' => ''
271+
'db_password' => '',
258272
);
259273
if ($env === self::STANDARD_ENV) {
260274
$copyFiles = array(
@@ -287,7 +301,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
287301
$templateDir = __DIR__ . '/files/flexible';
288302
}
289303
$params = array();
290-
$this->askParameters($configKeys, $params, $input, $output, $helper);
304+
$this->askParameters($keys, $params, $input, $output, $helper);
305+
$q = new ConfirmationQuestion(
306+
'Do you want to use the same db user and password for '
307+
. 'local run? (Y/n)',
308+
true
309+
);
310+
if ($helper->ask($input, $output, $q)) {
311+
$params['local_db_user'] = $params['db_user'];
312+
$params['local_db_password'] = $params['db_password'];
313+
} else {
314+
$keys = array(
315+
'local_db_user' => 'wp',
316+
'local_db_password' => '',
317+
);
318+
$this->askParameters($keys, $params, $input, $output, $helper);
319+
}
291320
$this->addAuthKeys($params);
292321
$project->copyFiles($templateDir, $copyFiles, $params);
293322
if (!$this->report($output, $project)) {

appengine/wordpress/src/files/flexible/wp-config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
/** The name of the database for WordPress */
8686
define('DB_NAME', '{{db_name}}');
8787
/** MySQL database username */
88-
define('DB_USER', '{{db_user}}');
88+
define('DB_USER', '{{local_db_user}}');
8989
/** MySQL database password */
90-
define('DB_PASSWORD', '{{db_password}}');
90+
define('DB_PASSWORD', '{{local_db_password}}');
9191
define('DB_HOST', '127.0.0.1');
9292
}
9393

appengine/wordpress/src/files/standard/wp-config.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,17 @@
5252
if ($onGae) {
5353
/** The name of the Cloud SQL database for WordPress */
5454
define('DB_NAME', '{{db_name}}');
55-
/** Live environment Cloud SQL login and SITE_URL info */
56-
/** From App Engine, the password is not required, so leave it blank here */
55+
/** Production login info */
5756
define('DB_HOST', ':/cloudsql/{{project_id}}:{{db_instance}}');
58-
define('DB_USER', 'root');
59-
define('DB_PASSWORD', '');
57+
define('DB_USER', '{{db_user}}');
58+
define('DB_PASSWORD', '{{db_password}}');
6059
} else {
6160
/** The name of the local database for WordPress */
6261
define('DB_NAME', '{{db_name}}');
6362
/** Local environment MySQL login info */
6463
define('DB_HOST', '127.0.0.1');
65-
define('DB_USER', '{{db_user}}');
66-
define('DB_PASSWORD', '{{db_password}}');
64+
define('DB_USER', '{{local_db_user}}');
65+
define('DB_PASSWORD', '{{local_db_password}}');
6766
}
6867

6968
/** Database Charset to use in creating database tables. */

appengine/wordpress/tests/StdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function setUpBeforeClass()
5555
$target = self::getTargetDir();
5656
$command = "php $helper setup -d $target "
5757
. " -n -p $project_id --env=s "
58-
. "--db_instance=wp-std --db_name=wp --db_user=wp "
58+
. "--db_instance=wp-std --db_name=wp --db_user=root "
5959
. "--db_password=$db_password";
6060
$wp_url = getenv('WP_DOWNLOAD_URL');
6161
if ($wp_url !== false) {

0 commit comments

Comments
 (0)