Thankfully, I managed to get this configured using only
.ebextensions configs. I created the following config file...
command: wget https://tn123.org/mod_xsendfile/mod_xsendfile.c
command: apxs -cia mod_xsendfile.c
First, this ensures that the correct version of httpd-devel is installed along with apxs, which is required to compile Apache extensions.
apxs isn't included in any EB version of Amazon Linux by default, and since the stock AMI for php 5.6 includes Apache 2.4, we have to make sure that we use the specific yum package for httpd24.
Next, we run two custom commands: The first command downloads
mod_xsendfile to the home directory (which is always
/home/ec2-user/ on Amazon Linux), while the second compiles it. Since this happens every time an instance is created,
mod_xsendfile will always be ready for use by the time apache is started.
It turns out this was actually a pretty simple solution, and it can be used to ensure any Apache package is downloaded and compiled every time a new instance is created on AWS Elastic Beanstalk.
NOTE: If you wanted to make this more fault-tolerant (such as if the
mod_xsendfile link was ever offline when an instance was being spun up), you could host the file somewhere else, like S3, and load it from there instead.
But this gets it working, at least... no custom AMI needed!