How to install Google PageSpeed with Amazon ElastiCache

How to improve the page loading times on your website using Google mod_pagespeed module for Apache. The Google PageSpeed module can be set to use the Amazon ElastiCache for caching of files. This takes load of Ubuntu and lets you focus the memory to run Apache.

 

After installing the Google PageSpeed module open the config file:

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

Scroll down to the section:

# If you want, you can use one or more memcached servers as the store for
# the mod_pagespeed cache.
 ModPagespeedMemcachedServers

Then add the address to your ElastiCache server.
Save the config file.
Restart Apache

sudo service apache2 restart

Change to Redis when it becomes available

Redis is a faster and better cache that memcache.

You shold change to redis when mod_pagespeed from Google starts to support Redis

Verify that PageSpeed works correctly

Your google page speed module has a web based reporting panel only available to localhost. You connect to the VPS server using SOCKS proxy through your SSHD server.

To access the Google page speed panel use the default HTTP:// access without SSL and the internal IP of you EC2 server.

The internal IP of your EC2  VPS server id displayed if you type

ifconfig

If the local IP of you EC2 VPS is 88.88.88.88 you can access the PageSpeed panel on the address:

http://88.88.88.88/pagespeed_admin/console

 

How to gain access to the PageSpeed panel

Check that you still have the HTML root folder

Check that you still have the default apache folder HTML

cd /var/www/
ls -a

If the necessary create the folder

sudo mkdir /var/www/html

For your reference create an index.html file

sudo nano /var/www/html/index.html

Tape some reference text in the file and then save it.

Then make sure that Apache can write to the folder

sudo chown www-data:www-data -R /var/www/html

 

Start the default port 80 Apache configuration

Every active Apache config file represents a potential entry point for the bad guys to your VPS. Every active Apache config drains your VPS server for memory. That is why only the config files you need should be active. In this case, you should activate the config file when you need to access the Google PageSpeed stats. Afterwards, disable the config file to block it as a possible entry point for bad guys and free up the resources.

To enable the config file:

sudo a2ensite 000-default.conf
sudo service apache2 restart

To deactivate the config file:

sudo a2dissite 000-default.conf
sudo service apache2 restart

Verify that you can access your server on port 80. If the local IP is 88.88.88.88, then you should be able to access the index.html file you have created in

/var/www/html/

by typing:

http://88.88.88.88/index.html

Don’t continue to the next step before this works

Allow the local IP to access Google PageSpeed panel

Open the page speed config file

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

Use “Ctrl + w” to search for

Allow from 127.0.0.1

Then add the local IP for your EC2 VPS server.

If the IP is 88.88.88.88 then this part of the config file would look like this:

 

 

 <Location /pagespeed_admin>
 Order allow,deny
 Allow from localhost
 Allow from 127.0.0.1
 Allow from 88.88.88.88
 SetHandler pagespeed_admin
 </Location>
 <Location /pagespeed_global_admin>
 Order allow,deny
 Allow from localhost
 Allow from 127.0.0.1
 Allow from 88.88.88.88
 SetHandler pagespeed_global_admin
 </Location>

Save the config file.

Restart Apache

sudo service apache2 restart

Connect to your VPS with VPN

Finally, connect to your EC2 VPS server using SOCKS proxy VPN.

The Google PageSpeed stats and info should now be able at:

http://88.88.88.88/pagespeed_admin/console
How to access your VPS through SOCKS VPN