Best PPA for Nginx with Google Pagespeed

I’ve been trying to install PageSpeed on an existing Nginx server for the last 12 hrs with no luck, I keep running into different errors and having to read over and again to solve them. This is my first VPS

But I understand that some PPAs have this inbuilt. I don’t mind starting a new server to have this installed from the scratch and rebuild WP on it. I know that Easyengine had it but took Pagespeed out in Ver 3.6

Any other PPA suggestions will be welcome

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


Before We Get Started

This is meant to be a copy and paste command, meaning you copy it from top to bottom and paste it to the CLI, then hit enter and let it run its course.

This installs NGINX w/Pagespeed, PHP 7.1, and MariaDB, but it will take a little bit of time to complete, so be patient; source compiles take time.

I’ve provided configuration samples for NGINX and your first Server Block below the command with a few details. This should get you started with a working build environment. You’ll still need to create your database(s), upload your PHP files, etc.

Finally … this is a long post. Take your time :-).

The One-Liner

apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install autoconf automake bc bison build-essential ccache cmake curl dh-systemd flex gcc geoip-bin google-perftools g++ icu-devtools libacl1-dev libbz2-dev libcap-ng-dev libcap-ng-utils libcurl4-openssl-dev libdmalloc-dev libenchant-dev libevent-dev libexpat1-dev libfontconfig1-dev libfreetype6-dev libgd-dev libgeoip-dev libghc-iconv-dev libgmp-dev libgoogle-perftools-dev libice-dev libice6 libicu-dev libjbig-dev libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev libluajit-5.1-2 libluajit-5.1-common libluajit-5.1-dev liblzma-dev libmhash-dev libmhash2 libmm-dev libncurses5-dev libnspr4-dev libpam0g-dev libpcre3 libpcre3-dev libperl-dev libpng-dev libpng12-dev libpthread-stubs0-dev libreadline-dev libselinux1-dev libsm-dev libsm6 libssl-dev libtidy-dev libtiff5-dev libtiffxx5 libunbound-dev libvpx-dev libvpx3 libwebp-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxml2-dev libxpm-dev libxslt1-dev libxt-dev libxt6 make nano perl pkg-config software-properties-common systemtap-sdt-dev unzip webp wget xtrans-dev zip zlib1g-dev zlibc \
&& add-apt-repository -y ppa:ondrej/php \
&& apt-get update \
&& apt-get -y install php7.1-cli php7.1-dev php7.1-fpm php7.1-bcmath php7.1-bz2 php7.1-common php7.1-curl php7.1-gd php7.1-gmp php7.1-imap php7.1-intl php7.1-json php7.1-mbstring php7.1-mysql php7.1-readline php7.1-recode php7.1-soap php7.1-sqlite3 php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache php7.1-xsl php-yaml \
&& mkdir -p /usr/local/src/packages/{modules,nginx,openssl,pcre,zlib} \
&& mkdir -p /etc/nginx/{cache/{client,fastcgi,proxy,uwsgi,scgi},config/php,lock,logs,modules,pid,sites,ssl} \
&& useradd -d /etc/nginx nginx \
&& cd /usr/local/src/packages/nginx \
&& wget \
&& tar xvf nginx-1.11.10.tar.gz --strip-components=1 \
&& cd /usr/local/src/packages/openssl \
&& wget \
&& tar xvf openssl-1.1.0e.tar.gz --strip-components=1 \
&& cd /usr/local/src/packages/pcre \
&& wget \
&& tar xvf pcre-8.40.tar.gz --strip-components=1 \
&& cd /usr/local/src/packages/zlib \
&& wget \
&& tar xvf zlib-1.2.11.tar.gz --strip-components=1 \
&& cd /usr/local/src/packages/modules \
&& wget \
&& tar zxf v0.32.tar.gz \
&& wget \
&& tar zxf v0.3.0.tar.gz \
&& wget \
&& tar zxf 2.3.tar.gz \
&& cd /usr/local/src/packages/modules/ \
&& wget${NPS_VERSION} \
&& unzip v${NPS_VERSION} \
&& cd /usr/local/src/packages/modules/ngx_pagespeed-${NPS_VERSION}-beta \
&& psol_url=${NPS_VERSION}.tar.gz \
&& [ -e scripts/ ] && psol_url=$(scripts/ PSOL_BINARY_URL) \
&& wget ${psol_url} \
&& tar -xzvf $(basename ${psol_url}) \
&& cd /usr/local/src/packages/nginx \
&& ./configure --prefix=/etc/nginx \
               --sbin-path=/usr/sbin/nginx \
               --conf-path=/etc/nginx/config/nginx.conf \
               --lock-path=/etc/nginx/lock/nginx.lock \
               --pid-path=/etc/nginx/pid/ \
               --error-log-path=/etc/nginx/logs/error.log \
               --http-log-path=/etc/nginx/logs/access.log \
               --http-client-body-temp-path=/etc/nginx/cache/client \
               --http-proxy-temp-path=/etc/nginx/cache/proxy \
               --http-fastcgi-temp-path=/etc/nginx/cache/fastcgi \
               --http-uwsgi-temp-path=/etc/nginx/cache/uwsgi \
               --http-scgi-temp-path=/etc/nginx/cache/scgi \
               --user=nginx \
               --group=nginx \
               --with-poll_module \
               --with-threads \
               --with-file-aio \
               --with-http_ssl_module \
               --with-http_v2_module \
               --with-http_realip_module \
               --with-http_addition_module \
               --with-http_xslt_module \
               --with-http_image_filter_module \
               --with-http_sub_module \
               --with-http_dav_module \
               --with-http_flv_module \
               --with-http_mp4_module \
               --with-http_gunzip_module \
               --with-http_gzip_static_module \
               --with-http_auth_request_module \
               --with-http_random_index_module \
               --with-http_secure_link_module \
               --with-http_degradation_module \
               --with-http_slice_module \
               --with-http_stub_status_module \
               --with-stream \
               --with-stream_ssl_module \
               --with-stream_realip_module \
               --with-stream_geoip_module \
               --with-stream_ssl_preread_module \
               --with-google_perftools_module \
               --with-pcre=/usr/local/src/packages/pcre \
               --with-pcre-jit \
               --with-zlib=/usr/local/src/packages/zlib \
               --with-openssl=/usr/local/src/packages/openssl \
               --add-module=/usr/local/src/packages/modules/ngx_devel_kit-0.3.0 \
               --add-module=/usr/local/src/packages/modules/headers-more-nginx-module-0.32 \
               --add-module=/usr/local/src/packages/modules/ngx_cache_purge-2.3 \
               --add-module=/usr/local/src/packages/modules/ngx_pagespeed- \
&& make \
&& make install

Once the above completes, we need to run the following, which will delete our existing NGINX config and files we don’t need.

rm -rf /etc/nginx/config/nginx.conf \
&& rm -rf /etc/nginx/config/*.default

Now, we’ll implement our actual NGINX configuration by creating a new NGINX configuration file.

nano /etc/nginx/config/nginx.conf

and paste in:

user                                                    nginx nginx;
worker_processes                                        1;
worker_priority                                         -10;

worker_rlimit_nofile                                    260000;
timer_resolution                                        100ms;

pcre_jit                                                on;

events {
    worker_connections                                  10000;
    accept_mutex                                        off;
    accept_mutex_delay                                  200ms;
    use                                                 epoll;

http {
    map_hash_bucket_size                                128;
    map_hash_max_size                                   4096;
    server_names_hash_bucket_size                       128;
    server_names_hash_max_size                          2048;
    variables_hash_max_size                             2048;

    index                                               index.php index.html index.htm;
    include                                             mime.types;
    default_type                                        application/octet-stream;
    charset                                             utf-8;

    sendfile                                            on;
    sendfile_max_chunk                                  512k;
    tcp_nopush                                          on;
    tcp_nodelay                                         on;
    server_tokens                                       off;
    server_name_in_redirect                             off;

    keepalive_timeout                                   5;
    keepalive_requests                                  500;
    lingering_time                                      20s;
    lingering_timeout                                   5s;
    keepalive_disable                                   msie6;

    gzip                                                on;
    gzip_vary                                           on;
    gzip_disable                                        "MSIE [1-6]\.";
    gzip_static                                         on;
    gzip_min_length                                     1400;
    gzip_buffers                                        32 8k;
    gzip_http_version                                   1.0;
    gzip_comp_level                                     5;
    gzip_proxied                                        any;
    gzip_types                                          text/plain

    client_body_buffer_size                             256k;
    client_body_in_file_only                            off;
    client_body_timeout                                 10s;
    client_header_buffer_size                           64k;
    client_header_timeout                               5s;
    client_max_body_size                                50m;
    connection_pool_size                                512;
    directio                                            4m;
    ignore_invalid_headers                              on;
    large_client_header_buffers                         8 64k;
    output_buffers                                      8 256k;
    postpone_output                                     1460;
    proxy_temp_path                                     /etc/nginx/cache/proxy;
    request_pool_size                                   32k;
    reset_timedout_connection                           on;
    send_timeout                                        10s;
    types_hash_max_size                                 2048;

    open_file_cache                                     max=50000 inactive=60s;
    open_file_cache_valid                               120s;
    open_file_cache_min_uses                            2;
    open_file_cache_errors                              off;
    open_log_file_cache                                 max=10000 inactive=30s min_uses=2;

    include                                             /etc/nginx/sites/*.conf;

Now we’ll create our PHP FastCGI Params file, much like we did the above.

nano /etc/nginx/config/php/fastcgi_params.conf

and paste in:

    fastcgi_param  SCRIPT_FILENAME    $request_filename;

    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 1m;
    fastcgi_temp_file_write_size 4m;
    fastcgi_max_temp_file_size 4m;
    fastcgi_intercept_errors off;

    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;

    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    fastcgi_param  HTTP_PROXY         "";

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;

    fastcgi_param  REDIRECT_STATUS    200;

Ok, now we need to create a server block for your domain, so we’ll create that now. Simply replace with your actual domain.

nano /etc/nginx/sites/

and paste in:

    listen                          80 default_server;
    listen                          [::]:80;
    server_name           ;

    root                            /home/username/htdocs/public;

    location /
        try_files $uri $uri/ =404;

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass   /run/php/php7.1-fpm.sock;
        fastcgi_index  index.php;

        include /etc/nginx/config/php/fastcgi_params.conf;

Change /home/username/htdocs/public to the actual directory where you’re installing WordPress (i.e. where the WordPress index.php file resides).

Finally, we need to make sure PHP-FPM can read/write on your files, so whichever directory you set as the root above, i.e. /home/username/htdocs/public, we need to change ownership of everything to www-data.

chown -R www-data:www-data /home/username/htdocs/public

That’ll make all files and directories owned by www-data, as they should be. Now we just need to start NGINX and restart PHP-FPM for good measure.

Type in nginx and hit enter, then:

system php7.1-fpm restart


You don’t specifically need a PPA as they have their own auto-installer that’s available. It’ll automate a source build of NGINX w/ ngx_pagespeed as a module. All you need to do is run:

bash <(curl -f -L -sS --nginx-version latest

… and follow the on-screen prompts.

Keep in mind, this is a very barebones installation of NGINX. If you need specific modules compiled in, you’ll need to specify those when the script prompts you.


Ive written a tutorial on this lEMP stack pagespeed mod. Hope this helps anyone needing mariadb php7 pagespeed mod nginx and letsencrypt