Difference between revisions of "GooglePageSpeed"

From wiki.mikejung.biz
Jump to navigation Jump to search
(Use Memcached)
Line 49: Line 49:
 
Make sure this line is commented out. Obviously this assumes you have memcached installed on the local host and listening on the default port. If you are using '''cpanel''' you will want to edit the pagespeed.conf file located at '''/usr/local/apache/conf/pagespeed.conf''', if you are using '''Ubuntu''' the file will be located at '''/etc/apache2/mods-enabled/pagespeed.conf'''
 
Make sure this line is commented out. Obviously this assumes you have memcached installed on the local host and listening on the default port. If you are using '''cpanel''' you will want to edit the pagespeed.conf file located at '''/usr/local/apache/conf/pagespeed.conf''', if you are using '''Ubuntu''' the file will be located at '''/etc/apache2/mods-enabled/pagespeed.conf'''
 
<pre>
 
<pre>
ModPagespeedFileCachePath            "/var/cache/mod_pagespeed/"
 
 
ModPagespeedMemcachedServers localhost:11211
 
ModPagespeedMemcachedServers localhost:11211
 
ModPagespeedCreateSharedMemoryMetadataCache "/var/cache/mod_pagespeed/" 51200
 
ModPagespeedCreateSharedMemoryMetadataCache "/var/cache/mod_pagespeed/" 51200
 +
ModPagespeedFileCachePath            "/var/cache/pagespeed/"
 +
ModPagespeedFileCacheSizeKb          102400
 +
ModPagespeedFileCacheCleanIntervalMs 3600000
 +
ModPagespeedFileCacheInodeLimit      500000
 +
ModPagespeedLRUCacheKbPerProcess  1024
 +
ModPagespeedLRUCacheByteLimit      16384
 
</pre>
 
</pre>
  
You can view memcached stats by running this command
+
You can view memcached stats by echoing stats and piping that into netcat.
 
<pre>
 
<pre>
 
echo stats | nc 127.0.0.1 11211
 
echo stats | nc 127.0.0.1 11211
 +
</pre>
 +
 +
To view pagespeed specific memcached statistics you can simply curl the url from localhost if you have access to the server. This will display all of the pagespeed and memcached specific information
 +
<pre>
 +
curl http://localhost/mod_pagespeed_statistics?memcached
 
</pre>
 
</pre>
  

Revision as of 17:41, 1 February 2015

Liquidweb 728x90.jpg

Links


  • PageSpeed can be added to any server runtime and applied dynamically to any application. This is available as a module for Apache and Nginx. This helps to optimize resources based on a lot of "web optimization filters".

Installation

This is for Ubuntu, however the same applies for Cent, just use yum and grab the .rpm instead

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

At this point, just restart / reload apache and you should be good to go.

Configuration

To modify the default settings, edit this file:

vim /etc/apache2/mods-enabled/pagespeed.conf

Default CoreFilter List

 add_head
   combine_css
   convert_meta_tags
   convert_png_to_jpeg
   extend_cache
   fallback_rewrite_css_urls
   flatten_css_imports
   inline_css
   inline_import_to_link
   inline_javascript
   rewrite_css
   rewrite_images
   rewrite_javascript
   rewrite_style_attributes_with_url

Use Memcached

Make sure this line is commented out. Obviously this assumes you have memcached installed on the local host and listening on the default port. If you are using cpanel you will want to edit the pagespeed.conf file located at /usr/local/apache/conf/pagespeed.conf, if you are using Ubuntu the file will be located at /etc/apache2/mods-enabled/pagespeed.conf

ModPagespeedMemcachedServers localhost:11211
ModPagespeedCreateSharedMemoryMetadataCache "/var/cache/mod_pagespeed/" 51200
ModPagespeedFileCachePath            "/var/cache/pagespeed/"
ModPagespeedFileCacheSizeKb          102400
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedFileCacheInodeLimit      500000
ModPagespeedLRUCacheKbPerProcess   1024
ModPagespeedLRUCacheByteLimit      16384

You can view memcached stats by echoing stats and piping that into netcat.

echo stats | nc 127.0.0.1 11211

To view pagespeed specific memcached statistics you can simply curl the url from localhost if you have access to the server. This will display all of the pagespeed and memcached specific information

curl http://localhost/mod_pagespeed_statistics?memcached

Control Default Filters

By default, the module uses "CoreFilters", which is a safe set of rules that most sites benefit from, if you want to disable everything and only enable certain items, you can do this globally here, however it's recommended to just enable / disable things per vhost using .htaccess or vhost directive. You would just uncomment the line below

# ModPagespeedRewriteLevel PassThrough

Include Additional Filters

If you want to globally enable more filters than the core rules offer you can uncomment these lines and just add the filters you want to enable.

# ModPagespeedEnableFilters rewrite_javascript,rewrite_css
# ModPagespeedEnableFilters collapse_whitespace,elide_attributes

.htaccess directives

You can specify additional filters in .htaccess, or in the main apache2.conf, or on the vhost level using a directive like this:

<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters remove_comments,rewrite_javascript,rewrite_css,rewrite_images
ModPagespeedEnableFilters elide_attributes,defer_javascript,move_css_to_head
ModPagespeedJpegRecompressionQuality -1
</IfModule>


Install PageSpeed Module on cPanel Server

Link: https://github.com/pagespeed/cpanel

This should be all you need to do, this was tested on CentOS 6.5 with WHM 11.40.1

git clone https://github.com/pagespeed/cpanel.git /var/cpanel/easy/apache/custom_opt_mods/Cpanel/

##Or use cPanel's git if you are unable to install via yum

/usr/local/cpanel/3rdparty/bin/git clone https://github.com/pagespeed/cpanel.git /var/cpanel/easy/apache/custom_opt_mods/Cpanel/

cd /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy && tar -zcvf Speed.pm.tar.gz pagespeed

##Now just run EA to enable the module

/scripts/easyapache

Now you can check to make sure the EA finished successfully and the module is enabled:

httpd -M

##You should see
 pagespeed_module (shared)

How to use Memcached with ModPageSpeed on a cPanel Server

If you are using cPanel and have mod_pagespeed installed you can modify the configuration file so that pagespeed uses memcached. This is not the base by default and if you want to speed up the site and use memory instead of just using disk you can edit the file listed below and enter in the IP and port of memcached. In this case I have memcached running on the same host. You will need to start apache after you are done editing the file.

vim /usr/local/apache/conf/pagespeed.conf

##Add These Lines
  ModPagespeedMemcachedServers 127.0.0.1:11211
  ModPagespeedMemcachedThreads 1
  ModPagespeedCreateSharedMemoryMetadataCache "/var/mod_pagespeed/cache" 51200