Saturday, December 26, 2015

Block all 404 errors

Recently, I found huge amount of 404 error which cause my server CPU to 100%. Most of the 404 errors are come from several IP addresses.

Firstly I installed iptables to block them out:

iptables -A INPUT -s %SOME-IP-ADDRESS% -j DROP

After doing this, to save it, you need to run

service iptables save

Later, I want to find some way to automatically block them out, I found fail2ban.

After simply install fail2ban, you need to create a file called jail.local to put settings in:

bantime  = 3600

enabled  = true
port     = http,https
logpath  = %(apache_access_log)s
maxretry = 5

This means if someone tries for 5 times 404 error, there IP address will be banned for 1 hour.

You also need to put a file called apache-script-bots.conf in filter.d folder:

failregex = ^ .* 404 .*$
ignoreregex =

This setting tell fail2ban to check Apache access log to find all the 404 errors.

Friday, November 27, 2015

Abandon git local branch

I've merged, I've commited changes locally, but I have not decided to push it or not, so I leave it there. After several days, I want to totally abandon my local branch.

I would do below:

  1. git checkout master
    It will just tell you that your local branch is different from remote.
  2. git reset --hard origin/master
    This is the real effect command, it will force your local to be exactly same as remote.

Friday, October 30, 2015

Wordpress posts show question marks

I installed Wordpress on my local server, when I moved it onto remote server, all posts show just question marks like this:


What I did was: mysqldump, then mysql in.

Later after lots of search, inspired by this post: 

I found all I need to do is to set remote database server to use utf8mb4.

Be careful, all database, tables and columns by the newest Wordpress are already utf8mb4, so I did not touch them. Just to this to change your mysql database server to use utf8mb4. Every line is needed:




Especially this line:

I don't know why Wordpress php need this line, but it do have effect. If someone know, please let me know. Thanks!

Wednesday, February 15, 2012

Install Hiphop on CentOS 5.4 64

On a clean CentOS 5.4 64 environment, all you need to do is following 5 steps:

1. rpm -ivh
2. rpm -ivh
3. rpm -ivh
4. yum install php52
5. yum install hiphop-php


1. mv /usr/bin/gcc44 /usr/bin/gcc
2. mv /usr/bin/g++44 /usr/bin/g++
3. cd /usr/lib64; rm -f; ln -s
4. cd /lib64; rm -f; ln -s /usr/lib64/

Then you can run:
hphp test.php --keep-tempdir=1 --log=3

Tuesday, May 11, 2010

Windows XP Quick Launch Bar Always Disappear

For some unknown reason (this reason is still unknown until now), my Windows XP quick launch bar will not be shown everytime after restart. I can right click the task bar and make it shown again, but after restart, it disappear again.

The solutions are variable, but no one can solve my issue. At last, by studying this post line by line, I got the issue solved by doing the following thing (actually just one thing):


This is the only useful solution, all other solutions like creating folders, setting other registry keys are all useless, and may potentially damage your system. So just use this one line and no need to try others.

Thursday, July 16, 2009

SimpleTest Eclipse Plugin Issue

SimpleTest is a TDD template for PHP, I feel interest to it is because it provides a plugin for Eclipse which I use for my PHP development. There is an installation guide provided by SimpleTest official website:, but the problem is when I tried to follow it, there are several steps not match.

Firstly, it says you can "new" a SimpleTest project, but actually there is no SimpleTest project type for you to choose. This is actually not a big deal, you can just create a normal project, it will have no bad impact.

The most frustrating thing happen later is when you run your first test, it will complain cannot find eclipse.php. Several other users complain about this issue too, see here. To solve this issue, I searched in whole package for the file, and finally got it in a file of, once I extracted it to a folder, and in Windows->Preferences->SimpleTest, set SimpleTest folder to that extracted folder, everything solved.

Friday, June 19, 2009

Eclipse can not debug PHP web page (session terminated)

When using Eclipse with PDT to debug PHP, it can successfully debug PHP script, but everytime when tring to debug PHP webpage, it will terminated quickly with information saying of "session terminated".

The reason is because there are 3 lines must be added in php.ini.

zend_extension_ts="C:\Program Files\PHP\ext\ZendDebugger.dll" (You need to search in your Eclipse folder to find out where the file exists and use the full path to it.)

After adding these 3 lines, restart Apache, then it works.