部署 Mod_PageSpeed

环境
Debian 7 x64 (查看系统位:getconf LONG_BIT

下载 mod_pagespeed

mkdir ~/mod_pagespeed cd ~/mod_pagespeed wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb

解包 deb

ar -x mod-pagespeed-stable_current_amd64.deb

解压

tar zxvf data.tar.gz

复制配置

cp ./etc/apache2/mods-available/pagespeed.conf /wp-content/local/apache/conf/
cp ./etc/apache2/mods-available/pagespeed.load /wp-content/local/apache/conf/
cp ./etc/apache2/conf.d/pagespeed_libraries.conf /wp-content/local/apache/conf/
cp ./wp-content/bin/pagespeed_js_minify /wp-content/local/apache/bin/
cp ./wp-content/lib/apache2/modules/mod_pagespeed_ap24.so /wp-content/local/apache/modules/
#cp ./wp-content/lib/apache2/modules/mod_pagespeed.so /wp-content/local/apache/modules/
// 查看 Apache 版本:apachectl -v
// 当 Apache 版本≥2.4.2 选择 pagespeed_ap24.so,否则 pagespeed.so

赋予权限

chmod 755 /wp-content/local/apache/modules/mod_pagespeed_ap24.so
#chmod 755 /wp-content/local/apache/modules/mod_pagespeed.so
mkdir /var/mod_pagespeed_cache
chown www.www /var/mod_pagespeed_cache

pagespeed.conf 添加

LoadModule pagespeed_module /wp-content/local/apache/modules/mod_pagespeed_ap24.so

引用配置

echo 'Include conf/pagespeed.conf' >> /wp-content/local/apache/conf/vhost/t.bpplpp.com.conf

检查

/wp-content/local/apache/bin/apachectl -t

报错

httpd: Syntax error on line 511 of /wp-content/local/apache/conf/httpd.conf: Syntax error on line 1 of /wp-content/local/apache/conf/pagespeed.conf: Cannot load /wp-content/local/apache/modules/mod_pagespeed_ap24.so into server: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /wp-content/local/apache/modules/mod_pagespeed_ap24.so)

解决
查看系统支持 GLIBC 版本

strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_

升级 GLIBC

wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz
tar zxvf glibc-2.14.tar.gz
cd glibc-2.14
mkdir build
cd ./build
../configure --prefix=/opt/glibc-2.14
make -j4

报错

make[1]: *** No rule to make target `/root/glibc-2.14/build/Versions.all', needed by `/root/glibc-2.14/build/abi-versions.h'. Stop.

解决

`cd wget http://ftp.gnu.org/gnu/gawk/gawk-4.1.4.tar.gz tar zxvf gawk-4.1.4.tar.gz cd gawk-4.1.4 ./configure --prefix=/usr --libexecdir=/wp-content/lib make make check make install

已解决所有细节问题。

再次执行

make -j4
make install

修改环境变量nano ~/.bashrc

添加LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH

搞定 GLIBC 问题。

再次检查 – 问题还发生,暂停折腾。

/wp-content/local/apache/bin/apachectl -t

检查运行情况

apachectl -t -D pagespeed_module | grep pagespeed
service httpd restart

参考

http://my.oschina.net/zhangxu0512/blog/262275
http://www.cnblogs.com/emanlee/p/4311901.html
http://www.hudongdong.com/skill/159.html

基础知识不够花了大量精力和时间查找资料,暂时没能在 Centos 搭建成功,虽然看到很多人成功并使用了,但目前正使用 Debian 8 x64 服役中。