Apache + mod_deflate

With mod_deflate you can use on-the-fly compression for your content delivered by apache. The content is compressed before it is sent to the browser which decompresses then the received data. Almost all modern browsers support gzip decompression. Although the apache module is called mod_deflate it uses the gzip compression method.

I could reduce the size of a lot of pages by almost 30-40% when delivering. As you can imagine this saves quite some bandwidth and gives you the ability to serve more pages.

So, how to implement this?

first you have to enable mod_deflate in your httpd.conf. Usually this module is already loaded if not uncomment the line or add

LoadModule deflate_module modules/mod_deflate.so

then create a new .conf file in your httpd config directory (usually something like /etc/httpd/conf.d) and add this

# add if module is enabled
<IfModule mod_deflate.c>

    # add content compression for given mime types
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript

    # set default compression level (1-9, higher number = higher compression)
    DeflateCompressionLevel 9

    # make some exceptions for problematic browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # set the deflate logging notice
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio

    # and set the logging format
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate

</IfModule>

into a new file, e.g. deflate.conf, save it and restart your apache server. From now on every page loaded will be served with gzip compression.

You can also use gzip compression from .htaccess. Simply add this:

# add if module is enabled
<IfModule mod_deflate.c>

    # add content compression for given mime types
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript

    # make some exceptions for problematic browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</IfModule>

Ensim 10.x/CentOS 5.10: upgrade MySQL 5.0 to 5.5

Hello,

as you may have noticed, CentOS 5.10 has stopped upstream updates for its stock MySQL version which is stuck at version 5.0.95. They have added MySQL 5.5 now to their repository but these packages are installed in different locations and have other startup-scripts then the default stock version, so that they can be run at the same time, but that's not very compatible with Ensim and its database management. Therefore I wrote a small upgrade script which removes MySQL 5.0 and installs 5.5, taking care of Ensim's database structure. Here are some script requirements:

  • python 2.4+ installed
  • EPEL and IUS repositories installed
  • all stock mysql55 packages excluded in yum (found in /etc/yum.repos.d/CentOS-Base.repo)

Here how to do the upgrade:

  1. download my script and place it wherever you want and unzip it
  2. check if all requirements above are fulfilled
  3. launch my script with: python /path/to/upgrade_ensim_mysql.py
  4. edit /etc/virtualhosting/filelists/mysql.sh and add following lines to it:
    N:S,rpm:mysql55
    N:S,rpm:mysql55-server
    N:S,rpm:mysql55-libs
    N:S,rpm:mysqlclient15
  5. edit /etc/init.d/mysqld and remove the parameters –skip-bdb and –skip-innodb
  6. now restart your mysql server as usual and do an ensim maintenance

For all the admins who are sceptic about user programmed scripts, here is what it basically does:

  • backup old needed files
    /etc/my.cnf
    /etc/init.d/mysqld_app_init
    complete mysql dump to /root/mysql_backup.sql
  • removes mysql5.0 packages without their dependencies
  • installs needed mysql55 packages
  • unlinks all symlinks and relinks the databases
    this step is needed because mysql50 supported database names with "-" in it, mysql55 doesn't, thus the "-" is replaced by "@002d" in the symbolic link
  • upgrades all database using mysql_upgrade
Ensim MySQL Upgrader (396 downloads )

Ensim Quota Fixer

Hello world,

We recently had some quota problems on one of our server with Ensim Control Panel. The control panel and command line quota tool reported other data than the users really used. Although the user had no files on the disk which were owned by him the quota reported a few megabytes used. I checked a few forums an read a few articles and wrote a bash script which fixes the quota problem.

Here what it does:

  • it turns off quota
  • does a backup of your old quota files (aquota.user and aquota.group)
  • scans new quota data
  • re-enables quota
  • and resets ensim users and admin quotas

Download the file, unzip it and run the script. Hope this helps someone as I struggled with this "bug" for some time.

Ensim Quota Fixer (1494 downloads )