Archive for the ‘Apache’ Category

Posted by 6bytes at 17 November 2010

Category: Apache, CentOS

Tags: , , , ,

I’m not going to write about whether I think mod_pagespeed is good or not, is it suitable for your website, why you should use it or not. I’ll focus only on installation.

Since you’re here and still reading I assume you want to speed up your website with Google’s mod_pagespeed. If you’re on a machine where for any reason installing from .rpm or .deb is not possible read on.

Dependencies

First we need to install Chromium ‘depot_tools’, which are used to build multiple open-source projects with dependencies on other open-source projects.

mkdir ~/bin
cd ~/bin
svn co http://src.chromium.org/svn/trunk/tools/depot_tools

You will need to add the depot_tools to your path. i.e. in bash:

export PATH=$PATH:~/bin/depot_tools

Check out mod_pagespeed and dependencies

mkdir ~/mod_pagespeed    # any directory is fine
cd ~/mod_pagespeed
# always check for latest version by going to http://modpagespeed.googlecode.com/svn/tags/ in your browser
# then copy link to /src ie. http://modpagespeed.googlecode.com/svn/tags/X.X.X.X/src
gclient config  http://modpagespeed.googlecode.com/svn/tags/0.9.1.1/src
gclient sync --force     # this will download all source code

Compile mod_pagespeed

cd ~/mod_pagespeed/src
make BUILDTYPE=Release   # BUILDTYPE defaults to 'Debug'

Install mod_pagespeed

First edit centos.sh and change parameters according to your needs. Then run it.

vim install/centos.sh
cd install
./centos.sh
./centos.sh staging
./centos.sh install

Restart Apache

/etc/init.d/httpd restart

Check if Apache loaded mod_pagespeed.

httpd -M # list static and shared modules, mod_pagespeed should be here
httpd -l # list compiled in modules

If above doesn’t work try something like this:

/usr/src/httpd/httpd -M
/usr/src/httpd/httpd -l

If it’s there go to /etc/httpd/pagespeed.conf and configure it. I’ll write a bit more about configuring mod_pagespeed in my next post. If it’s not there make sure mod_pagespeed.so is in Apache module directory and if not copy it there.

locate mod_pagespeed.so
cp /tmp/mod_pagespeed.install/mod_pagespeed.so /usr/local/apache2/modules/

Edit your Apache configuration file and add Include /etc/httpd/pagespeed.conf if it isn’t already there. Next edit /etc/httpd/pagespeed.conf and add

LoadModule pagespeed_module /usr/local/apache2/modules/mod_pagespeed.so

Restart Apache and you should see something like X-Mod-Pagespeed: 0.9.1.1-173 in your website’s response headers.

References:

http://code.google.com/speed/page-speed/docs/using_mod.html
http://code.google.com/p/modpagespeed/wiki/HowToBuild

Posted by 6bytes at 25 June 2009

Category: Apache, MySQL, PHP

Tags: , , ,

If your PDO scripts are crashing Apache after installing xampp 1.7 for windows all you need to do is:

All should be good now.

Posted by 6bytes at 29 October 2008

Category: Apache

Compressing CSS and JavaScript files will put a bit more load on the server but its worth doing as it will save you some bandwidth and your site will be delivered faster to your users/visitors.

Load mod_deflate

First you need to make sure you have mod_deflate module loaded.  Check you have this line in your httpd.conf file and if so, that it’s uncommented.  The line should look like this:

LoadModule deflate_module modules/mod_deflate.so

All following options can be put in httpd.conf file but just for keeping things organized I recommend creating a new file in the same folder called deflate.conf

Enable compression

To enable compression for everything type in the following:

SetOutputFilter DEFLATE

To enable compression only for certain types of files type in the following:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript

Compression level

Available levels are 1 – 9 meaning 1 – weakest compression using least resources and 9 – strongest compression using the most resources of the server.   All modern servers have no problem with handling level 9.

DeflateCompressionLevel 9

Old browsers

To exclude browsers not fully supporting compression type in the following:

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Logs

Setting up a log file lets you know when and who requested your files as well as gives you information about how well your files were compressed.

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate

Result

If you’ve created deflate.conf file it should look something like that:


SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript

DeflateCompressionLevel 9

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog /var/log/deflate_log deflate

In your httpd.conf file add one line to include deflate.conf

Include /path/to/file/deflate.conf

Restart apache:

service httpd restart

If Apache starts without any problems your content should be compressed.

More detailed info can be found on Apache documentation here.

Posted by 6bytes at 18 October 2008

Category: Apache

When you want to patch your site or just make some amends its a good idea to close the site so that your visitors don’t see the mess you make while patching :)

You can easily do it using .htaccess file.  I assume you know basics of Apache mod_rewrite so I’m not gonna explain each line.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.1$
RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.2$
RewriteRule !holding_page.php|holding_page.jpg$ holding_page.php [R=307,L]

This line:

RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.1$

specifies the IP address you want to let in to see your site.  You can add as many IP addresses as you want.

Last line:

RewriteRule !holding_page.php|holding_page.jpg$ holding_page.php [R=307,L]

specifies two files that can be accessed by anyone (holding_page.php and holding_page.jpg).  Everything else should be redirected to holding_page.php

We don’t want search engines to think we closed down our site.  That’s why the flag 307 which means a temporary redirect.