Podcast Feed

Since my site has weekly MP3 uploads, it makes sense to create a podcast feed for it. Unfortunately, those updates were implemented with custom post types, which don’t generate podcast feeds automatically with the <enclosure> tags. Thus I would have to generate a custom feed myself.

The Codex page on Customizing Feeds explains how to get a custom post type to use my own custom feed. Since I’m using a child theme, I used get_stylesheet_directory() instead of get_template_directory().

When I first setup the custom post type and imported the existing content, the meta value _wp_attached_file included the full URL. It still does as the custom insert post functions for the custom post type have been written that way. Thus to generate the path to the file (to get the filesize for the RSS feed), I had to modify the output of get_attached_file() by using the get_attached_file filter.

Using the default RSS2 template as a starting point, I modified the template to produce a feed which more or less follows the iTunes format. The major challenge was getting the filesize of the MP3 files, this was done with the PHP filesize() function.

$size = filesize( get_attached_file( $child->ID ) );

The author and subtitle fields were field with the available post meta stored with the custom post type.

A strange problem I encountered was that this worked perfectly with iTunes on my test setup, but iTunes refused to recognize the feed properly on the live site. This was solved by using feedburner, and subscribing to the feedburner feed instead. However, this still doesn’t explain what’s wrong with the feed on the actual site which prevents iTunes from getting it properly.

Amazon Web Services

Amazon Web Services (AWS) provides computing resources in the cloud. You can get access to as many ‘machines’ as you’re willing to pay for, as well as storage, database services and many others. All these can be combined to create a rapidly scalable application.

AWS does provide a free usage tier, allowing anyone to sign up and try out the service for free for a year, as long as the application remains below limits. Full details of these limits can be found on their website.

The free usage tier includes 750 hours of an EC2 micro instance, enough to run a little web server. The rest of this post will give a brief overview of how to get WordPress running on EC2.

Start by creating a new instance in the region of your choice. The Amazon Machine Images (AMIs) which are free to use are marked with a yellow star. AWS has recently started offering Ubuntu as a free image. This has made it much easier for me to get stuff working.

AWS provides instructions on how to create a SSH key and use it to login to the instance. If you want to allow others or other machines to login, generate SSH keys for them and place the public portion in the /home/ubuntu/.ssh/authorized_keys file.

Install Apache, PHP and MySQL using apt-get. This is basic LAMP setup stuff.

Install SVN. This is optional, but I like using SVN to install WordPress because it’s so easy to update.

To change the location of the webroot folder, change the DocumentRoot setting of /etc/apache2/sites-enabled/000-default

For permalinks to work, mod_rewrite must be enabled. Also, the AllowOverride setting in the 000-default apache configuration file must be set to ‘all’.

From the AWS Management Console, click on the instance to see its public DNS information. This address is the publicly accessible IP address. The full domain name ending in ec2-xxx-xxx-xx-xx..compute.amazonaws.com can be used for the WordPress site and home URLs. You can also create a shorter address with DynDNS and point it to the IP address given.

Before your web server can be reached from the internet, there’s one more thing to do. Go to Security Groups in the AWS Management Console, it’s under the Network & Security section. Select the security group used by your instance. Add a new inbound rule for port 80 (HTTP). This is necessary for the web server to be publicly accessible.

Now that everything is ready, use any method you like to install WordPress. Remember to create a database and user first.