Elixir is a language with great unicode support. But recently I encountered a strange unicode related issue when I deployed a Phoenix application to an Ubuntu Server on Digital Ocean. I had the latest stable versions of Erlang and Elixir installed. The issue was not caused by Elixir but it was because of a missing configuration on my server. I hope that the the solution that I found will be useful for others.

The problem was that instead of unicode characters of my native language Malayalam, question marks where getting inserted into the the database. Initially I thought that the issue was with Ecto or the MySQL database adapter Mariaex. (I always prefer to use PostgreSQL with Phoenix as it is the default choice. But because of certain specific requirements of the project I ended up using MySQL). But since the same versions of Ecto and Mariaex were perfectly working on my development machine, I started looking for other possible reasons.

Finally, after a lot of research I figured out that the value of the locale environment variable LC_ALL was not set on my server. After entering the following command to set its value as en_US.UTF-8, and thereafter restarting the phoenix server the issue was resolved.

$ sudo update-locale LC_ALL=en_US.UTF-8

This command will update the file /etc/default/locale. You can verify that by running

$ cat /etc/default/locale

If we set the value of LC_ALL, it will override the values of LANG and other LC_* variables. Since we are changing the value of an environment variable, we need to stop the phoenix server and start it again, for fetching the updated value when it starts running.

Please check Understanding locale environment variables on IBM Knowledge Center if you are interested in learning more about these variables.