awswordpress-pro

Configure WordPress for cloud storage on Amazon S3

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

NOTE: Before following the steps in this guide, ensure that you have an Amazon Web Services account with (optionally) an IAM user account and the corresponding AWS access key and secret key. You should also install and activate the WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage plugin in your WordPress blog (instructions).

To configure Amazon S3 storage for your WordPress blog, follow these steps:

  • Log in to your server console.

  • Open the WordPress wp-config.php configuration file in a text editor and add the following lines to the file, after the initial <?php PHP tag:

    NOTE: Depending on your installation type, the WordPress wp-config.php configuration file can be found in the following locations:

    • Approach A (Bitnami installations using system packages): /opt/bitnami/wordpress/wp-config.php

    • Approach B (Self-contained Bitnami installations): /opt/bitnami/apps/wordpress/htdocs/wp-config.php

      define( 'AS3CF_SETTINGS', serialize( array(
        'provider' => 'aws',
        'access-key-id' => 'XXXX
        'secret-access-key' => 'XXXX'
      ) ) );
    

    Remember to replace the XXXX placeholders in the above lines with your actual AWS access key and secret key.

    S3 configuration

  • Save the file.

Next:

  • Log in to your WordPress blog as an administrator.

  • Select the “Settings -> Offload Media” menu item. Select the “Amazon S3” radio button and click “Next”.

  • Click the “Create new bucket” link. You can also choose an existing bucket if you prefer.

  • On the resulting page, create a new S3 bucket to store your WordPress media files by selecting a region, entering a unique bucket name and clicking the “Create New Bucket” button.

  • Once the bucket has been created, you’ll be transferred to a page where you can configure plugin behaviour. Ensure that the “Copy Files to Bucket” and “Rewrite Media URLs” options are turned on. Other settings can be left at their default values or modified per your preference.

    S3 configuration

  • Click “Save Changes” to save your settings.

You can now add pages and posts to WordPress as normal. When you add a media file using the WordPress editor or media library, your media file will be uploaded to both the WordPress blog and the chosen S3 bucket.

The plugin will automatically rewrite URLs so that the media is served from S3 instead of from your WordPress host. In the screenshot below, refer to the image information panel, which shows the S3 bucket URL for the image.

S3 usage in WordPress

Last modification September 7, 2021