简体   繁体   中英

Trying to run Wordpress on Google App Engine with Google SQL Cloud

Warning: mysql_connect(): MySQL server has gone away in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Warning: mysql_connect(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Warning: mysql_connect(): MySQL server has gone away in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Getting these errors with everything.

WP_CONFIG:

define('DB_NAME', 'wordpress_db');

/** MySQL database username */
define('DB_USER', 'wp_user');

/** MySQL database password */
define('DB_PASSWORD', 'wp_password');

/** MySQL hostname */
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
  define('DB_HOST', ':/cloudsql/YOUR_PROJECT_ID:INSTANCT_ID');
}else{
  define('DB_HOST', '127.0.0.1');
}

Followed these instructions: https://developers.google.com/appengine/articles/wordpress

the google cloud instance run on a separate project but the app is allowed to access

If you are migrating your WP to GCE w/Cloud SQL, you should:

  1. Create a cloud storage bucket & upload your mysqldump file (with --hex-blob condition).
  2. Create a cloud SQL instance + create a root password (no password by default).
  3. Import the *.sql (or gzip) file up into the database.
  4. Create a [WordPress] user with privileges to that db access within that cloud sql instance.
  5. Pre-authorize GCE instance access to the Cloud SQL instance, by static IP, or ephemeral IP [CIDR format].
  6. Depending on your [WP] GCE server flavor (eg debian), install mysql-client .
  7. Create a Cloud SQL IPv4 address.
  8. Copy the address into your WP config.php file, like: define('DB_HOST', 'xx.xx.xxx.xxx:3306');

Your WP site should establish the database connection on the next page refresh.

Make sure your app engine instance and Cloud SQL instance is set to the same region.

By default, app engine is set to United States.

Lastly, check that you've authorised your app engine app in your Cloud SQL instance.

The google app engine documentation states

"Google Cloud Platform project called is connecting to a Cloud SQL instance named ."

you are probably getting an error because for project id you are using the project Id for your appengine application not your Cloud SQL project ID. so try:

$db = new pdo('mysql:unix_socket=/cloudsql/<sql-project-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM