Drupal 7.50 with support for full UTF-8

This is quite a significant release so there is a version jump from Drupal 7.44 --> 7.50. It introduces a few new features and bugfixes.

The few new features in Drupal 7.50 are:

  • New "administer fields" permission added for trusted users
  • Protection against clickjacking enabled by default
  • Support for full UTF-8 (emojis, Asian symbols, mathematical symbols) is now possible on MySQL
  • Improved support for PHP 7

You can read it at: https://www.drupal.org/blog/drupal-7-50

I'm not a big fan of emojis, in fact i find them quite annoying. But i do like to stay current and on top of things with my own and clients' Drupal sites.

In this article, i want to cover the support for full UTF-8 that allows for emojis, Asian symbols and mathematical symbols to be included in your content because updating to Drupal 7.50 isn't enough, you still need to convert your DB char set to utf8mb4.

Note: utf8mb4 is only supported on MySQL 5.5.3 or higher and MariaDB 10.0 or higher.

How do we do this?

Before you begin, you need Drush installed on your server. I'm using Drush 8.0.x version and MariaDB 10.0.26. For those that do not have Drush, you can try this solution found on StackOverflow.

These steps below will takes you through the process of updating a single Drupal DB to add support for full UTF-8. You will need to repeat these steps for every drupal installation.

  1. Back up your database and files (and perform this process in a test environment before on your production site if at all possible).
  2. Prepare MySQL by making sure the following three settings are in my.cnf (then restart MySQL):
    [mysqld]
    innodb_large_prefix=true
    innodb_file_format=barracuda
    innodb_file_per_table=true
    

    If you are using CentOS 7.x, my.cnf is located at /etc/my.cnf

    Note: if you have this line in your my.cnf: default-storage-engine=MyISAM
    you should uncomment it out.
  3. Install the drush command to convert your site's databases:
    drush @none dl utf8mb4_convert-7.x
    
  4. Upgrade your Drupal codebase to version 7.50 (download link: Drupal 7.50)

  5. You might run into this issue if you have not been cleanly uninstalling your modules causing some redunant entries left in the DB tables. The error msg you might be something like this:
     

    file system: addtihs. In order to fix this, put the module back in its original location. 
    For more information see the documentation page. in _drupal_trigger_error_with_delayed_loggin()(line 1128 of /var/www/drupal/includes/bootstrap.inc)
    
    

    To fix this, run the command below (remember to replace module_name with the name of the module you want to remove. Do this for each module you want to remove):

    drush sql-query "DELETE from system where name='module_name' AND type = 'module';"
    
    See: https://www.drupal.org/node/2487215 for more details regarding above issue.
  6. Add charset and collation settings in your site /sites/default/settings.php file:

    $databases['default']['default'] = array(
      'database' => 'databasename',
      ...
      'charset' => 'utf8mb4',
      'collation' => 'utf8mb4_general_ci',
    );
    
  7. Navigate to your drupal installation webroot directory and run this command:

    drush utf8mb4-convert-databases

If all goes well, Drush will start converting all the Drupal 7 DB tables:

drush convert db tables to full utf-8

Now you can test by adding Emoji (??). Create a page and copy this smiling pile of poo: ? into your content page ?. If you don't like ?, try others emoji at: http://getemoji.com/

Good news, if you are running Drupal 8, you don't need to go through this process ?

Big thanks to Jeff Geerling. This article was made possible from his tutorial. I recommend you check out his other articles as well, a lot of useful stuff on his blog.

Update:

If for some reason your hosting provider wouldn't or do not support utf8mb4 but you have already converted your database, you can revert the changes. Use this drush command:

drush utf8mb4-convert-databases --charset=utf8 --collation=utf8_general_ci

 

If the above failed to work, there is another alternative. You can use this script - convert.php.zip 

Update the lines to match your database login details:

$db_server = 'localhost';   
$db_user = 'db user';   
$db_password = 'db pass';   
$db_name = 'db name';   
$char_set = 'char set'; 

For $char_set = 'char set';, use $char_set = 'utf8';

upload this file to the web root of your website and run it in a web browser, ie, http://your-domain.com/convert.php