I realize there's no yum package for mod_xsendfile (which is a huge bummer), so I'm wondering if it's at all possible to add it via an .ebextensions config given that it needs to be downloaded and compiled.

Is it even possible to do this solely with .ebextensions configs or do I need to create and maintain a custom AMI to get this working on Elastic Beanstalk? If it is possible, how do I configure it without a yum package?


In addition to your own answer:

Besides httpd24-devel, you will also need gcc installed or apxs -cia mod_xsendfile.c will fail.


Thankfully, I managed to get this configured using only .ebextensions configs. I created the following config file...

        httpd24-devel: []
        command: wget https://tn123.org/mod_xsendfile/mod_xsendfile.c
        cwd: /home/ec2-user
        ignoreErrors: true
        command: apxs -cia mod_xsendfile.c
        cwd: /home/ec2-user
        ignoreErrors: true

First, this ensures that the correct version of httpd-devel is installed along with apxs, which is required to compile Apache extensions.

Since 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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.