Moodle is an open-source LMS widely used by institutions and educators for virtual learning environments. The name stands for Modular Object-Oriented Dynamic Learning Environment.
One critical point in Moodle operations is database encoding. Charset issues can lead to:
- invalid characters in text output;
- incorrectly encoded files;
- Ajax failures caused by inconsistent strings.
Even with debug enabled, root cause often appears only in server error_log. If the issue is charset/collation related, the flow below is usually effective.
Backup system and database
Always back up before changing anything.
Example with a test clone:
- original:
banco_01 - clone:
banco_01_fix
This can be done from jailed shell without root.
Check current charset/collation
mysql -e "USE banco_01_fix; SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';"
Typical output:
utf8mb4_general_ci
Change charset/collation
Moodle recommends utf8mb4_unicode_ci.
Edit Moodle config.php and temporarily point to clone DB:
$CFG->dbname = 'banco_01_fix'; // original was banco_01
Run Moodle collation conversion:
php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci
Warning: this may take time on large databases.
Set collation in config.php:
$CFG->dboptions = array(
'dbcollation' => 'utf8mb4_unicode_ci',
);
Force MySQL UTF-8 (optional)
Warning: use only as a last resort.
Edit /etc/mysql/my.cnf:
[client]
default-character-set = utf8mb4
[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
skip-character-set-client-handshake
Then repair/optimize databases:
mysqlcheck -u root -p --auto-repair --optimize --all-databases
Important notes
moodledatamust be writable.- Its path is defined in
config.php. - Broad permissions may improve compatibility but increase security risk.
- Official recommendation is to keep
moodledataoutsidepublic_html. - In some control panels (e.g., Hestia), architecture constraints may apply.
- Validate permission model and ownership against your web/PHP runtime.
This post is licensed under CC BY-NC.
Comments
Join the discussion below.
Comments are not configured yet. Add Cusdis settings in /assets/json/config/blog-comments-config.json.