Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wordpress on AppEngine Codelab

Wordpress on AppEngine Codelab

Zero to Hero with Google Cloud Platform
A Wordpress on App Engine Codelab

Kenneth Kinyanjui

August 16, 2014
Tweet

More Decks by Kenneth Kinyanjui

Other Decks in Programming

Transcript

  1. DESIGN DEVELOP DISTRIBUTE Zero to Hero with Google Cloud Platform

    GDG Nairobi Created by / || http://gdgnairobi.info Kenneth Kinyanjui @kenju254 GDG Kimathi University
  2. Heads Up -What is Google Cloud Plaftorm? -Why choose Google

    Cloud Platform? -Who uses Google Cloud Platform? -What are some of the common misconceptions? -Which languages are supported on Google Cloud? -Lets get down to business
  3. Compute Compute Engine Storage Cloud Storage Cloud Datastore Cloud SQL

    Big Data Bigquery Services Cloud Endpoints Translate API Prediction API Product as a Service Google App Engine
  4. Automatic Scaling Run on Google's Infrastructure Mix and match of

    all the Google Cloud Services and APIs Performance you can count on Focus on building the product Get the support you need
  5. Google App Engine is a web framework Google App Engine

    is a VPS Google App Engine is a SaaS
  6. Google App Engine is an PaaS Compute Engine is Google's

    IaaS Cloud Endpoints is an example of a SaaS
  7. Prerequisites 1. Install the 2. Install 3. for a Google

    Cloud Platform project, and set up a Cloud SQL instance, as described , and a Cloud Storage bucket, as described . You'll want to name your Cloud SQL instance "wordpress" to match the config files provided here. 4. Visit your project in the , going to the App Engine section's Application Settings area, and make a note of the Service Account Name for your application, which has an e-mail address (e.g. < P R O J E C T _ I D > @ a p p s p o t . g s e r v i c e a c c o u n t . c o m ). Then, visit the Cloud Storage section of your project, select the checkbox next to the bucket you created in step 3, click Bucket Permissions, and add your Service Account Name as a User account that has Writer permission. PHP SDK for Google App Engine MySQL Sign up here here Google Cloud Console
  8. Clone this git repo and its submodules by running the

    following commands: g i t c l o n e - - r e c u r s i v e h t t p s : / / g i t h u b . c o m / G o o g l e C l o u d P l a t f o r m / a p p e n g i n e - p h p - w o r d p r e s s - s t a r t e r - p r o j e c t . g i t c d a p p e n g i n e - p h p - w o r d p r e s s - s t a r t e r - p r o j e c t / You now have a copy of , the , , and . WordPress App Engine plugin for WordPress Batcache Memcached Object Cache
  9. Edit w p - c o n f i g

    . p h p and a p p . y a m l , replacing y o u r - p r o j e c t - i d to match the Project ID (not the name) that was assigned to your Google Cloud Platform project.
  10. Because of GitHub and licensing limitations, we can't put these

    files in the right places for you. Run this script to move all the files into place: m o v e _ f i l e s _ a f t e r _ e d i t i n g . s h This script: 1. Moves w p - c o n f i g . p h p from root into w o r d p r e s s / , replacing the file there. 2. Moves b a t c a c h e / a d v a n c e d - c a c h e . p h p to w o r d p r e s s / w p - c o n t e n t / 3. Moves b a t c a c h e / b a t c a c h e . p h p to w o r d p r e s s / w p - c o n t e n t / p l u g i n s / 4. Moves w p - m e m c a c h e / o b j e c t - c a c h e . p h p to w o r d p r e s s / w p - c o n t e n t / 5. Moves the contents of a p p e n g i n e - w o r d p r e s s - p l u g i n / to w o r d p r e s s / w p - c o n t e n t / p l u g i n s /
  11. Using MySQL, run d a t a b a s

    e s e t u p . s q l to set up your local database. For a default installation (no root password) this would be: m y s q l - u r o o t < d a t a b a s e s e t u p . s q l But really, all it's doing is running this line -- the WordPress installation script will do the heavy lifting when it comes to setting up your database. C R E A T E D A T A B A S E I F N O T E X I S T S w o r d p r e s s _ d b ; To run WordPress locally on Windows and OS X, you can use the by going to File > Add Existing Project or you can run one of the commands below. Launcher
  12. On Mac and Windows, the default is to use the

    PHP binaries bundled with the SDK: $ A P P _ E N G I N E _ S D K _ P A T H / d e v _ a p p s e r v e r . p y p a t h _ t o _ t h i s _ d i r e c t o r y On Linux, or to use your own PHP binaries, use: $ A P P _ E N G I N E _ S D K _ P A T H / d e v _ a p p s e r v e r . p y - - p h p _ e x e c u t a b l e _ p a t h = P H P _ C G I _ E X E C U T A B L E _ P A T H p a t h _ t o _ t h i s _ d i r e c t o r Now, with App Engine running locally, visit h t t p : / / l o c a l h o s t : 8 0 8 0 / w p - a d m i n / i n s t a l l . p h p in your browser and run the setup process, changing the port number from 8080 if you aren't using the default. Or, to install directly from the local root URL, define W P _ S I T E U R L in your w p - c o n f i g . p h p , e.g.: d e f i n e ( ' W P _ S I T E U R L ' , ' h t t p : / / l o c a l h o s t : 8 0 8 0 / ' ) ; You should be able to log in, and confirm that your app is ready to deploy.
  13. If all looks good, you can upload your application using

    the Launcher or by using this command: $ A P P _ E N G I N E _ S D K _ P A T H / a p p c f g . p y u p d a t e A P P L I C A T I O N _ D I R E C T O R Y Just like you had to do with the local database, you'll need to set up the Cloud SQL instance. The SDK includes a tool for doing just that: g o o g l e _ s q l . p y < P R O J E C T _ I D > : w o r d p r e s s This launches a browser window that authorizes the g o o g l e _ s q l . p y tool to connect to your Cloud SQL instance. After clicking Accept, you can return to the command prompt, which has entered into the SQL command tool and is now connected to your instance. Next to s q l > , enter this command: C R E A T E D A T A B A S E I F N O T E X I S T S w o r d p r e s s _ d b ;
  14. You should see that it inserted 1 row of data

    creating the database. You can now type e x i t -- we're done here. Now, just like you did when WordPress was running locally, you'll need to run the install script by visiting: h t t p : / / < P R O J E C T _ I D > . a p p s p o t . c o m / w p - a d m i n / i n s t a l l . p h p Or, to install directly from the root URL, you can define WP_SITEURL in your w p - c o n f i g . p h p , e.g.: d e f i n e ( ' W P _ S I T E U R L ' , ' h t t p : / / < Y O U R _ P R O J E C T _ I D > . a p p s p o t . c o m / ' ) ;
  15. Activating the plugins Now, we just need to activate the

    plugins that were packaged with your app. Log into the WordPress administration section of your blog at h t t p : / / < P R O J E C T _ I D > . a p p s p o t . c o m / w p - a d m i n , and visit the Plugins section. Click the links to activate Batcache Manager and Google App Engine for WordPress. Configuring email and hooking WordPress up to your Cloud Storage Now visit Settings > App Engine. Enable the App Engine mail service - this will use the App Engine Mail API to send notifications from WordPress. Optionally, enter a valid e-mail address that mail should be sent from (if you leave this blank, the plugin will determine a default address to use). The address of the account you used to the create the Cloud Console project should work. Stay on this page, because in order to be able to embed images and other multimedia in your WordPress content, you need to enter the name of the Cloud Storage bucket you created when going through all the Prequisites earlier under Upload Settings. Hit Save Changes to commit everything.
  16. Congratulations! You should now have a blog that loads rapidly,

    caches elegantly, sends email properly, and can support adding images and other media to blog posts! Most importantly, it will take advantage of Google's incredibly powerful infrastructure and scale gracefully to accomodate traffic that is hitting your blog.
  17. You'll want to keep your local copy of the application

    handy because that's how you install other plugins and update the ones that are packaged with this project. Due to the tight security of the App Engine sandbox, you can't directly write to files in the application area -- they're static. That's also why we hooked your uploads up to Cloud Storage. So, to install plugins, you log into the admin area of your local WordPress instance, install or update any plugins you want there, and redeploy. Then go into the admin area for your hosted WordPress instance to activate the plugins.