Thursday, October 13, 2011

Qmail route email to external smtp relay

Edit
/var/qmail/control/smtproutes
content:
:hostname.com

Example:
:smtp.tm.net.my

References:

Monday, October 10, 2011

Kloxo Yum Gave Error... Trying Again

If you ever tried to install kloxo, and encounter this error,
it might be that you are trying to install kloxo on 64bits system.
Do a uname -m to see if its x86_64 (if yes, then its 64bits).
If its a i686, its not.

If you encounter that error, its likely that your /etc/php.ini is configured to disallow function "system".
Edit the php.ini and find for all line with:
disable_functions =exec,passthru,shell_exec,system...
and comment it off by adding #
Try to find for more of these line. Sometimes its been set more than once.

Updated: 24 Sept 2012:
Okay, normally this error comes out when an installation is incomplete along the process.
So the system have been configured to reject system call, therefore reinstalling it is not possible.
Best way is to reformat your server and install from fresh again.
Normally happen to 64 bits os, best to fall back to 32bits.

Tuesday, October 4, 2011

MySQL Lock tables and subqueries

Example error:
Table 'table' was not locked with LOCK TABLES

Example:
LOCK TABLES x write, y write;
select * from x; #works
select * from y; #works

But:
select *,
(select fieldname from y where fieldcond=x.field2) as yname
from x where field1='xxx'; #failed with
#y tables is not locked

Solution:
LOCK TABLES x write, y write, y as yalias write;
select *,
(select fieldname from y yalias where fieldcond=x.field2) as yname
from x where field1='xxx';
#WORKS!

Check system file changes from installed package

On redhat based system:

rpm --verify -all

On Debian based system:

dpkg -l \*|while read s n rest; do if [ "$s" == "ii" ]; then echo $n;
fi; done > ~/tmp.txt
for f in `cat ~/tmp.txt`; do debsums -s -a $f; done

Monday, October 3, 2011

select a field by first row via left join

There are times when we need to select first record of a table in a join tables.
Problem with mysql is that after joining tables together, there will be no indexing,
making query extremely slow.

First, makesure all inner join uses on query to limit the records instead of where condition.
This way, the record is filtered based on table indexes (make sure you index'em first) in the joining process.

2nd, to only populate a field by first row which matches the criteria, do a left join

select x.field1, x.field2 from table1 x inner join table2 x2 on x.field3=x2.field2
left join table2 x3 on x2.field1=x3.field1 and x3.fields=[some condition to filter to first row]
group by ...

Roundcube Error 500

It seems that kloxo always have issue updating roundcube.
Most of the time, the webmail is updated, but the database is not.
to fix it:
mysql -u root -p roundcubemail
source /home/kloxo/httpd/webmail/roundcube/SQL/mysql.update.sql


Wednesday, September 28, 2011

MySQL data contains chinese charactor become äöüßæåéé

It took me hours figuring this.
All my mysql data became symbols.
Then finally, i found the culprit.
1st, i converted my field and default charset of my table to unicode.
But i did not update the existing data to unicode. So it was my mistake.

2nd, in php, i changed my mysql_set_charset("UTF-8");
So now all the data from the table which contains original latin will be forced to utf-8.
So the symbol appear in my html output, so does phpmyadmin.

To fix this, i wrote a program to retrieve the data from latin charset, and
then output it as a code in array to replace the data later back to the database as utf-8.

Example:
mysql_set_charset("latin1", $conndb);
mysql_query("select ...");
$aData = mysql_fetch_assoc($query);

mysql_set_charset("utf-8", $conndb);
$aData["fieldname"] = utf8_encode($aData["fieldname"]);
//then update those record with newly encoded utf8
mysql_query("update table ... ");

so, the next time we query the database, ensure to use
mysql_set_charset("utf-8", $conndb);