How to Host your WordPress Website on Amazon EC2 and S3

By January 26, 2017 CMS, Web One Comment
how-to-host-your-wordpress-website-on-amazon-ec2-and-s3

You can enjoy reliable, fast, and protected website (against any type of data loss) by hosting your website on cloud.

In this article, I will let you know the basic procedure to host your WordPress website on Amazon S3 and EC2.

Hosting on Amazon S3

Hosting your images on Amazon s3 is a great option because you can stop worrying about backing up your images as S3 keeps multiple copies of your files and access to the images is very fast. It also reduces the load on your server of images.

Hosting on Amazon EC2

Amazon EC2 helps you in making resizable memory and compute capacity online (on cloud).  Hosting on aws gives you an awesome plug and play option for your server hard disks, capacity and computing power.

Why Hosting on AWS EC2 and S3 is Beneficial?

  • You can enjoy flexible pricing structure for each service do you want to avail.
  • The configuration dashboard is so easy to manage. So that you can setup if you have little experience with Amazon S3 and EC2.
  • You get scalable hosting.
  • Now, you have highly available website.
  • You will feel ease in loading high potential resources (content pulling) for your website.

Process to Host your WordPress Website

Step-1:

Sign up for the Amazon Account. You will get the Access Key and API Key for this

Add it into your WordPress plugin to access it in the Amazon directory

define( ‘AWS_ACCESS_KEY_ID’, ‘*****************

<strong><em>’ );

define( ‘AWS_SECRET_ACCESS_KEY’, ‘

</em>

</strong>*************************************’ );

Step-2:

You will get the Amazon Web Services Management Console.

Step-3:

Select the services which you are looking forward.

Step-4:

On service tab ( select EC2 and S3).

2

Step-5: Steps for S3 

Click to S3 first1

  • Create a bucket on S3: The S3 bucket is actually a container like the structure of your website, that’s the bucket for your S3 asset for your WordPress website.

3

  • Now, you have to set up your WordPress website to communicate with the S3.
  • From the “Static Website Hosting” option, enable website hosting on your index page (that would probably the first landing page of your website).4
  • Enable website hosting indexed document and error file in case of any error.5
  • Upload all the files that you want to be in your S3 bucket. Your bucket is accessible privately. You can check out your bucket URL from the side bar of S3. dashboard.6
  • If you have developed a bucket earlier then, select the required bucket and hit upload to push your relevant content in the S3 Bucket.
  • After File upload, it will be pulled from that directory from Amazon S3 bucket, where it was once saved.
  • After your file upload, you can make these file public to make it accessible via its AWS S3 bucket URL (in my case it’s: www.yourwebsite.com.s3_website-eu-west-1.amazonaws.com). Now, the images and content can be accessed from your S3 bucket now.add-bucket-policy
  • You can add the bucket privacy policy from the “Permission” link on the left panel of the S3 bucket.  Click on ‘Add Bucket Policy’ to add a code for it. Now you can access all the content of your website publically.

{

 “Version”: “2012-10-17″,

 “Statement”: [

{

  “Sid”: “PublicReadGetObject”,

  “Effect”: “Allow”,

  “Principal”: {

    “AWS”: “*”

  },

  “Action”: “s3:GetObject”,

  “Resource”: “arn:aws:s3:::YOUR-BUCKET-NAME-HERE/*”

}

 ]

}

  • Check for the URL of your website. Here is your website from Amazon S3 bucket.

Step-6: Steps for EC2 

Now, for launching your EC2 Instance, follow the procedure as below:

  • Just login to your AWS console.
  • Find the EC2 under compute list under Amazon Web Services dashboard.

1

  • To configure your virtual machine, create and launch an EC2 instance.2
  • After creating, configure your instance by going through the configuration wizard.
  • In the configuration setup, choose AWS marketplace that has WordPress installed. If not, then go to the left navigation panel and select AWS marketplace.
  • In the provided list click on the WordPress and install it. Ongoing through its steps, review it.3
  • On going through the next step, proceed it with or without key (as you want it).
  • Your instance is launched now. You can activate any subdomain or domain in it.
  • The Public IP is associated with the website, which you will be using for your website.
  • Your website is now launched, and all the assets are loaded via AWS. To make it accessible, with your very own URL, edit your “.htaccess” file.  
  • Run your EC2 instance, load your files and access it through its server now.

Step-7: Steps to Do on WordPress Dashboard End

Once you done with creating the EC2 Instance for your website and making the S3 Bucket for your content, you now need to link it into the WordPress dashboard end.

For this, the necessary procedure is :

Install AWS Plugins

  • Go to the plugin area, and Click on “Add Plugin” .
  • Search for plugin named “ Amazon Web Services” which will Houses the Amazon Web Services (AWS) PHP libraries and manages access keys. Required by other AWS plugins.
  • Once installed, download another plugin for S3. It is advised to install the plugin named “Amazon S3 and CloudFlare”.
  • Activate both the plugins
  • Once activated, on the left panel find AWS, click Access Key, it will ask you to add the Access API key and Secret Access Key  for your AWS, just add it and Save Changes.amazon_keys_720

 

  • Now, Go for S3 and CloudFront,  and browse for the Existing Bucket, or Create New one , depending upon the thing you want to get.

bucket_720

  • You will see all the content in your existing bucket. The next screen will be

path_720

Set the path from where it will sync your images or content. Check for any other option, if it suits you.

Now, all the things are ready for work and your assets will launch from the S3 bucket, when you add into your WordPress post or pages. It will automatically sync and load from AWS.

Conclusion

Vizteck is striving to adopt the latest practices for making data secure and reliable on the server and client end. All of the projects that we deliver to our clients are managed without any data loss. For this we adopt the Amazon Web Services. For any further query or suggestion regarding this, feel free to contact us.

Author Uroosa Sehar

More posts by Uroosa Sehar
  • Andrew Belford

    Hi Team

    Thank you for the above tutorial

    I found it very detail and helpful. There is one thing that I couldn’t get it to work. Whenever I tried to upload a photo in the plugin, it shows that it has been uploaded in S3, but it doesn’t show the image itself neither on the preview page. If I selected it it will show as a blank image on my website.

    Do you think is it something that is related to S3 or the plugin itself?

    I look forward to hear from you

    cheers
    AB

mautic is open source marketing automation