skip to Main Content

I have a docker based apache httpd server. I need to install mod_pagespeed into that.

The flavour I am using is debian based not alpine based for now – for some reasons.

Following is the list of commands required to install the module in debian/ubuntu dist – from the official site

wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-*.deb
sudo apt-get -f install

This is giving error

dpkg: dependency problems prevent configuration of mod-pagespeed-stable:
 mod-pagespeed-stable depends on apache2; however:
  Package apache2 is not installed.

This is obvious because there is no apache2 service installed, only httpd command works.

Even the folder structure is different then regular debian/ubuntu installation.

I don’t find any .so file anywhere, otherwise I can put it in some directory and do a LoadModule.

I guess I need to do a custom build from source, is there any easy way?

2

Answers


  1. Chosen as BEST ANSWER

    Mostly @Michael's answer is correct, however for those who uses default docker's apache module (like me) following answer would suffice.

    Because debian's apache installation is different than docker apache's installation. (And if you already have setup/customised all the configuration and cannot re-customise to be debian's structure)

    I have built the pagespeed module from that answer and then copied the module to my installation.

    Dockerfile

    FROM debian:stretch as pagespeed
    
    ENV APACHE_RUN_USER www-data
    ENV APACHE_RUN_GROUP www-data
    ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
    ENV APACHE_RUN_DIR /var/run/apache2
    ENV APACHE_LOCK_DIR /var/lock/apache2
    ENV APACHE_LOG_DIR /var/log/apache2
    ENV LANG C
    
    RUN apt-get update 
        && DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 wget 
        && wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb -O /tmp/modpagespeed.deb 
        && dpkg -i /tmp/modpagespeed.deb
    
    FROM httpd:2.4.43
    
    # all these things are my custom configuration. You probably don't need these
    COPY --chown=root:www-data ./docker-assets/httpd-custom.conf $HTTPD_PREFIX/conf/httpd.conf
    COPY --chown=root:www-data ./docker-assets/httpd-default.conf $HTTPD_PREFIX/conf/extra/httpd-default.conf
    COPY --chown=root:www-data ./docker-assets/httpd-vhosts-custom.conf $HTTPD_PREFIX/conf/extra/httpd-vhosts.conf
    COPY --chown=root:www-data ./docker-assets/httpd-ssl.conf $HTTPD_PREFIX/conf/extra/httpd-ssl.conf
    COPY --chown=root:www-data ./docker-assets/httpd-mpm.conf $HTTPD_PREFIX/conf/extra/httpd-mpm.conf
    
    # pagespeed module adding as custom build here. You may need to change some paths in .load file
    COPY --chown=root:www-data ./docker-assets/pagespeed.load $HTTPD_PREFIX/conf/extra/
    COPY --chown=root:www-data ./docker-assets/pagespeed.conf $HTTPD_PREFIX/conf/extra/
    COPY --chown=root:www-data ./docker-assets/pagespeed_libraries.conf $HTTPD_PREFIX/conf/extra/
    # Or directly copy from build stage
    # COPY --from=pagespeed --chown=root:www-data /etc/apache2/mods-available/pagespeed.conf $HTTPD_PREFIX/conf/extra/
    # COPY --from=pagespeed --chown=root:www-data /etc/apache2/conf-available/pagespeed_libraries.conf $HTTPD_PREFIX/conf/extra/
    COPY --from=pagespeed --chown=root:www-data /usr/lib/apache2/modules/mod_pagespeed.so $HTTPD_PREFIX/modules/
    COPY --from=pagespeed --chown=root:www-data /usr/lib/apache2/modules/mod_pagespeed_ap24.so $HTTPD_PREFIX/modules/
    # pagespeed end
    

  2. You may use the following Dockerfile as a base:

    FROM debian:stretch
    
    ENV APACHE_RUN_USER www-data
    ENV APACHE_RUN_GROUP www-data
    ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
    ENV APACHE_RUN_DIR /var/run/apache2
    ENV APACHE_LOCK_DIR /var/lock/apache2
    ENV APACHE_LOG_DIR /var/log/apache2
    ENV LANG C
    
    RUN apt-get update 
        && DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 wget 
        && wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb -O /tmp/modpagespeed.deb 
        && dpkg -i /tmp/modpagespeed.deb
    
    RUN mkdir -p /var/log/apache2 /var/run/apache2 /var/lock/apache2 
        && chown www-data:www-data /var/log/apache2 /var/run/apache2 /var/lock/apache2
    
    CMD ["apache2", "-DFOREGROUND"]
    
    EXPOSE 80
    

    Build the image and launch a container, you’ll get a response header similar to X-Mod-Pagespeed: 1.13.35.2-0.

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search