Internet Explorer 6 and HTTP compression

Recently I wrote about installing mod_gzip on CentOS 5. However since then I have discovered that Internet Explorer 6 has does not support this properly, and intermittently does not load items properly!

To resolve this I had to change the Apache configuration. This is the configuration that I am now using:

1
2
3
4
5
6
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
BrowserMatch \bOpera !no-gzip
Header append Vary User-Agent

This turns off the HTTP compression based on their user agent.

Here are some of the known issues:
http://support.microsoft.com/kb/321722/EN-US/ (IE5.5, IE6 and IE6SP1 always cache gzip encoded content)
http://support.microsoft.com/default.aspx?scid=kb;LN;Q312496 (IE6http://support.microsoft.com/default.aspx?scid=kb;en-us;823386&Product=ie600 (IE6sp1, compressed HTML pages only partially appear)

And this is one of the sites I found to help with the resolution:
http://www.contentwithstyle.co.uk/Blog/147/

Ikea mobile phones

Ikea has launched its own mobile phone service called Family Mobile (which piggybacks on the T-Mobile network). This is “pay as you go” service offering very competitive rates when compared to other UK providers.

Basically it is a flat rate of 9p per minute whether you are calling a land line or another mobile phone, regardless of the network. Text messages are also reasonable at 6p each.

The service allows you to automatically top up your balance when a pre-set minimum is reached, so there is no need to worry about buying top up vouchers, and as it is aimed at family usage you can have multiple phones on the same account.

If you need to buy a handset then their prices do look more expensive than other service providers, so it will probably be cheaper to bring an existing handset or buy one elsewhere and take their SIM only option.

If you already have a phone that is compatible with the T-Mobile network then it should work, otherwise you may need to get your phone unlocked. Your existing provider may be able to do this for a fee, alternatively you can try and do it yourself. There are several sites on the internet that can give you the necessary information. One example is http://unlockme.co.uk/.

Installing PHP XCache on CentOS 5

XCache is a PHP opcode cacher, which basically means that it will cache the compiled code the first time a PHP page/script is executed thus avoiding the compilation step on subsequent executions.

I used the 1.2.2. release of XCache and followed the quick guide instructions to install from source.

The installation requires that the php-devel package is installed. This is required to compile PHP extensions (the comand phpize is required for this installation).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@testserver xcache-1.2.2]# yum install php-devel
Dependencies Resolved
=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-devel               i386       5.1.6-20.el5_2.1  updates           512 k
Updating for dependencies:
 php                     i386       5.1.6-20.el5_2.1  updates           1.1 M
 php-cli                 i386       5.1.6-20.el5_2.1  updates           2.1 M
 php-common              i386       5.1.6-20.el5_2.1  updates           154 k
 php-gd                  i386       5.1.6-20.el5_2.1  updates           113 k
 php-ldap                i386       5.1.6-20.el5_2.1  updates            35 k
 php-mbstring            i386       5.1.6-20.el5_2.1  updates           969 k
 php-mysql               i386       5.1.6-20.el5_2.1  updates            84 k
 php-pdo                 i386       5.1.6-20.el5_2.1  updates            62 k
 php-xml                 i386       5.1.6-20.el5_2.1  updates            94 k
Transaction Summary
=============================================================================
Install      1 Package(s)
Update       9 Package(s)
Remove       0 Package(s)
Total download size: 5.2 M
Is this ok [y/N]:

It appears that this will also update the core PHP package and dependancies, so care should be taken. Try this on a test server and not your production server!

Here are the steps I took to install XCache:

1
2
3
4
5
6
7
8
[root@testserver ~]# tar -zxf xcache-1.2.2.tar.gz
[root@testserver ~]# cd xcache-1.2.2
[root@testserver xcache-1.2.2]# phpize
[root@testserver xcache-1.2.2]# ./configure --enable-xcache
[root@testserver xcache-1.2.2]# make
[root@testserver xcache-1.2.2]# make install
[root@testserver xcache-1.2.2]# cp /etc/php.ini /etc/php.ini.bk
[root@testserver xcache-1.2.2]# cat xcache.ini >> /etc/php.ini

In my configuration the xcache.ini and resulting php.ini had the wrong path to the module that has been installed. The module was installed in /usr/lib/php/modules/ but the configuration was looking in /usr/local/lib/php/extensions/non-debug-non-zts-xxx/.

All that was needed was a simple change to the configuration file to comment out the fully qualified path and tell it to use the extensions directory:

1
2
3
4
5
6
7
8
9
10
[xcache-common]
;; install as zend extension (recommended), normally "$extension_dir/xcache.so"
;; zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/xcache.so
;; For windows users, replace xcache.so with php_xcache.dll
;; zend_extension_ts = c:/php/extensions/php_xcache.dll
;; or install as extension, make sure your extension_dir setting is correct
 extension = xcache.so
;; or win32:
; extension = php_xcache.dll

Then just check it’s installed:

1
2
3
4
5
[root@testserver xcache-1.2.2]# php -v
PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

Success! However Apache must be restarted in order for this to work with PHP web pages.

1
service httpd restart

Now if you access a page containing the phpinfo(); function you should be able to search for XCache and find it.

XCache is now installed and running.

I did not see the need to install the php-devel package on our live servers and I know that our live servers are identical to our test servers other than hard disk and memory sizes (we use VMWare extensively and they come from the same template).

This means that all the binaries compiled on the test server should be compatible with our live servers, so I just copied the xcache-1.2.2 folder from the test server and followed the above steps again starting with the “make install” step.

1
[root@testserver ~]# tar -cvzf xcache-install.tgz xcache-1.2.2/

copy this to the /root/ directory on the live server

1
2
3
4
5
6
7
8
9
10
[root@liveserver ~]# tar -xvzf xcache-install.tgz
[root@liveserver xcache-1.2.2]# make install
[root@liveserver xcache-1.2.2]# cp /etc/php.ini /etc/php.ini.bk
[root@liveserver xcache-1.2.2]# cat xcache.ini >> /etc/php.ini
[root@liveserver xcache-1.2.2]# vi /etc/php.ini
[root@liveserver xcache-1.2.2]# php -v
PHP 5.1.6 (cli) (built: Sep 20 2007 10:16:10)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

Installing mod_gzip on CentOS 5

CentOS 5 is packaged with Apache 2 which is not compatible with mod_gzip. The module mod_deflate is the Apache 2 equivalent.

Installing mod_deflate on CentOS 5 is a fairly simple process. The module is included in CentOS 5 and just need to be configured.

The only changes required are to the Apache configuration file /etc/httpd/conf/httpd.conf. I recommend that you take a backup before you make any changes.

Here are the steps that I took:

1. Check that the deflate module is loaded.
In my configuration file this was already done with this line:

1
LoadModule deflate_module modules/mod_deflate.so

If this is not there then I suspect all that is required is to add this line. However if you need to do this I recommend that you check the module /etc/httpd/modules/mod_deflate.so is installed.

2. Configure the deflate module
All that was required was to add the following lines to the Apache configuration file.

1
2
3
4
5
6
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
BrowserMatch \bOpera !no-gzip
Header append Vary User-Agent

Update 26/08/2008: Originally I only had the first line of the above configuration. However it turns out that there are issues with Internet Explorer 6 and HTTP compression.

I added this after

1
2
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

but you should be able to add it anywhere in the main section.

3. Restart Apache

1
service httpd restart

4. Test it’s working
The easiest way to check that it is working is with the YSlow plugin for Firebug. Firebug is a Firefox plugin that will give you lots of useful information.

To test just load a page in your browser, go to the Firebug/YSlow plug and select the “Performance” option. This will give you a performance grade. You should hopefully see an “A” for “4. Gzip components”. If not do a Ctrl-F5 to ensure that you’re not viewing cached content.

If this still does not report an “A” for “4. Gzip components”. then it is possible that your page has other content types that need to be added for YSlow to be happy.

Summary
This is only a quick overview of the steps I took, and by no means comprehensive A more detailed tutorial is available here: http://www.howtoforge.com/apache2_mod_deflate

MySQL export to CSV

MySQL allows you to export a query directly in to a CSV file that can be opened by Microsoft Excel.

This is the basic syntax:

1
SELECT FIELDS FROM TABLE INTO OUTFILE '/path/to/file_name.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';

The export file that is created “file_name.csv” must not already exist, the MySQL user must have write permissions to the directory the file will be created in, and the FILE permission within MySQL.

See the MySQL manual: SELECT Syntax

Viewing Flickr as a solar system

Flickr is possibly the largest collection of public photos on the planet.  Flickr has an API which allows anyone with some programming skills to write their own programs and websites, etc using their images and data.

Yesterday I came across the http://taggalaxy.de/ which allows you to view Flickr as a solar system.  You search for an image tag and this becomes the centre of your solar system, and the most popular associated tags are the surrounding planets.

It’s another different way of exploring this vast collection!

Creating a MySQL unicode UTF-8 database

Here’s the syntax for creating a UTF-8 database in MySQL as I can never remember it!

1
CREATE DATABASE `databasename` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;

New domain and blog!

This is the first entry on my new blog! This site is hosted by Web Hosting Buzz. So far I am impressed with the ease of configuration and installation. This WordPress installation was installed by a few simple clicks using their administration tools, saving me from downloading, installing and configuring it all myself.

All I need now is a new theme/design and some worthwhile content!