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

How to use Amazon RDS & S3 with AMIMOTO AMI WordPress

How to use Amazon RDS & S3 with AMIMOTO AMI WordPress

How to use Amazon RDS & S3 with AMIMOTO AMI WordPress

More Decks by Amimoto - Flexible Cloud WordPress Hosting

Other Decks in How-to & DIY

Transcript

  1. @Amimoto_Ami
    amimoto-ami.com
    AMIMOTO (HHVM) + AMAZON RDS + S3

    View Slide

  2. WHAT IS
    AMAZON RDS

    View Slide

  3. Scalable
    6 database engines
    Relational Database
    Easy to set up and
    operate

    View Slide

  4. ADVANTAGES
    • Scale your CPU, IOPS, and storage space

    • Snapshot-based on demand 

    and automatic backups

    • Multi Availability Zones deployment

    • Secondery synchronous instance in 

    case the primary fails

    View Slide

  5. DISADVANTAGES
    • No shell access to the DB instance

    • Restricted user privileges

    • Disabled replication in MySQL

    • Weekly 4-hour maintenance window

    • RDS Instance cannot be stopped

    View Slide

  6. MOVING YOUR

    DATABASE TO
    RDS

    View Slide

  7. Architecture without RDS

    View Slide

  8. Architecture with RDS

    View Slide

  9. Login to your AWS Console

    View Slide

  10. Creating a MySQL server in Amazon RDS

    View Slide

  11. Database Engine

    View Slide

  12. Database Engine

    View Slide

  13. Specify database details

    View Slide

  14. Advanced Settings

    View Slide

  15. Creating DB

    View Slide

  16. DB created

    View Slide

  17. Login to your instance

    View Slide

  18. Connecting your EC2 to RDS
    1. Log into the root of your server using SSH:


    $ ssh -i /Users/macpil/Desktop/example.pem [email protected]_ip or
    domain

    2. Run the following command:


    $ mysql -h {endpoint} -P 3306 -u {mymasteruser} -p 


    View Slide

  19. {endpoint} can be found in the RDS information of AWS Management Console

    {mymasteruser} and password are specified when you want to create RDS

    View Slide

  20. Data migration
    Export data via wp-cli:


    $ wp --path=/path/to/wordpress db export



    /path/to/wordpress is the directory where WordPress is installed

    In AMIMOTO AMI it’s usually /var/www/vhosts/{instance_id} 


    View Slide

  21. Data migration
    Import data to RDS:


    $ mysql -h {endpoint} -P 3306 -u {mymasteruser} -p {databasename} <
    dump.sql


    {endpoint} can be found in the RDS information of AWS Management Console

    {mymasteruser} and {databasename} are specified when you want to create RDS

    View Slide

  22. Rewriting wp-config.php
    // ** MySQL settings - You can get this info from your web host ** //
    $db_data = false;
    if ( file_exists('/opt/aws/cloud_formation.json') ) {
    $db_data = json_decode(file_get_contents('/opt/aws/
    cloud_formation.json'), true);
    if ( isset($db_data['rds']) ) {
    $db_data = $db_data['rds'];
    $db_data['host'] = $db_data['endpoint'] . ':' .
    $db_data['port'];
    }
    }
    if ( !$db_data ) {
    $db_data = array(
    'database' => 'RDS_DATABASE_NAME_HERE',
    'username' => 'RDS_USER_NAME_HERE',
    'password' => 'RDS_PASSWORD_HERE',
    'host' => 'RDS_ENDPOINT_HERE',
    );
    }

    View Slide

  23. Rewriting wp-config.php
    RDS_DATABASE_NAME_HERE Database Name which was set in Configure Advanced
    Settings
    RDS_USER_NAME_HERE Master Username which was set in Specify DB Details
    RDS_PASSWORD_HERE Master Password which was set in Specify DB Details
    RDS_ENDPOINT_HERE RDS endpoint
    When you set as above in wp-config.php, let’s check if you can connect to WordPress.

    View Slide

  24. Stoping MySQL in the AMIMOTO AMI
    Since MySQL was moved to RDS, MySQL process in AMIMOTO AMI is no longer
    necessary.
    Rewrite the configuration file, in AMIMOTO AMI, the middleware settings use chef-solo,
    where they are described in /opt/local/amimoto.json

    View Slide

  25. Stoping MySQL in the AMIMOTO AMI
    Since MySQL was moved to RDS, MySQL process in AMIMOTO AMI is no longer
    necessary.
    Rewrite the configuration file, in AMIMOTO AMI, the middleware settings use chef-solo,
    where they are described in /opt/local/amimoto.json

    To stop starting MySQL, please rewrite the file:


    {

    "nginx" : { "config" : { "user" : "nginx", "group" : "nginx" } },

    "php" : { "config" : { "user" : "nginx", "group" : "nginx" } },

    "mysql" : { "enabled" : false },

    "phpfpm" : { "enabled" : true },

    "run_list" : [ "recipe[amimoto]" ]

    }

    View Slide

  26. Stoping MySQL in the AMIMOTO AMI
    For AMIMOTO AMI HHVM version, rewrite as follows:
    {
    "nginx" : { "config" : { "user" : "nginx", "group" : "nginx" } },
    "php" : { "config" : { "user" : "nginx", "group" : "nginx" } },
    "mysql" : { "enabled" : false },
    "hhvm" : { "enabled" : true },
    "run_list" : [ "recipe[amimoto]" ]
    }

    View Slide

  27. Stoping MySQL in the AMIMOTO AMI
    Finally run the following command:


    $ sudo /opt/local/proviosion 

    $ mysql stop service

    View Slide

  28. WHAT IS
    AMAZON S3

    View Slide

  29. AMAZON S3
    • Scalable, high-speed, low-cost
    • Designed for online back and archiving

    of data
    • Static website hosting
    • Uploading, storage and downloading 

    of practically any file or object up to 5 GB
    • No limit on the number of items that 

    a subscriber can store
    • Data is stored on redundant servers 

    in multiple data centers

    View Slide

  30. Select S3 from the AWS Console

    View Slide

  31. Create a Bucket

    View Slide

  32. Create a Bucket

    View Slide

  33. Bucket summary

    View Slide

  34. Enable website hosting

    View Slide

  35. Go to Security Credentials

    View Slide

  36. Create New Access Key

    View Slide

  37. Copy/Download the Access Key details

    View Slide

  38. Enable the Nephila clavata plugin

    View Slide

  39. Configure the plugin

    View Slide

  40. WordPress Media Library on Amazon S3

    View Slide

  41. http://amimoto-ami.com/slack/
    Questions:

    View Slide

  42. @Amimoto_Ami
    amimoto-ami.com
    THANK YOU!
    AMIMOTO (HHVM) + AMAZON RDS + S3

    View Slide