Is it possible to use AWS Beanstalk's .ebextensions config to install mod_pagespeed Apache module?
Asked Answered
G

4

10

I'm using AWS Beanstalk for my Django/Python application, and I would like to use Google's mod_pagespeed module. Is it possible to install and run mod_pagespeed using the .ebextensions/.config file?

Goodly answered 17/4, 2013 at 17:33 Comment(0)
A
6

Download the package

Add the rpm into your ebextensions directory

create a .config file in the .ebextensions directory

add commands to the config file like this:

container_commands:
    01-command:
        command:        rm -rf /pagespeed/ebextensions

    02-command:
        command:        mkdir -p /pagespeed/ebextensions

    03-command:
        command:        cp -R .ebextensions/* /pagespeed/ebextensions/

    04-command:
        command:        rpm -U /pagespeed/ebextensions/mod-pagespeed.rpm

Ensure the commands are indented as shown, with no tabs, otherwise it wont work.

swap "mod-pagespeed.rpm" for whatever the actual rpm file name is.

Affective answered 27/4, 2013 at 22:30 Comment(6)
Will that ensure that it is enabled as well?Goodly
the rpm installs the .conf files for you, if you find that you need to restart apache, add another command to the .config file for "apachectl restart"Affective
I would suggest to rewrite commands to the bash script, because container_commands runs any time when you do deploy. Bash script can check is it first time run and then install necessary changes. This will help you to decrease downtime during deployment.Congruent
@Vadim911 your statement seems a contradiction in terms - 'deploying' is just that (a first); which is what beanstalk is using in a auto-scaling act and thus where .ebextensions is most often used outside of an initial deployment. Can you clarify your post? To me it appears man2xxl is right on target.Correggio
@Correggio When I said "deploying", I mean process when you deploy bundle with .ebextentions and application to beanstalk.Congruent
@All, I would recommend to read nice and may best article regarding beanstalk customization: hudku.com/blog/…Congruent
G
3

Ok so I want to add Charlie Smith's answer. I would suggest you make sure you have the following things turned on.

  1. mod_deflate - You probably want to Gzip your html, css, xml, and javascript.
  2. Enable the rewrite domains filter in your Apache.conf if you use CDN (ex. AWS CloudFront)
  3. Set a short cache-control for images and css so pagespeed will be able to extend the cache when you turn on the extend_cache filter.
  4. I also like the rewrite_javascript, dns_prefetch, collapse_whitespace, and combine_javascript filters.

Here are the GitHub Gists that show you how its done.

Goodly answered 10/5, 2013 at 15:43 Comment(0)
B
3

Thanks guys! I got it working great following your answer @man2xxl.

You don't have to mess with the /pagespeed/extensions directory though, the beanstalk .ebextensions config can simply be:

packages:
  yum:
    at: []

10_setup_apache_for_mod_pagespeed:
  command: "cp enable_mod_pagespeed.conf /etc/httpd/conf.d"
20_install_mod_pagespeed:
  command: rpm -U -iv --replacepkgs mod-pagespeed-*.rpm
30_clear_mod_pagespeed_cache:
  command: touch /var/cache/mod_pagespeed/cache.flush
Barth answered 12/6, 2014 at 20:18 Comment(1)
This assumes you have the mod_pagespeed rpm included in the root of your repo.Sherburne
S
2

You can install packages by URL. So you don't have to download and distribute the RPM. Something like this works:

packages:
    rpm:
        pagespeed: https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
files:
    "/etc/httpd/conf.d/zzzz-pagespeed-options.conf":
        mode: "00644"
        owner: root
        group: root
        encoding: plain
        content: |
            # put your pagespeed configuration here

Note that I titled the file zzzz-pagespeed-options.conf so that the httpd server will load it last.

Another advantage of this is you really don't need include any commands whatsoever or worry about copying files over and maintaining the files in your .ebextensions folder. You just update the files entry in the .config file.

Shig answered 4/8, 2016 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.