[ wordpress ] gcloud

Switch Gcloud project

gcloud config set project my-project

Create database

1) a new Cloud SQL for MySQL Second Generation instance

gcloud sql instances create wordpress \
    --activation-policy=ALWAYS \
    --tier=db-n1-standard-1

Describe where your database is

gcloud sql instances describe wordpress | grep region

TIPS : delete

gcloud sql instances delete wordpress

2) Create the database
instance name / database name : `wordpress`
database user name : `root`

gcloud sql databases create wordpress --instance wordpress

TIPS : delete

gcloud sql databases delete wordpress --instance wordpress

3) change root password

gcloud sql users set-password root % \
    --instance wordpress \
    --password=YOUR_INSTANCE_ROOT_PASSWORD # Don't use this password!

Composer

composer require google/cloud-tools
composer require google/cloud-tools
php vendor/bin/wp-gae

wp-gae command provides a convenient way for you to either create a new WordPress project or add the required configuration to an existing one

The wp-gae command will ask you several question in order to set up your Cloud SQL database connection, and then write the required configuration to your wp-config.php configuration file. It also copies the following files into your project directory to allow WordPress to run on Google App Engine:

app.yaml: The App Engine configuration file that specifies the runtime and static asset handlers.
cron.yaml: The App Engine configuration file that ensures wp-cron.php is run every 15 minutes.
php.ini: For setting PHP configuration in App Engine specific to WordPress.
gae-app.php: The Front Controller, which is required for all App Engine applications.

Create a new WordPress project

php vendor/bin/wp-gae create

 

 

Migrate existing project to gcloud

php vendor/bin/wp-gae update path/to/your-wordpress-site

deploy 

gcloud app deploy app.yaml cron.yaml

Pricing :

“for the month of November and December which amounts to $8.05 per month. So it’s almost the same as paying for shared hosting I’d say. It looks like the Cloud SQL instance does not shut down.”

https://stackoverflow.com/questions/27654922/wordpress-on-google-app-engine-pricing

ref : https://cloud.google.com/community/tutorials/run-wordpress-on-appengine-standard?authuser=3

[ css ] javascript load deferred style

put the `link href` into `noscript id=”deferred-styles”`

Then insert this javascript

    var loadDeferredStyles = function() {
      var addStylesNode = document.getElementById("deferred-styles");
      var replacement = document.createElement("div");
      replacement.innerHTML = addStylesNode.textContent;
      document.body.appendChild(replacement)
      addStylesNode.parentElement.removeChild(addStylesNode);
    };
    var raf = requestAnimationFrame || mozRequestAnimationFrame ||
        webkitRequestAnimationFrame || msRequestAnimationFrame;
    if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });
    else window.addEventListener('load', loadDeferredStyles);
  

[ ApolloClient ] fetch error on IE 11

Error on IE 11 : 

fetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\n
// For example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");

Solution :

if (!window.fetch) window.fetch = fetch

ref : https://www.npmjs.com/package/whatwg-fetch