UTF-8 with MySQL and LAMP

A recent question on a mailing list was the best practices for UTF-8 and PHP/MySQL. The following are the configurations I used in my multi-language projects.

MySQL UTF-8 Configuration

# my.cnf
default_character_set = utf8
character_set_client       = utf8
character_set_server       = utf8
default_character_set = utf8

PHP UTF-8 Configuration

default_charset = "utf-8"

Apache UTF-8 Configuration

AddDefaultCharset UTF-8
    AddCharset UTF-8   .htm

HTML file UTF-8 Configuration

 <meta charset="utf-8">

PHP file UTF-8 Configuration

header('Content-type: text/html; charset=UTF-8');

MySQL connection (extra precaution)


Shell UTF-8

And last but not least, even editing files in shell can be affected (.e.g UTF-8 data to be inserted into DB from file). Ensure at least

export LC_CTYPE=en_US.UTF-8
export LANG=en_US.UTF-8