How to automate GeoIP updates on Linux

This works for Ubuntu, Debian and CentOS distributions. You need a valid license key from MaxMind. This is available as a subscription at a nominal fee.

If you have installed GeoIP successfully, you should have the geoipupdate program. If you don’t, you need the run the following.

Install over Ubuntu or Debian:

[code lang=”bash”]sudo apt-get install geoip-bin geoip-database libgeoip-dev[/code]

Install over CentOS:

[code lang=”bash”]sudo yum install re2c geoip geoip-data geoip-devel[/code]

Both libgeoip-dev and geoip-devel are required for compiling PHP’s GeoIP.

Once you run geoipupdate the first time, it tells you about a missing GeoIP file.

[code lang=”bash”]root@gladlycode:~# geoipupdate
Error opening GeoIP Configuration file /etc/GeoIP.conf[/code]

Now you copy over from the default file:

[code lang=”bash”]mv /etc/GeoIP.conf.default /etc/GeoIP.conf[/code]

If you now run geoipupdate, you get the following:

MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684
Invalid UserID

Continue reading How to automate GeoIP updates on Linux

How to install PHP GeoIP in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date[/code]

Continue reading How to install PHP GeoIP in CentOS

How to let PHP send emails

PHP not sending emails? You need a mail transfer agent (MTA). If you’re in the Ubuntu platform, you can use postfix for this:

[code lang=”bash”]sudo apt-get install postfix[/code]

You can read on more information here.

Previously my Contact Form 7 WordPress plugin didn’t work, it works fine after I install and configured postfix. I can’t go through the specifics of the configuration with you since yours would probably differ. I selected “Internet Site” and press the return key (Enter) all the way selecting the default options. On doing so, Contact Form 7 starts to work already.

Should you need to configure postfix again, you can reconfigure too:

[code lang=”bash”]sudo dpkg-reconfigure postfix[/code]

Contact Form 7 uses WP_Mail which uses PHP’s mail() function. If you do need to troubleshoot, try sending emails with mail().

If you need additional configuration, you may need to update the following:

  • Settings SMTP and smtp_port need to be set in your php.ini
  • Also, either set the sendmail_from setting in php.ini, or pass it as an additional header.

I did not have to configure anything more than postfix. I am using Ubuntu server, on nginx web server.

How to install PHP APC in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date[/code]

Continue reading How to install PHP APC in CentOS

How to know which processes uses the most resources

There are times where some processes use too much resources. You can use “ps aux” to get a list of all the processes that are currently running. But what about having them sorted? Here is one way. This works in Ubuntu Linux.

Top 10 % CPU usage

[code lang=”bash”]ps aux|sort -nr -k3|grep -v USER|head -10[/code]

Top 10 % Memory usage

[code lang=”bash”]ps aux|sort -nr -k4|grep -v USER|head -10[/code]

The following is the sample output for Top 10 % memory usage:

[code lang=”bash”]briecheese ~: ps aux|sort -nr -k4|grep -v USER|head -10
www-data 3883 2.9 14.1 107052 37176 ? S 11:44 1:46 /usr/bin/php-cgi
www-data 3882 2.9 13.8 107664 36264 ? S 11:44 1:46 /usr/bin/php-cgi
www-data 3881 1.2 13.2 106768 34688 ? S 11:44 0:44 /usr/bin/php-cgi
www-data 3884 3.1 13.1 107244 34592 ? S 11:44 1:54 /usr/bin/php-cgi
www-data 3879 1.1 11.8 106888 31160 ? S 11:44 0:40 /usr/bin/php-cgi
www-data 3880 0.9 9.5 94232 25092 ? S 11:44 0:34 /usr/bin/php-cgi
mysql 3659 3.5 6.9 277256 18200 ? Sl 09:45 6:25 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/ –skip-external-locking –port=3306 –socket=/var/run/mysqld/mysqld.sock
root 4103 0.2 1.0 53468 2704 ? Ss 12:44 0:00 sshd: me [priv]
me 4106 0.0 0.8 18128 2116 pts/0 Ss 12:44 0:00 -bash
www-data 3875 0.0 0.7 57440 1972 ? S 11:44 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf[/code]

Percentage memory usage is the 4th column. This is useful when you need a quick overview of what’s consuming the most memory. [Thanks U-Zyn]

How to repair MySQL tables

There are generally 2 ways of repairing MySQL tables using the command line. First is to use “mysqlcheck“, the other is to use “myisamchk” (only for MyISAM). This is more for my own information.

This has been tested on Ubuntu 9.10 with MySQL 5


This is how you can check if your database tables are fine:

[code lang=”bash”]mysqlcheck -uUsername -pSecret –all-databases[/code]

Change “Username” to your username and “Secret” to your password.

To repair them, use:

[code lang=”bash”]mysqlcheck -uUsername -pSecret –all-databases –auto-repair[/code]

This requires of your MySQL daemon to be running. If it isn’t running use this to start:

[code lang=”bash”]sudo /etc/init.d/mysql start[/code]


If you have trouble running ‘mysqlcheck’, you can consider using ‘myisamchk’ instead if your tables are MyISAM. This command can be performed without MySQL daemon running. This fixes the data in your file system directly and this has saved me once.

[code lang=”bash”]sudo myisamchk –max-record-length=1048576 -o -f /var/lib/mysql/db_name/table_name.MYI[/code]

Change “db_name” to your database name and “table_name” to the name of the table you wish to repair.

My disk got full

I just realized I totally used up my disk space in my slice:

[code lang=”bash”]briecheese ~: sudo /etc/init.d/mysql start
[sudo] password for me:
* /etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full![/code]

It has never occurred to me that this would happen. I start to do some clearing up and delete some backups that I no longer need.

[code lang=”bash”]briecheese ~/www: df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.4G 6.7G 2.3G 75% /
varrun 129M 40K 129M 1% /var/run
varlock 129M 0 129M 0% /var/lock
udev 129M 16K 129M 1% /dev
devshm 129M 0 129M 0% /dev/shm
overflow 1.0M 0 1.0M 0% /tmp[/code]

I managed to free more than 2 Gb.

Firefox 3.5 Beta 4 significantly faster in Linux

Let’s face it, Firefox isn’t exactly the fastest browser around. In Linux it’s worse, in fact, Windows Firefox through Wine in Linux is faster than Linux Firefox.

Tuxradar benchmark Firefox 3.5 Beta 4’s performance and the results are very optimistic.

I use Firefox and Opera in Ubuntu and I prefer Opera in terms of speed but it just never felt quite like a native application in Ubuntu. Firefox just doesn’t appear as responsive sometimes.

E Text Editor has been opensourced, Linux version coming

E Text Editor has been opensourced. Linux version is expected too as E Text Editor blog reveals:

Releasing the Source

As of today, the source of the e text editor is being released. This is the first step in the transformation into an Open Company.

Note that this is not just handing the development over to the community. I am still, and will continue to be, the main developer. Development of the editor will continue and it will still be fully supported in the future.

What the release means is that you can never risk ending up with a product that is totally abandoned, that many more eyes will be there to find and remove bugs, that companies and individuals can themselves add features only they need for inhouse use and that the community can help speed up the development of e and hopefully free me up to work on the more innovative features (of which there are many in the planning stages).

Linux version

There has been many questions about whether the release of the source would make it possible to build a Linux version. The answer is yes. The source does build under Linux, it just needs a Linux version of the ecore library which will be released shortly.(Source: E Text Editor)

I tried a trial of E Text Editor before but it was a little buggy back then. This news do, however, made me smile.