Moving WordPress uploads to AWS S3

There are 2 plugins that make the magic work.

https://wordpress.org/plugins/amazon-s3-and-cloudfront/

Connects your install to the bucket of your choice and all future uploads will go to S3

https://wordpress.org/plugins/regenerate-thumbnails/installation/

This plugin will run on the existing uploads (if you have any) and regenerate them on S3 whilst updating your URLs in the posts/pages.

There is a pretty handy walk through here too if you are new to AWS permissions and buckets.

https://premium.wpmudev.org/blog/moving-wordpress-media-to-amazon-s3/

Installing WordPress in a subdirectory in a .NET application

When you install WordPress as a root web app using Web Platform Installer, everything just works. ¬†However, adding a WordPress blog to a subdirectory (e.g. /blog) needs quite a few extra steps beyond the base install¬†to get everything ‘working’.

Installing PHP

I used the PHP 7 32 bit. Before installing it you will need the Visual C++ Redistributable (again 32 bit)!

https://www.microsoft.com/en-gb/download/details.aspx?id=48145

Web.config in sub directory

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
      <clear/>
      <rule name="wordpress" patternSyntax="Wildcard">
        <match url=".*"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
        <action type="Rewrite" url="index.php"/>
      </rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

Web.config in root

No changes required

Permissions

The web.config in the root must have a few permissions added to it before things will work. Add IUSR(Should already by on) and IIS_IUSRS. This will allow the subdirectory to access the parent.

Virtual Application and App Pool

  • Remove the default application and app pool that the wordpress install created.
  • Create a new app pool (unmanaged code) and set the Identity (advanced settings) to LocalSystem
  • Re-add the virtual application and ensure you use the new app pool created above.

Uploads and Imports

To enable uploads to work I had to make a few changes

  • Php uploads to C:\Windows\Temp and then copies to the uploads directory. The problem is that the permissions get inherited. Create a new directory, add IIS_IUSRS permissions and update PHPini.php to point to this as the temp uploads folder.
  • Also in the wp-admin directory I found I needed to add a new phpini.php to allow for better memory management, as a relatively small data import would cause it to tank. Not sure if this is a required step but it seemed to help!
<?php

 phpinfo()

?>

memory_limit = 128M

Summary

So there you have it. There is definitely a learning curve to this if you’re not from PHP land, but overall the installation seems to be working!

Resources

A selection of resource that came in very handy to making this all happen!

http://serverfault.com/questions/613927/500-error-on-fresh-install-of-iis-and-php

http://www.mbrauchler.com/wordpress-image-upload-problem-using-iis-on-windows-server-2008/

https://wordpress.org/support/topic/iis-image-upload-view-issues

http://stackoverflow.com/questions/14966871/second-wordpress-installation-on-iis-server

https://wordpress.org/support/topic/wordpress-installation-on-root-folder-sub-folder-on-iis-server-url-conflict?replies=5