Wednesday, December 17, 2008

some LAMP tricks

LAMP is short for Linux+Apache+Mysql+Php. It's perhaps the most popular personal website platform for individual users and small business. I am not going to talk LAMP in this post, instead, I would like to introduce a CMS (content management system) - Joomla to you guys as well as some useful tricks.

Recently I set up a CMS with Joomla and encounter some weird problems. I would like the record them and share with you guys.

1. mysql access denied problem. I create a user locally but I cannot use login remotely via this user. Finally I realized that the access level is actually depend on the way you create the user. If you just GRANT all privileges to a new user, then this user can only be accessed locally. Here is an safe way to create user which allows you to login remotely
mysql> INSERT INTO user (Host,User,Password)
-> VALUES('localhost','dummy','');
mysql> FLUSH PRIVILEGES;
2. Most likely Mysql doesn't use UTF-8 as its default encoding. Edit /etc/mysql/my.cnf. At last it should look like
[client]
default-character-set=utf8
...

[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server-utf8
collation-server=utf_general_ci
init-connect='SET NAMES utf8'
...

3. Joomla 1.0.x (based on Php) also doesn't use UTF-8. Here is the receipt.
1).edit /includes/database.php
//@mysql_query("SET NAMES 'utf8'", $this->_resource);
to
@mysql_query("SET NAMES 'utf8'", $this->_resource);
2). edit the end of file globals.php, it should look like
}
header("Content-Type: text/html; charset=UTF-8");
?>


3). edit language/english.php, find
DEFINE('_ISO','charset=iso-8859-1');
change it to
DEFINE('_ISO','charset=UTF-8');

Enjoy!