How to speed up apache with mod_pagespeed and Memcached on Ubuntu 15.10

Datetime:2016-08-23 01:28:27         Topic: Memcached          Share        Original >>
Here to See The Original Article!!!

This tutorial exists for these OS versions

On this page

  1. Installation of mod_pagespeed
  2. Installation of Memcached
  3. 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:

uname -a

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)

cd /tmp


dpkg -i mod-pagespeed-stable_current_amd64.deb

Ubuntu 32 bit

cd /tmp


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:

nano /etc/apache2/mods-available/pagespeed.conf

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:


ModPagespeedMemcachedServers localhost:11211


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 11211

[email protected]

:/tmp# echo stats | nc 11211STAT pid 1636STAT uptime 254STAT time 1460561250STAT version 1.4.24 UbuntuSTAT libevent 2.0.21-stableSTAT pointer_size 64STAT rusage_user 0.000000STAT rusage_system 0.020000STAT curr_connections 6STAT total_connections 8STAT connection_structures 7STAT reserved_fds 20STAT cmd_get 34STAT cmd_set 15STAT cmd_flush 0STAT cmd_touch 0STAT get_hits 14STAT get_misses 20STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 8573STAT bytes_written 22539STAT limit_maxbytes 67108864STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT malloc_fails 0STAT bytes 6856STAT curr_items 9STAT total_items 15STAT expired_unfetched 0STAT evicted_unfetched 0STAT evictions 0STAT reclaimed 0STAT crawler_reclaimed 0STAT crawler_items_checked 0STAT lrutail_reflocked 0



Put your ads here, just $200 per month.