Skip to content Skip to sidebar Skip to footer

Wordpress Plugin to Upload Files to Amazon S3

This post is contributed by Mike Coleman | Developer Abet for Lightsail | Twitter: @mikegcoleman

Introduction

This is the second in a series of weblog posts on how to build a highly-available WordPress site on Amazon Lightsail. If you've not read the first mail service in the serial, Implementing a highly available Lightsail database, y'all will desire to become back and practise that equally this mail continues on from there. If yous accept read that mail, and so welcome back.

As a quick review, in the kickoff post, I explained how to deploy a WordPress case with a standalone MySQL database on Lightsail. In that mail I as well talked about how the WordPress data is stored not simply in the database, but also on the web server'due south file organization.

In this mail, I show you how to configure WordPress  to store shared media files (pictures, videos, etc) on Amazon Simple Storage Service (Amazon S3). Amazon S3 is a managed storage service that provides an affordable, performant, and secure method for storing all kinds of data. The interface between WordPress and Amazon S3 is the WP Offload Media Lite plug-in from Delicious Brains. The plug-in takes any file uploaded to WordPress and copies it over to Amazon S3 where your other WordPress instances tin access it.

Prerequisites

You should accept deployed your WordPress instance, and configured it to work with a standalone MySQL database in Lightsail.

In this post, I use additional AWS services beyond Lightsail. Yous need an AWS account with sufficient privileges to the residual of AWS.

Solution Overview

This web log covers how to install and configure the WP Offload Media Calorie-free plug-in with the post-obit steps:

  1. Create an Amazon S3 bucket to concur your media files.
  2. Add together an AWS Identity and Access Direction (IAM) user and policy.
  3. Update the WordPress configuration file with the user credentials.
  4. Install and configure the actual plug-in.
  5. Upload an epitome to WordPress to test it all out.

Solution

Create an S3 Bucket

This bucket hosts files that are publicly accessible on the Internet, so y'all must ensure your business relationship-wide S3 permissions allow for public bucket admission.

  1. Navigate to the S3 console.
  2. From the left-hand menu click Block public admission (account settings).
  3. If Cake all public access is checked, click Edit .
    If the bank check box is cleared and at to the lowest degree the first 2 sub boxes are also unchecked (see image below) y'all can move onto the next section.
    Otherwise go along with footstep 4.
  4. Clear the checkbox adjacent to Block all public access .
  5. For the application, y'all merely demand to allow access via ACL. And then, ensure the first two boxes are cleared and the final two are checked.picture 1, block public access
  6. Click Salvage Changes .
  7. Blazon confirm into the text box, and click Ostend .

Annotation: These settings are account wide, and so you must ensure that permissions on all buckets in your business relationship are fix appropriately.

Now that the public access permissions have been prepare accordingly, you can create your bucket.

  1. From the left-hand menu click Buckets .
    S3 bucket
  2. About the tiptop right click Create Bucket .
  3. Give your bucket a name. Note: All S3 saucepan names are globally unique, and then you lot cannot apply the same proper name every bit the one I use in this weblog .Make a notation of the name you cull, you demand to enter it into your WordPress configuration later in this tutorial.
    Cull the region for your saucepan. You should create all your resources for this tutorial in the same region, so make a note of which region you lot choose.
    Amazon S3 configuration
  4. Uncheck Block all public access, and so check the last ii sub boxes. This is similar to the steps yous took in the prior section. Only this time you are setting the policy for this particular bucket instead of the whole business relationship.block public access
  5. Check the box to acknowledge that you are making this bucket public.
    turning off public access
  6. Click Create saucepan.

You at present have a bucket to shop your media files. In the next section, you lot create an IAM user with the advisable permissions to copy files from WordPress into the S3 saucepan.

Create an IAM User

In society to store your media files on Amazon S3, WordPress needs to present credentials that prove information technology has the correct permissions. To practice and then, yous first create an IAM policy. Adjacent, you add a new IAM user and assign the policy you just created. One time the credentials are created, add together them to your WordPress configuration file.

Let'south outset by creating the IAM policy.

  1. Navigate to the IAM habitation page.
  2. From the left-hand menu click Policies.

IAM policies

       3. Near the height left click Create policy.

4. Click the JSON tab.
JSON editor

  1. Articulate the contents in the edit box, and paste in the text beneath. You demand to ensure you use the proper noun of the bucket y'all created in the previous steps where indicated .

Your text windows should look like to the one below, with the exception being your bucket name beingness used in the Resource section:

json editor

  1. Click Review policy .
  2. Name your policy wp-s3-policy and click Create policy .

Side by side you create a new user, and apply the policy you just created to that user.

  1. Click on Users from the left-hand menu.

IAM User

  1. Click the Add together user button at the height of the page.

add user

  1. Give the user a meaningful proper name, in my example I telephone call it wp-s3-user
  2. Cheque the Programmatic admission box

programatic access

  1. Click Side by side: Permissions
  2. Click Attach exiting policy directly and then in the Search box enter wp-s3-policy (without quotes)
  3. From the search results bank check the box next to wp-s3-policy .

setting new permissions

  1. Click Adjacent : Tags at the bottom of the screen
  2. Click Next:Review at the bottom of the screen
  3. Click Create User at the bottom of the screen

The next page then loads, and shows you the credentials you need to configure the WP Offload Media Calorie-free plug in.

Click Show under Undercover access key and copy and paste both values (Admission Key ID and Secret Access Key) into another document then y'all can reference them afterward. You can also download a CSV file with the information by clicking the button in the center of the screen

Important: If you navigate away from this screen, you will not exist able to obtain the credentials once more and will demand to create a new user. Be sure to either download the CSV or temporarily copy and paste both values into another document. Treat these credentials the same manner you'd treat any sensitive username / password pair .

Next, connect to your WordPress instance by using your own SSH client or the web-based SSH customer in the Lightsail panel.

wordpress IP

Once you're at the terminal prompt for your WordPress instance, yous demand to set two surroundings variables (ACCESS_KEY and SECRET_KEY) that contain the credentials for your IAM user.

To fix the surround variables substitute the values for your IAM user's access key and hole-and-corner key into the lines beneath and input each line 1 at a time at the terminal prompt:

ACCESS_KEY=AKIAIOSFODNN7EXAMPLE

SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Next, you must update your WordPress configuration file (wp-config) with the credentials.

First, copy and paste the following command to create a file with the credentials that you lot insert into the configuration file in the next step:

Next, copy and paste the following sed command to insert the temporary file you just created into the WordPress configuration file:

sed -i "/define( 'WP_DEBUG', false );/r credfile.txt" \
/dwelling/bitnami/apps/wordpress/htdocs/wp-config.php

The sed command changes the permissions on the WordPress configuration file. Copy and paste the post-obit control to reset it:

sudo chown bitnami:daemon /home/bitnami/apps/wordpress/htdocs/wp-config.php

Restart the services on the instance by copying and pasting the following command into the terminal window:

sudo /opt/bitnami/ctlscript.sh restart

After the services restart, your WordPress instance is configured to use the IAM credentials and y'all are set to configure the WP Offload Media Light plug-in.

Install and Configure the Plug-in

Now that the configuration file holds your credentials, y'all tin can movement on to installing and configuring the WP Offload Media Lite plug-in.

The next step requires you to log into the WordPress dashboard. To exercise that yous demand the Bitnami application password for your WordPress site. It's stored at /domicile/bitnami/bitnami_application_password.

Enter the following cat command in the terminal to display the value:

cat /dwelling house/bitnami/bitnami_application_password

This is the password for your WordPress dashboard:

password for dashboard

Log into the ambassador control console of your WordPress site. The WordPress login screen tin be accessed at http://SiteIpAddress/wp-admin , where SiteIpAddress is the IP accost of your WordPress instance, which can exist found on the card for your instance in the Lightsail console.

IP address

For example, the case above has the IP accost 192.0.2.0, so you'd access the login screen using http://192.0.ii.0/wp-admin.

Equally far as login credentials, the default user name is user. Employ the Bitnami application password you copied or wrote down previously.

Once signed in, install and configure the WP Offload Media Lite plugin by following these steps:

  1. From the left-hand menu click Plugins and Add new .

add new WP plugin

  1. On the add new plug-in page, enter WP media offload into the search bar.

WP media offload

  1. Click Install At present on the WP Offload Media Lite plugin.

installing plugin

After a few seconds the Install At present push will change to read Activate .

  1. Click the Activate
  2. You should be back to the WordPress plug-in screen.
    Scroll downward until you find WP Offload Media Lite. Information technology will exist most the bottom as the plugins are listed alphabetically. ClickSettings.

edit plug in

  1. Enter the name of the bucket you created before, and click Save Bucket Settings. Be sure to use your bucket name instead of the one in the image beneath.bucket name
    Note: You cannot apply 'Scan existing buckets' or 'Create new bucket' considering the security policy you created does not have the advisable permissions. Enabling those permissions would give the plug-in access to all your account's S3 buckets, which is not appropriate.

Your WordPress website is at present configured to upload files to the Amazon S3 bucket managed past the WP Offload Media Lite plugin.

Test the plug-in

You can test to run into if the plugin is working correctly by uploading a new media file, and verify it's being served from the Amazon S3 bucket. Follow these steps:

  1. From the left-hand card of the WordPress server click Media and then Add new.

adding new media in WP

  1. Either drag and driblet a file or click the Select button and choose a file from your local machine.
  2. After the file uploads click the Edit button next to the thumbnail

edit files

  1. On the right-hand side of the screen the File URL should point to your S3 bucket.

File URL to S3 bucjet

  1. Copy that URL into a browser and ensure your file loads up correctly.

Your media files are now being centrally served out of Amazon S3. At this point y'all're ready to finalize the look and feel of your site, and so calibration out the forepart – which y'all do in a subsequent blog postal service.

Determination

In this post y'all learned how to install and configure the Media Offload Low-cal plug-in. Your media files are now centrally served out of S3. You are fix to finalize the look and feel of your site and scale out the forepart terminate. A subsequent postal service in this serial explores that process.

hoernerhorwill.blogspot.com

Source: https://aws.amazon.com/blogs/compute/deploying-a-highly-available-wordpress-site-on-amazon-lightsail-part-2-using-amazon-s3-with-wordpress-to-securely-deliver-media-files/

Post a Comment for "Wordpress Plugin to Upload Files to Amazon S3"