{"id":746,"date":"2017-11-07T00:40:52","date_gmt":"2017-11-07T00:40:52","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=746"},"modified":"2017-11-10T11:13:08","modified_gmt":"2017-11-10T11:13:08","slug":"creating-a-fault-tolerant-wordpress-site","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=746","title":{"rendered":"Creating a Fault Tolerant WordPress Site"},"content":{"rendered":"<h2>Part 1 &#8211; Getting Setup<\/h2>\n<p>https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/5028334?start=15<\/p>\n<p><a href=\"http:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-747\" src=\"http:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha.png\" alt=\"\" width=\"456\" height=\"811\" srcset=\"https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha.png 456w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha-169x300.png 169w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha-84x150.png 84w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2017\/11\/wordpress-ha-300x534.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Set Region to US-East<\/li>\n<li>Identity and Access Management (IAM)\n<ul>\n<li>Create a Role for S3 administrative access<\/li>\n<\/ul>\n<\/li>\n<li>Create our Security Groups\n<ul>\n<li>Put these in your default VPC<\/li>\n<li>Networking &gt; VPC &gt; Security Groups\n<ul>\n<li>Web-DMZ\n<ul>\n<li>HTTP (80)<\/li>\n<li>SSH (22)<\/li>\n<li>0.0.0.0\/24<\/li>\n<\/ul>\n<\/li>\n<li>RDS-SG\n<ul>\n<li>MySQL (3306)<\/li>\n<li>Web-DMZ<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Create our Elastic Load Balancer\n<ul>\n<li>EC2 &gt; Load Balancers<\/li>\n<li>Public facing<\/li>\n<li>All availability zones<\/li>\n<li>Security Group\n<ul>\n<li>Web-DMZ<\/li>\n<\/ul>\n<\/li>\n<li>Configure Routing\n<ul>\n<li>Target group\n<ul>\n<li>Target group=New target group<\/li>\n<li>Name=MyWordpressServers<\/li>\n<\/ul>\n<\/li>\n<li>Health checks\n<ul>\n<li>healthy.html<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Default everything else and [Create]<\/li>\n<\/ul>\n<\/li>\n<li>Setup S3 for our Code\n<ul>\n<li>Storage &gt; S3\n<ul>\n<li>tas-wordpress<\/li>\n<li>tas-media<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Setup CloudFront\n<ul>\n<li>Networking &gt; CloudFront &gt; New Distribution &gt; Web<\/li>\n<li>Origin Settings\n<ul>\n<li>tas-media<\/li>\n<li>Restrict bucket access=Yes<\/li>\n<li>Origin Access Identity=Create a New Identity<\/li>\n<li>Grant Read Permissions=Yes<\/li>\n<\/ul>\n<\/li>\n<li>Leave everything else default and [Create Distribution]<\/li>\n<\/ul>\n<\/li>\n<li>Setup RDS\n<ul>\n<li>Databases &gt; RDS &gt; [Launch a DB Instance]<\/li>\n<li>MySQL &gt; [Select]<\/li>\n<li>Production (For Multi AZ)<\/li>\n<li>Specify DB Details\n<ul>\n<li>Multi-AZ=Yes<\/li>\n<li>VPC Security Group=RDS-SG<\/li>\n<\/ul>\n<\/li>\n<li>Settings\n<ul>\n<li>DB Name\/Username\/PW=taswp123<\/li>\n<li>[Next Step]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Part 2 &#8211; Setting up EC2<\/h2>\n<p>https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/5028338?start=0<\/p>\n<ul>\n<li>Setup DNS\n<ul>\n<li>Networking &gt; Route53 &gt; Select Domain &gt; Add Alias to ELB &amp; Save<\/li>\n<\/ul>\n<\/li>\n<li>Create EC2 Instances\n<ul>\n<li>EC2 &gt; Launch Instance\n<ul>\n<li>Amazon Linux AMI<\/li>\n<li>t2.micro<\/li>\n<li>Default VPC<\/li>\n<li>S3-Admin Role<\/li>\n<li>Web-DMZ Security Group<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Setup the instance\n<ul>\n<li>yum update -y<\/li>\n<li>Install\n<ul>\n<li>httpd<\/li>\n<li>php<\/li>\n<li>php-mysql<\/li>\n<li>stress (for stress testing)<\/li>\n<\/ul>\n<\/li>\n<li>Update \/ect\/httpd\/conf\/httpd.conf\n<ul>\n<li>AllowOverride ALL<\/li>\n<\/ul>\n<\/li>\n<li>Create healthy.html\n<ul>\n<li>echo &#8220;I&#8217;m healthy&#8221;&gt; \/var\/www\/html\/healthy.html<\/li>\n<\/ul>\n<\/li>\n<li>Install WordPress\n<ul>\n<li>wget https:\/\/wordpress.org\/latest.tar.gz<\/li>\n<li>tar -xzf latest.tar.gz<\/li>\n<li>cp -r wordpress\/* \/var\/www\/html\/\n<ul>\n<li>-or- cp -r wordpress\/* .<\/li>\n<\/ul>\n<\/li>\n<li>Clean up unused files\n<ul>\n<li>rm -rf wordpress<\/li>\n<li>rm -rf latest.tar.gz<\/li>\n<\/ul>\n<\/li>\n<li>Set \/wp-content for read-write\n<ul>\n<li>chmod -R 755 wp-content<\/li>\n<li>chown -R apache:apache wp-content<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Start Apache and set to start on boot\n<ul>\n<li>service httpd start<\/li>\n<li>chkconfig httpd on<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Configure the Elastic Load Balancer\n<ul>\n<li>Default target group=MyWordpressServers<\/li>\n<li>Edit target group\n<ul>\n<li>Health checks\n<ul>\n<li>Healthy threshold=2<\/li>\n<li>Unhealthy threshold=2<\/li>\n<li>Timeout=5<\/li>\n<li>Interval=6 (must be longer than the Timeout)<\/li>\n<\/ul>\n<\/li>\n<li>Register the instance\n<ul>\n<li>{Targets} [Edit]<\/li>\n<li>Select the Instance &gt; [Add to Registered] &gt; [Save]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Part 3 &#8211; Adding Resilience and CloudFront<\/h2>\n<p>https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/5028344?start=0<\/p>\n<h4>Backup our data to S3<\/h4>\n<pre>aws s3 cp --recursive \/var\/www\/html s3:\/\/data-bucket-name<\/pre>\n<h4>Copy all media files to S3<\/h4>\n<pre>aws s3 cp --recursive \/var\/www\/html\/wp-content\/uploads s3:\/\/media-bucket-name<\/pre>\n<p>This command will re-copy every thing every time it is ran.\u00a0 Better to use the sync command.<\/p>\n<pre>aws s3 sync --delete \/var\/www\/html\/wp-content\/uploads s3:\/\/media-bucket-name<\/pre>\n<h4>Create .htaccess rewrite rule<\/h4>\n<pre>Options +FollowSymlinks\r\nRewriteEngine on\r\nrewriterule ^wp-content\/uploads\/(.*)$ http:\/\/d2lf6ybul99vzg.cloudfront.net\/$1 [r=301,nc]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>Part 4 &#8211; Setting up our AMIs<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/7244328?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/7244328?start=0<\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"warning\">This section did not work for me! No matter what I did, the URL remained the one in the database. I ended up editing my wp-config.php files and adding the appropriate lines:<br \/>\n&#8220;Write&#8221; Instance<\/p>\n<pre>define('WP_SITEURL','http:\/\/write.thomasroberts.name');\r\ndefine('WP_HOME','http:\/\/write.thomasroberts.name');<\/pre>\n<p>&#8220;Production&#8221; Instance<\/p>\n<pre>define('WP_SITEURL','http:\/\/thomasroberts.name');\r\ndefine('WP_HOME','http:\/\/thomasroberts.name');<\/pre>\n<p>Next, I removed the crontab line that said to download the code on &#8220;Production&#8221;<\/p>\n<pre>#*\/5 * * * * root aws s3 sync --delete s3:\/\/thomasandsofia-east1 \/var\/www\/html<\/pre>\n<p>Finally, I created the AMIs for both instances. So far, so good!<\/p>\n<\/div>\n<h2>\nStep 5 &#8211; Create Launch Configurations and Auto-Scaling Groups<\/h2>\n<p>** Make sure you add the desired subnets when creating an Auto Scaling Group!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 1 &#8211; Getting Setup https:\/\/www.udemy.com\/aws-certified-solutions-architect-associate\/learn\/v4\/t\/lecture\/5028334?start=15 &nbsp; Set Region to US-East Identity and Access Management (IAM) Create a Role for S3 administrative access Create our Security Groups Put these in your default VPC Networking &gt; VPC &gt; Security Groups Web-DMZ HTTP (80) SSH (22) 0.0.0.0\/24 RDS-SG MySQL (3306) Web-DMZ Create our Elastic Load Balancer EC2 ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=746\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,16],"tags":[],"class_list":["post-746","post","type-post","status-publish","format-standard","hentry","category-amazon-web-services-aws","category-databases"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=746"}],"version-history":[{"count":11,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":758,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/746\/revisions\/758"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}