This tutorial exists for these OS versions
On this page
- Installation of mod_pagespeed
- Installation of Memcached
- Configure mod_pagespeed to use Memcached
This tutorial will show you how to improve the page load times of your website by using the Google mod_pagespeed module for Apache in conjunction with the fast in-memory cache Memcached on Ubuntu 15.10 (Wiley Werewolf). The page load time is an important factor to get good rankings in search engines, you can test the current load time e.g. with the Google PageSpeed Insights tool or with the developer tools in the Firefox web browser. Pagespeed is an Apache 2 module that optimizes and caches the content of a website before it gets delivered to the browser, the result is that the page loads, the system load on your server decreases and the server will be able to deliver more pages per second. Mod_pagespeed uses a filesystem cache by default, in this tutorial, we will replace the filesystem cache with Memcached, a fast in-memory caching daemon which will further improve the load time. This tutorial is compatible with all kind of apache setups, I will use aUbuntu LAMPserver as basis but you may also use on of the ISPConfig 3 Perfect Server tutorials.
Installation of mod_pagespeed
Google provides mod_pagespeed .deb packages for 32 and 64-bit Ubuntu installations.
How to find out if you need the 32bit or 64Bit package? Run the command:
The result of the command should be similar to the screenshot below.
When the command contains the string "x86_64" then your system runs a 64Bit Linux kernel. In this case, use the commands provided below for 64Bit Ubuntu.
Ubuntu 64 bit(Default for most current servers)
dpkg -i mod-pagespeed-stable_current_amd64.deb
Ubuntu 32 bit
dpkg -i mod-pagespeed-stable_current_i386.deb
Then restart Apache 2 to load the mod_pagespeed configuration.
service apache2 restart
Installation of Memcached
The Memcached daemon is available in the Ubuntu repositories as .deb package an can be installed with apt:
apt-get -y install memcached
Run the command "netstat -tap | grep memcached" to see if Memcached is started:
netstat -tap | grep memcached
The result of the netstat command shall look like this:
The Port is shown right after the word localhost, in this case the port is 11211 which is the default port of memcached. We need to know that port number for the mod_pagespeed configuration.
If you like to use Memcache from your PHP based applications and not just for mod_pagespeed, then install the PHP Memcached extension:
apt-get install php5-memcached
Configure mod_pagespeed to use Memcached
Open the pagespeed.conf file in an editor, I will use the nano editor here:
and search for the line " ModPagespeedMemcachedServers":
# ModPagespeedMemcachedServers localhost:11211
Remove the # in front of the line so that the resulting line looks like the one below:
If you have plenty of memory in your server, then you can get a further speedup by removing the # in front of this line:
ModPagespeedCreateSharedMemoryMetadataCache "/var/cache/mod_pagespeed/" 51200
Then restart the Apache 2 server to activate the new configuration.
service apache2 restart
Now mod_pagespeed will use Memcached as storage backend. You can get usage statistics from Memcached with the nc command:
echo stats | nc 127.0.0.1 11211