May 28, 2010

Enabling mod_mem_cache in Lighttpd 1.4.26

Filed under: Linux — Tags: , — hoball @ 12:31 pm


Make sure you have the lighttpd 1.4.26 source

Check if the patch binary is installed

yum -y update patch

cd ~/lighttpd-1.4.26

Download the patch file from http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModMemCache

wget http://redmine.lighttpd.net/attachments/download/1086/lighttpd-1.4.x-svn-mod_mem_cache.patch
patch -p1 < ./lighttpd-1.4.x-svn-mod_mem_cache.patch

./configure –with-fam –with-pcre –with-zlib –with-bzip2 –with-openssl –sbindir=/usr/sbin –sysconfdir=/etc/lighttpd
make install

If successful, edit /etc/lighttpd/lighttpd.conf

server.modules += (“mod_mem_cache”)
mem-cache.enable = “enable”
mem-cache.filetypes = (
mem-cache.max-memory = 128 # in Megabytes
mem-cache.max-file-size = 256 # in Kilobytes
mem-cache-expire-time = 1440 # in seconds

Restart Lighttpd

/sbin/service lighttpd restart

Check for error messages

tail /var/log/lighttpd/error.log

If no error, check the Lighttpd mod_status config page

Loaded modules: mem_cache

Statistics of the memory cache is in mod_status statistics page

mem-cache.cachenumber: 518
mem-cache.hitpercent: 56
mem-cache.usedmemory: 6960064 (should be in bytes)


May 27, 2010

Installing mod_geoip on Lighttpd

Filed under: Linux — Tags: , — hoball @ 7:12 pm


Geolocation software is used to get the geographic location of visitor using IP address. You can determine country, organization and guess visitors location. This is useful for

a] Fraud detection

b] Geo marketing and ad serving

c] Target content

d] Spam fighting

e] And much more.

mod_geoip is a Lighttpd module for fast ip/location lookups. In this tutorial you will learn about mod_geoip installation and php server side examples to determine visitors country.

mod_geoip uses the MaxMind GeoIP / GeoCity databases, which comes in two version:

* Free Version: Country and city databases are free with 99.5% accuracy.
* Paid Version: If you need 99.8% accuracy and other fancy details about IP address use paid version.

See this page for Free vs Paid version details.
A note about CentOS / RHEL / Fedora Linux users

If you are using 3rd party repo (see RPMforge and EPEL repo installations FAQ), you can install binary mod_geoip package as follows and skip directly to configuration part:

# yum install lighttpd-mod_geoip

Step # 1: Install C API for mod_geoip

Type the following command to download and extract MaxMind C API:

# cd /tmp
# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
# tar -zxvf GeoIP.tar.gz

Configure, compile and install C API:

# cd GeoIP-1.4.6
# ./configure
# make
# make install

Configure GNU ld

You need link mod_geoip using C API. You need to configure dynamic linker run time bindings as follows:

# cd /etc/ld.so.conf.d/
# vi geoip.conf

Append the following configuration:


Save and close the file. Run ldconfig to activate configuration:

# ldconfig

Verify that the name of each directory including /usr/local/lib is scanned, and any links that are created:

# ldconfig -v | less

Sample output:

libGeoIPUpdate.so.0 -> libGeoIPUpdate.so.0.0.0
libGeoIP.so.1 -> libGeoIP.so.1.4.6
libmysqlclient_r.so.15 -> libmysqlclient_r.so.15.0.0
libmysqlclient.so.15 -> libmysqlclient.so.15.0.0
libmysqlclient_r.so.15 -> libmysqlclient_r.so.15.0.0
libmysqlclient.so.15 -> libmysqlclient.so.15.0.0
libsepol.so.1 -> libsepol.so.1
libtermcap.so.2 -> libtermcap.so.2.0.8

[Output truncated]

Step #2: Download lighttpd latest version

Type the following command:

# cd /tmp
# wget http://www.lighttpd.net/download/lighttpd-1.4.22.tar.gz
# tar -zxvf lighttpd-1.4.22.tar.gz
# cd lighttpd-1.4.22

Step #3: Download mod_geoip patch

Type the following command:

# cd lighttpd-1.4.22/src
# wget http://redmine.lighttpd.net/attachments/download/716/mod_geoip_for_1.4.c -O mod_geoip.c
Compile lighttpd with mod_geoip patch

Edit Makefile.am and add the following after the last module:

lib_LTLIBRARIES += mod_geoip.la
mod_geoip_la_SOURCES = mod_geoip.c
mod_geoip_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
mod_geoip_la_LIBADD = $(common_libadd) -lGeoIP

Save and close the file. Now compile lighttpd as follows:

# cd ..
# aclocal
# automake -a
# autoconf
# make clean

Now you must use –enable-maintainer-mode option:

# ./configure –program-prefix= –prefix=/usr –exec-prefix=/usr –bindir=/usr/bin –sbindir=/usr/sbin –sysconfdir=/etc –datadir=/usr/share –includedir=/usr/include –libdir=/usr/lib –libexecdir=/usr/libexec –localstatedir=/var –sharedstatedir=/usr/com –mandir=/usr/share/man –infodir=/usr/share/info –with-openssl –enable-maintainer-mode
# make
# make install

Step # 4: Download GeoLite Database (Free version)

Type the following command:

# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# gunzip GeoIP.dat.gz
# ls -lh GeoIP.dat

Sample output:

-rw-r–r– 1 root root 1.1M Mar 9 21:13 GeoIP.dat

Install GeoIP.dat file:

# mkdir /usr/local/GeoIP
# cp -v GeoIP.dat /usr/local/GeoIP

Step # 5: Configure Lighttpd

Open your lighttpd.conf file and append the following configuration. First, enable mod_geoip:

server.modules += ( “mod_geoip”)

Finally, set path to GeoIP.dat file and turn on memory caching for faster lookups:

geoip.db-filename = “/usr/local/GeoIP/GeoIP.dat”
geoip.memory-cache = “enable”

Save and close the file. Finally, restart the lighttpd:

# /etc/init.d/lighttpd restart

Step # 6: Test your setup

mod_geoip will set environment variable such as follows:


You can use any server side programming language to determine visitors GEO location. Here is a sample php code:

What is my IP address - determine or retrieve my IP address

Another example: Redirecting user to country specific URL

Upgrade Lighttpd from 1.4.20 to 1.4.26

Filed under: Linux — Tags: , , , — hoball @ 7:07 pm

gcc automake autoconf libtool make
pcre-devel gamin (gamin-devel) zlib zlib-devel bzip2 bzip2-devel curl

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.26.tar.gz
tar -xzvf lighttpd-1.4.26.tar.gz
cd lighttpd-1.4.26
./configure --with-fam --with-pcre --with-zlib --with-bzip2 --with-openssl --sbindir=/usr/sbin --sysconfdir=/etc/lighttpd
make install
/sbin/service lighttpd restart

Very likely Lighty will report SSL error

cd src
rm network.c
wget http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/2716/raw/branches/lighttpd-1.4.x/src/network.c
cd ..
./configure --with-fam --with-pcre --with-zlib --with-bzip2 --with-openssl --sbindir=/usr/sbin --sysconfdir=/etc/lighttpd
make install


February 15, 2010

Running suPHP(System-wise) and FastCGI(user-specific) concurrently under cPanel/Apache2

Filed under: Linux — Tags: , , , — hoball @ 12:22 am

Step 1:
Compile PHP using EasyApache3, enables suPHP and FastCGI option

Step 2:
Go to “Apache Config”—>”PHP and SuExec Configuration”
Selects “suphp”, Save

Step 3:
Go to “Apache Config”—>”PHP and SuExec Configuration”
Selects “fcgi”, Save

Step 4:
make a copy of /usr/local/cpanel/cgi-sys/php5
cp /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5-bk

Step 5:
Switch back to suPHP [Repet Step 2]

Step 6:
rename “php-bk” to “php5″
mv /usr/local/cpanel/cgi-sys/php5-bk /usr/local/cpanel/cgi-sys/php5

Step 7:
Go to “Apache Config”–>”Include Editor”–>”Pre-VirtualHost file”
# Fastcgi configuration for PHP5 ( suPHP is active )
LoadModule fcgid_module modules/mod_fcgid.so

<IfModule mod_fcgid.c>
MaxRequestsPerProcess 10000000

<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from [Your IP]


Step 8:
edit the custom directives file


# Config Fast CGI

<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php

<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
FCGIWrapper /home/[username]/php-fcgi-wrapper .php

Step 9:
Create a wrapper script
touch /home/[username]/php-fcgi-wrapper

# Both are the same.
exec /usr/local/cpanel/cgi-sys/php5
#exec /usr/bin/php-cgi

chmod 755 /home/[username]/php-fcgi-wrapper

Step 10:
Verify and rebuild httpd.conf
/scripts/ensure_vhost_includes –user=[user]

Step 10:
Open http://%5Byour domain in action]/server-info
Use top / ps aux / pstree -Aaup to check

suPHP will execute PHP by calling the ‘php’ under httpd child processes
If succeed,  FastCGI will execute PHP by calling ’suexec’ under httpd child process

Step 11:
If succeed,
Go to “Apache Config”–>”Include Editor”–>”Pre-VirtualHost file”
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from [Your IP]








Apache mod_info helped me a lot:



December 7, 2009

A Brief description of installing MRTG on CentOS5.3 with Lighttpd

Filed under: Linux — Tags: , , — hoball @ 7:06 pm

Requirements: net-snmp, net-snmp-utils, mrtg, lighttpd

mrtg : Multi Router Traffic Grapher

net-snmp and net-snmp-utils : SNMP (Simple Network Management Protocol) is a protocol used for network management. The NET-SNMP project includes various SNMP tools. net-snmp package contains the snmpd and snmptrapd daemons, documentation, etc. You also want to install the net-snmp-utils package, which contains NET-SNMP utilities.

Install the packages

# yum install mrtg net-snmp net-snmp-utils

Configure snmpd.conf

# cp /etc/snmpd/snmpd.conf /etc/snmpd/snmpd.conf.factory-default

# vi /etc/snmpd/snmpd.conf

Comment out the contents, append: (http://www.sofee.cn/blog/2006/10/21/49/)

# Added by Justin
## sec.name source community
com2sec local   localhost       public
com2sec lan  public

## group.name sec.model sec.name
group   MyRWGroup       v1      local
group   MyRWGroup       v2c     local
group   MyRWGroup       usm     local
group   MyROGroup       v1      lan
group   MyROGroup       v2c     lan
group   MyROGroup       usm     lan

view all    included  .1                               80
#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

## context sec.model sec.level prefix read write notif
access MyROGroup ""      any       noauth    exact      all    none   none
access MyRWGroup ""      any       noauth    exact      all    all    all
rocommunity  public
disk / 100000
disk /mnt/share 500000

Save and close the file

# chkconfig snmpd on
# service snmpd restart

Make sure you see interface IP, by running the following command:

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Sample Outputs:

IP-MIB::ipAdEntIfIndex.123.xx.yy.zzz = INTEGER: 2
IP-MIB::ipAdEntIfIndex. = INTEGER: 1
Configure MRTG

# vi /etc/mrtg/mrtg.cfg


# /usr/bin/cfgmaker –global ‘WorkDir: /var/www/mrtg’ –output /etc/mrtg/mrtg.cfg public@

Create the html file

# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

Configure Lightttpd

# vi /etc/lighttpd/lighttpd.conf

Add a new alias:

alias.url + ( "/mrtg" => "/var/www/mrtg/www" )

or Append the alias:

alias.url += ( "/mrtg" => "/var/www/mrtg/www" )

Please read the followings for detailed tutorials or documentation.

English Tutorials:


Chinese Tutorials:





Official documentation:



October 22, 2009

Enable Num Lock on Gnome startup

Filed under: Linux — Tags: , , , , — hoball @ 10:30 pm

Run the following command:

Explanation: install numlockx, generate a backup file for /etc/gdm/Init/Default, edit it

su -c 'yum install numlockx'  su -c 'cp /etc/gdm/Init/Default /etc/gdm/Init/Default_backup'  su -c 'gedit /etc/gdm/Init/Default'

When the text editor is launched, go to the bottom part of the file, add the following before exit 0

if [ -x /usr/bin/numlockx ]; then
    /usr/bin/numlockx on

Save and restart Gnome or reboot system to see if it works!


  1. http://www.unixmen.com/linux-tutorials/documentations-a-howto/118-how-to-enable-num-lock-on-gnome-startup-
  2. http://www.cyberciti.biz/faq/how-to-linux-turn-on-num-lock-on-gnome-startup/

October 14, 2009

Useful Linux commands #2

Filed under: Linux — Tags: , , — hoball @ 5:21 pm
ps -efww|grep sqlr-listener|grep -v grep|cut -c 9-15|xargs kill -9
实 时查看正在执行的sql语句
/usr/sbin/tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'
netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"t",state[key]}'
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more


netstat -tna | cut -b 49- |grep TIME_WAIT | sort |morenetstat -an | grep TIME_WAIT | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more


netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | morenetstat -an | grep ":80" | grep ESTABLISHED | sort | more


ps -efww|grep sqlr-listener|grep -v grep|cut -c 9-15|xargs kill -9


netstat -anpo|grep php-cgi|wc -l
Source: http://www.quit8.com/read.php/18.htm

Useful Linux commands

Filed under: Linux — Tags: , , — hoball @ 5:17 pm

Find files older than 60 days
find * -mtime +60

Delete files in backup folder which are older than 60 days
rm -f `find /backup/ -mtime +60`

Search for a string inside files
grep -H -r “search me” /var/www

Find files owned by apache user
find /var/www/ -user apache

Find directories owned by apache user
find /var/www/ -user apache –type d

Listing files in a directory
ls -lh

Copy an entire directory (files + subdirectories)
cp -R existingdir/ newdir/

Zip up an entire directory
zip -r zipefilename foldername

Count total number of files in a directory
ls -1 | wc -l
find . -type f | wc -l

Get directory size
du -hs /var/www

Get amount of free disk space available
df -h

Get Linux version details
uname -a
cat /proc/version

Source: http://eisabainyo.net/weblog/useful-linux-commands/

October 23, 2008

Restart SCIM

Filed under: Linux — Tags: , , , — hoball @ 9:11 pm

To restart SCIM, input the command below in terminal

pkill ^scim && scim -d

October 9, 2008

Run PPS service on Firefox 3.0.2 by Sun Java JRE SE6 Update 10

Filed under: Linux — Tags: , , , , — hoball @ 12:13 am

In order to run PPSHK on a linux system, we need to install the Java JRE.

Versions of Java JRE before SE6 Update 10 will not run, confirmed by the PPS technician.

Download the RPM of Java JRE SE6 Update 10 RC from sun.com


Once the download complete, launch the terminal and navigate to the folder

sh jre-6u10-rc2-linux-i586.rpm

The installer should start. When it has completed the installation, confirm the following file exists


This can be done by listing the folder

ls /usr/java/jre1.6.0_10/plugin/i386/ns7/

Once confirmed, a symbolic link should be created in the plugin folder of mozilla

ln -s /usr/java/jre1.6.0_10/plugin/i386/ns7/libjavaplugin_oji.so /home/[USER]/.mozilla/plugin/libjavaplugin_oji.so

replace [USER] to your username

Finally, close and restart Firefox, check if the java plugin has been loaded. In address bar, type


Older Posts »

Create a free website or blog at WordPress.com.