Tuesday 28 January 2014

Mod_Pagespeed in CentOS 6.4


PageSpeed Module


 

PageSpeed speeds up your site and reduces page load time.
This open-source web server module automatically applies web performance best practices to pages and associated
assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.



The goal of mod_pagespeed is to speed up your website. It does this by applying filters to a variety of files in order to reduce the number of trips the browser has to make to grab what it needs, to reduce the size of those files and to optimize the length those files are cached.


Features

    Automatic website and asset optimization
    Latest web optimization techniques
    40+ configurable optimization filters
    Free, open-source, and frequently updated
    Deployed by individual sites, hosting providers, CDNs

PageSpeed improves web page latency and bandwidth usage by changing the resources on that web page to implement web performance best practices.
Each optimization is implemented as a custom filter in PageSpeed, which are executed when the HTTP server serves the website assets.
Some filters simply alter the HTML content, and other filters change references to CSS, JavaScript, or images to point to more optimized versions.



Install & Compile mod_pagespeed with Apache in CentOS 6.4


----------------------------------------------------------------------------------------
1) Stop unwanted Services or settings
----------------------------------------------------------------------------------------
# /etc/init.d/NetworkManager stop
# chkconfig NetworkManager off
Note: Make sure you have configured Network i.e. (IP Address/Netmask/Gateway/DNS)

# vi /etc/sysconfig/selinux
SELINUX=disabled

----------------------------------------------------------------------------------------
2) Open Necessary Ports in iptables

----------------------------------------------------------------------------------------
# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
#/etc/init.d/iptables restart
#chkconfig iptables on

----------------------------------------------------------------------------------------------------
3) Install Dependencies for Apache (install as per your requirement.)
----------------------------------------------------------------------------------------------------

yum install make gcc automake zlib-devel bison cmake libtool wget gcc-c++ unzip ncurses-devel mod_ssl openssl openssl-devel php* pcre-devel libxml2-devel curl-devel gd-devel libxslt-devel  zlib* libtool* gcc*


----------------------------------------------------------------------------------------------------
4) Compile APR & APR Utils
----------------------------------------------------------------------------------------------------
#APR
#wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz

#tar -xvzf apr-1.4.6.tar.gz
#cd apr-1.4.6/
#./configure
#make
#make install
#cd ..


Note : if you get error= 

rm: cannot remove `libtoolT': No such file or directory issue. then follow the steps.
Edit your configure file

vi /softwares/apr-1.4.6/configure
Change the line

    $RM "$cfgfile"
      to
    $RM -f "$cfgfile"




# APR Utils
#wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz

#tar -xvzf apr-util-1.4.1.tar.gz
#cd apr-util-1.4.1
#./configure --with-apr=/usr/local/apr
#make
#make install



----------------------------------------------------------------------------------------
5) Install and Configure Apache
----------------------------------------------------------------------------------------

#/etc/init.d/httpd stop
#chkconfig httpd off
#cd /softwares/
#wget http://archive.apache.org/dist/httpd/httpd-2.2.25.tar.gz
#tar -zxvf httpd-2.2.25.tar.gz
#cd httpd-2.2.25
#./configure  --prefix=/opt/apache --with-apr=/usr/local/apr/ --enable-deflate
#make
#make install
#rm -rf /softwares/httpd-2.2.25
#vi /opt/apache/conf/httpd.conf

Listen 80
User apache
Group apache



#cp /etc/httpd/modules/libphp5* /opt/apache/modules/
#cp /etc/httpd/conf.d/php.conf /opt/apache/conf/


#/opt/apache/bin/apachectl -k restart


----------------------------------------------------------------------------------------------------
6)        ############ Mod Pagespeed Installation ############
----------------------------------------------------------------------------------------------------


#mkdir /opt/mod_pagespeed

if you do not already have installed
#yum install at

Download the mod_pagespeed RPM to build.
#wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm

#rpm2cpio mod-pagespeed-stable_current_x86_64.rpm | cpio -idmv
#cp usr/lib64/httpd/modules/mod_pagespeed.so /opt/apache/modules/
#chmod 755 /opt/apache/modules/mod_pagespeed.so

#mkdir -p /var/mod_pagespeed/{cache,files}
#chown nobody.nobody /var/mod_pagespeed/*


#Mod_Pagespeed has a dependency that you want to enable: mod_deflate
#Enable mod_deflate module with following command

#/opt/apache/bin/apxs -c -i /softwares/httpd-2.2.25/modules/filters/mod_deflate.c



Open pagespeed configuration file & Paste Following container in configuration file

#vi /opt/apache/conf/pagespeed.conf


############## mod_pagespeed Config ##############
LoadModule pagespeed_module /opt/apache/modules/mod_pagespeed.so

<IfModule pagespeed_module>
    ModPagespeed on
ModPagespeedFetchWithGzip on
SetOutputFilter DEFLATE

    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

ModPagespeedFileCachePath            "/var/mod_pagespeed/cache/"
ModPagespeedGeneratedFilePrefix      "/var/mod_pagespeed/files/"

ModPagespeedRewriteLevel PassThrough

ModPagespeedFileCacheSizeKb          102400
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedLRUCacheKbPerProcess     1024
ModPagespeedLRUCacheByteLimit        16384
ModPagespeedCssInlineMaxBytes        2048
ModPagespeedImageInlineMaxBytes      2048
ModPagespeedCssImageInlineMaxBytes   2048
ModPagespeedJsInlineMaxBytes         2048
ModPagespeedCssOutlineMinBytes       3000
ModPagespeedJsOutlineMinBytes        3000

ModPagespeedEnableFilters extend_cache,combine_css,move_css_to_head,rewrite_javascript,rewrite_images,add_head,rewrite_css,collapse_whitespace,remove_comments,remove_quotes,sprite_images,convert_meta_tags
ModPagespeedRespectVary on

    <Location /mod_pagespeed_beacon>
          SetHandler mod_pagespeed_beacon
    </Location>

    <Location /mod_pagespeed_statistics>
        Order allow,deny
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_statistics
    </Location>


############## mod_pagespeed Config ##############



Make a copy of your apache configuration httpd.conf file.
#cp /opt/apache/conf/httpd.conf /opt/apache/conf/httpd.conf-BACKUP


Edit and include the pagespeed configuration.
#vi /opt/apache/conf/httpd.conf

Include /opt/apache/conf/pagespeed.conf




Save and restart apache service.

#/opt/apache/bin/apachectl -k restart

Thats finished Test your page speed modules on website headers.

curl -I http://localhost    OR    http://127.0.0.1

Output :

HTTP/1.1 200 OK
Date: Tue, 28 Jan 2014 09:39:30 GMT
Server: Apache/2.2.25 (Unix) PHP/5.3.3
Accept-Ranges: bytes
X-Mod-Pagespeed: 1.6.29.7-3566
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 44
Content-Type: text/html






Check syntax
#httpd -M | grep page








Note :Enable Filters as per Your requirement (ModPagespeedEnableFilters in vi /opt/apache/conf/pagespeed.conf)



Ref:https://developers.google.com/speed/pagespeed/module
----------------------------------------------------------------------------------------------------
                                              Enjoy  mod_pagespeed
----------------------------------------------------------------------------------------------------

No comments:

Post a Comment