Wednesday, October 26, 2016

Nginx, Drupal and mbstring: a major mess, and how to avoid it

This is not a particularly interesting issue, merely one of a particularly confusing nature. So I decided to write about it for future reference. And if that saves anybody time when they encounter the same situation I was in that would make it worth the effort to document it as it took me quite some time to sort out.

So I have tried to get Drupal 7 to run under NGINX 1.10 on my CentOS 7 VM. The first major requirement that required custom work was the one calling for PHP v5.2.4 or higher (full list of requirements available here). I have chosen to go for PHP v5.5 (I forget the exact reason but now, at least based on the Wiki article, I may be due for another update - at least to PHP 5.6 or PHP 7). So I did indeed install PHP 5.5. I don't remember the exact sequence for that - and that stage went through smoothly, something along the lines outlined here. At any rate, that was an easy and uneventful phase of the process.

Now with that out of the way I thought things were on track to get better - but fate would have it different. As I tried to go through the moves and initialize the Drupal-based website I was working on I got the following:

Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini mbstring.http_input setting. Please refer to the PHP mbstring documentation for more information.
As I tried resolving the issue I asked for advice on the NGINX user forum (the thread available here, in Russian). Skipping every twist and turn of this rather protracted affair let me just summarize it by saying that mostly everyone, myself included was looking for ways to turn off the multibyte string processing without realizing that the relevant module had to first be installed which it was not.

So the solution turned out to be simple. But like I said - it took time. The solution was this:

1) Install the relevant module:

yum install php55w-mbstring

2) Change the relevant lines in the config files. The lines to alter need to look as follows:

ini_set('mbstring.http_input', 'pass');
ini_set('mbstring.http_output', 'pass');

as detailed here.

So yes - Drupal wants you to install the functionality it does not need (multi-byte strng processing) and then wants you to disable it. Go figure.

Once again - thanks to everyone who helped me in the process, and if that helps somebody avoid the pain I had to go through, then this post is of some use.