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

WordPress with CloudFront + AMAZON RDS + S3

WordPress with CloudFront + AMAZON RDS + S3

#Creating JIN-KEI Simple Stack
- List of commands on this hands-on
https://github.com/amimoto-ami/hans-on-materials/blob/master/howto/simple-stack_en.md

More Decks by Amimoto - Flexible Cloud WordPress Hosting

Other Decks in How-to & DIY

Transcript

  1. WordPress
    with
    CloudFront + AMAZON RDS + S3
    @Amimoto_Ami
    amimoto-ami.com

    View full-size slide

  2. Architecture

    View full-size slide

  3. AMAZON CloudFront
    AMAZON RDS
    AMAZON S3
    w %#XJUIIJHIGBJMVSFUPMFSBODF
    w TQFFEVQDPOUFOUTEFMJWFSZXJUI$%/
    w $PTUF⒎FDUJWFNFEJBTUPSBHFT
    (PBM

    View full-size slide

  4. Starting up AWS services
    Plugins configurations
    Workflow
    Preparations

    View full-size slide

  5. Preparations
    for
    construction

    View full-size slide

  6. http://bit.ly/1Xio3cC
    -JTUPGDPNNBOET

    View full-size slide

  7. AWS CLI installation
    CloudFront corresponding
    Workflow
    Start up AMIMOTO AMI
    preparations

    View full-size slide

  8. AWS CLI installation
    CloudFront corresponding
    Workflow
    Start up AMIMOTO AMI
    preparations

    View full-size slide

  9. https://aws.amazon.com/marketplace/pp/B01DAONMCK/

    View full-size slide

  10. When you start up AMIMOTO, 

    step forward until this “Welcome” page.

    View full-size slide

  11. AWS CLI installation
    CloudFront corresponding
    Workflow
    Start up AMIMOTO AMI
    preparations

    View full-size slide

  12. AWS CLI
    w $PNNBOE-JOF*OUFSGBDFGPS"84
    w :PVDBONBOJQVMBUFBMMUISPVHI
    DPNNBOEMJOF
    w 'PSDPOpHVSFUIF$MPVE'SPOU
    "84$-*

    View full-size slide

  13. Create IAM user
    Initial setup
    Workflow
    AWS-CLI installation

    View full-size slide

  14. Create IAM user
    Initial setup
    Workflow
    AWS-CLI installation

    View full-size slide

  15. 1. Install AWS Command Line Interface (aws-cli) to your Mac or PC


    Two ways to install aws-cli:

    - Install follow the AWS user guide page:

    http://docs.aws.amazon.com/cli/latest/userguide/installing.html


    - Install through package manager Homebrew, if you use Mac:

    http://brew.sh/index.html

    "84$-*JOTUBMMBUJPO

    View full-size slide

  16. Copy below command and pate into your terminal.app then hit [return] key

    $ /usr/bin/ruby -e "$(curl -fsSL https://
    raw.githubusercontent.com/Homebrew/install/
    master/install)"

    $ brew install wget

    $ brew install awscli

    'PS.BDVTFST

    View full-size slide

  17. 'PS8JOEPXTVTFS
    w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU

    IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ
    w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU

    IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ

    View full-size slide

  18. Create IAM user
    Initial setup
    Workflow
    AWS-CLI installation

    View full-size slide

  19. move to Identity and Access Management

    View full-size slide

  20. Create new user

    View full-size slide

  21. Enter a user name and generate access key.
    BNJNPUPDMJ
    BNJNPUPDMJ

    View full-size slide

  22. Save security credentials to your local (anywhere you want)

    View full-size slide

  23. Attach policy to created user

    View full-size slide

  24. Choose CloudFrontFullAccess and…

    View full-size slide

  25. Choose AmazonS3FullAccess then click [Attach Policy]

    View full-size slide

  26. Two policies are attached to the user

    View full-size slide

  27. Create IAM user
    Initial setup
    Workflow
    AWS-CLI installation

    View full-size slide

  28. aws configure --profile amimoto-cli

    View full-size slide

  29. 4BNQMFDPOpHVSBUJPO
    AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX

    AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Default region name [None]: ap-northeast-1

    Default output format [None]: JSON

    View full-size slide

  30. AWS Access Key ID and AWS Secret Access Key

    View full-size slide

  31. 4BNQMFDPOpHVSBUJPO
    AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX

    AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Default region name [None]: ap-northeast-1

    Default output format [None]: JSON

    View full-size slide

  32. AWS CLI installation
    CloudFront corresponding
    Workflow
    Start up AMIMOTO AMI
    preparations

    View full-size slide

  33. aws --profile amimoto-cli configure set preview.cloudfront true
    $POpHVSBUJPODPNNBOE

    View full-size slide

  34. aws --profile amimoto-cli cloudfront help
    $POpHVSBUJPODIFDL

    View full-size slide

  35. Setting up 

    AWS services

    View full-size slide

  36. Amazon RDS
    Amazon S3
    Workflow
    CloudFront

    View full-size slide

  37. Amazon RDS
    Amazon S3
    Workflow
    CloudFront

    View full-size slide

  38. AMAZON CloudFront
    •Global content delivery network
    (CDN) service
    •High data transfer speeds and
    reduce server load
    •Supports failover if a failure

    View full-size slide

  39. export origin_url='{ORIGIN URL}'; aws
    --profile amimoto-cli cloudfront
    create-distribution --cli-input-json
    "$(curl -l -s https://
    raw.githubusercontent.com/amimoto-
    ami/create-cf-dist-settings/master/
    source_dist_setting.sh | sh)"
    4FUUJOH$MPVE'SPOUVQXJUI"84$-*

    View full-size slide

  40. http://bit.ly/1VAnJ8q
    -JTUPGDPNNBOET

    View full-size slide

  41. • Install WordPress into the server’s document root directory;
    • Replace {ORIGIN URL} to the server domain name (or Public DNS) of AMIMOTO;
    • Change amimoto-cli to your created profile, if necessary;
    • On this hands-on, set
    Public DNS of EC2 to {ORIGIN URL}
    /PUF

    View full-size slide

  42. *GZPVDBOOPUpOE1VCMJD%/4PO&$
    Check following documents:
    Updating DNS Support for Your VPC
    http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-
    dns.html#vpc-dns-updating
    or
    AWSͰPublic DNS(ύϒϦοΫDNS)ׂ͕Γ౰ͯΒΕͳ͍࣌ͷղܾ๏
    http://qiita.com/kasokai/items/4ea689ce9f206e78a523

    View full-size slide

  43. FYQPSUPSJHJO@VSMbFD99999999BQ
    OPSUIFBTUDPNQVUFBNB[POBXTDPN`
    BXTŠQSPpMFBNJNPUPDMJDMPVEGSPOUDSFBUFEJTUSJCVUJPODMJ
    JOQVUKTPO DVSMMTIUUQTSBXHJUIVCVTFSDPOUFOUDPN
    BNJNPUPBNJDSFBUFDGEJTUTFUUJOHTNBTUFS
    TPVSDF@EJTU@TFUUJOHTIcTI

    4BNQMFDPOpHVSBUJPO

    View full-size slide

  44. 20-30 minutes to complete for 

    CloudFront starts up

    View full-size slide

  45. Amazon S3
    Amazon RDS
    Workflow
    CloudFront

    View full-size slide

  46. AMAZON S3
    •AWS storage service
    •Data is stored on redundant servers 

    in multiple data centres
    •High fault tolerance
    •No limit on the number of items 

    can be stored •

    View full-size slide

  47. Click S3 on AWS Console page.

    View full-size slide

  48. Create a bucket

    View full-size slide

  49. Name a bucket; unique and easy to specify

    View full-size slide

  50. Bucket properties

    View full-size slide

  51. Copy Endpoint and paste it to the text file.

    View full-size slide

  52. Choose Enable website hosting

    View full-size slide

  53. Input index.html into Index Document

    View full-size slide

  54. Click [Save] to apply settings.

    View full-size slide

  55. Amazon S3
    Amazon RDS
    Workflow
    CloudFront

    View full-size slide

  56. AMAZON RDS
    •Managed DB service
    •Single click to change specification
    •Easy to replication

    View full-size slide

  57. AMAZON RDS
    MariaDB
    Amazon Aurora
    Various DB engine
    MySQL

    View full-size slide

  58. Switching DB to RDS
    Workflow
    Set up

    View full-size slide

  59. Switching DB to RDS
    Workflow
    Set up

    View full-size slide

  60. Values to input
    • DB Instance IdentifierɿName of DB instance
    • Master UsernameɿRoot user of DB
    • Master PasswordɿPassword for root user of DB
    • Confirm PasswordɿConfirmation password for root user of DB
    Copy and paste them to notepad and save as text file.

    View full-size slide

  61. )PTUOBNFPG
    EBUBCBTF

    View full-size slide

  62. Coffee break

    View full-size slide

  63. Switching DB to RDS
    Workflow
    Set up

    View full-size slide

  64. &EJUMPDBMDPOpHQIQ
    $ sudo su -
    # cd /var/www/vhosts/{INSTANCE_ID}
    # vim local-config.php

    View full-size slide

  65. Needs to edit (Line: 11–18)
    if ( !$db_data ) {
    $db_data = array(
    'database' => '{Database Name}',
    'username' => '{Master Username}',
    'password' => '{Master Password}',
    'host' => '{RDS_ENDPOINT}',
    );
    }

    View full-size slide

  66. Access to CloudFront’s DNS with your browser

    View full-size slide

  67. Back to WordPress’ set up page.
    Fill in required field then install WordPress.

    View full-size slide

  68. Installation has completed

    View full-size slide

  69. Stop MySQL on AMIMOTO(EC2)

    View full-size slide

  70. # vim /opt/local/amimoto.json

    View full-size slide

  71. Disable MySQL autostart
    • Before
    {
    "mod_php7" : { "enabled": true },
    "run_list" : [ "recipe[amimoto]" ]
    }
    • After
    {
    "mod_php7" : { "enabled": true },
    "mysql": { "enabled": false },
    "run_list" : [ "recipe[amimoto]" ]
    }

    View full-size slide

  72. # /opt/local/provision

    View full-size slide

  73. Error Establishing a Database Connection
    • local-config.php still refers to previous DB in EC2 (AMIMOTO)
    • Make sure configuration of local-config.php

    View full-size slide

  74. Set up plugins
    for WordPress

    View full-size slide

  75. C3 CloudFront Cache Clear
    CF Preview Fix
    Plugins
    Nephila clavata

    View full-size slide

  76. CF Preview Fix
    C3 CloudFront Cache Clear
    Nephila clavata
    Plugins

    View full-size slide

  77. Activate Nephila clavata plugin on WordPress Dashboard

    View full-size slide

  78. Configure the plugin

    View full-size slide

  79. Values to input
    • AWS Access Key: Access key for IAM user amimoto-s3
    • AWS Secret Key: Access key for IAM user amimoto-s3
    • AWS Region: Region (optional)
    • S3 Bucket: S3 bucket name
    • S3 URL: S3 bucket URL
    • Storage Class: Choose STANDARD

    View full-size slide

  80. Media library copied onto Amazon S3

    View full-size slide

  81. CF Preview Fix
    C3 CloudFront Cache Clear
    Plugins
    Nephila clavata

    View full-size slide

  82. $$MPVE'SPOU$MFBS$BDIF
    • CloudFront͸Ωϟογϡ࡟আ࣌ʹ՝
    ۚ͞ΕΔͷͰཁ஫ҙ
    • Flush CloudFront Cache on
    WordPress
    • Flush automatically when article
    published/updated or manually
    • Pay as each request for invalidation

    View full-size slide

  83. Configure the plugin
    $ cd /var/www/vhosts/{INSTANCE_ID}
    $ wp plugin activate c3-cloudfront-clear-cache
    $ wp c3 update distribution_id
    $ wp c3 update access_key
    $ wp c3 update secret_key

    View full-size slide

  84. CF Preview Fix
    C3 CloudFront Cache Clear
    Plugins
    Nephila clavata

    View full-size slide

  85. Install and activate [CF Preview Fix] plugin

    View full-size slide

  86. Removing
    resources

    View full-size slide

  87. AMAZON CloudFront
    Disable CloudFront

    View full-size slide

  88. AMAZON RDS
    Delete Amazon RDS

    View full-size slide

  89. AMAZON S3
    Delete Amazon S3

    View full-size slide

  90. %FMFUF4CVDLFU
    • All media are removed permanently
    • Someone will create same S3 bucket name

    View full-size slide

  91. IAM
    Delete the created 

    IAM user

    View full-size slide

  92. AMAZON CloudFront
    Delete CloudFront

    View full-size slide

  93. Never forget
    delete EC2

    View full-size slide

  94. http://amimoto-ami.com/slack/
    Feel free to contact us!

    View full-size slide

  95. @Amimoto_Ami
    amimoto-ami.com
    THANK YOU!
    WordPress
    with
    CloudFront + AMAZON RDS + S3

    View full-size slide