Joomla site shows odd characters after migrating to new server

I have a customer who has a slew of Joomla websites.  These are all older Joomla sites that are limping along with a short life expectancy while their replacements are being built by the  customer.   The sites had been hosted on various cPanel servers of mine of the years, from the days of PHP 5.2 and MySQL 4.1 all the way up to now, with CloudLinux and MariaDB 10.    Each site has been migrated/transferred to another server multiple times over its lifetime, always to another server running a newer version of MySQL.

Fast Forward.    The customer now has a dedicated server of their own running CloudLinux, cPanel and MariaDB.    The customer wanted these sites migrated to their server, and of course I was on board with that.

I started migrating these sites only to find that after migration many of them were displaying strange characters in place of apostrophes and other “normal” characters.   Obviously some sort of character set / encoding issue.    This really baffled me, and I spent many days investigating the cause and testing different theories and changing configurations to get these sites to display properly.   At no time did I feel that modifying Joomla code or standard Apache / PHP configurations was the answer, since these sites survived numerous migrations in the past without issue.    PHP settings were exactly the same.    SQL character sets, character encoding and collation were all the same.    The databases themselves were unchanged from the dump/import done during the cPanel transfer process.

On Sunday I decided to switch from PHP 5.3 from CloudLinux’s PHP selector to “native” PHP 5.5 compiled through EasyApache 3.   Lo and behold, the sites worked fine.   Ok, I was on top something, but didn’t know what yet.    I brought up some phpinfo data from a site when running native PHP and compared it to phpinfo from a site when running PHP Selector.    After doing a stare-and-compare until my eyes were crossed, I finally realized one thing different about the two phpinfo results.

When running native PHP 5.4, the Client API versions for mysql, mysqli and pdo_mysql PHP modules showed as mysqlnd 5.0.10 – 20111026, but when running Alt-PHP PHP 5.3 from PHP Selector the API versions showed as 10.0.24-MariaDB.   Ahah, now we’re getting somewhere.   My thought that there was something fouled up with the MariaDB specific drivers shipped with CloudLinux’s Alt-PHP, such as them possibly using different collation or something.   I opened up a ticket with CloudLinux.    I had some nice back and forth exchanges with support persons at CL, each time trying something different.   Of course, as mentioned before, I was adamant that I wasn’t going to be changing code or character sets in PHP/Apache or converting databases from one character set or another.

After about an hour of troubleshooting, one of the CL guys suggested that I disable the mysql, mysqli and pdo-mysql modules and enable the nd_mysql, nd_mysqli and nd_pdo_mysql drivers.    Much to my surprise, that resolved my issue.   And now phpinfo when running Alt-PHP PHP 5.3 also showed the Client API version as mysqlnd 5.0.8-dev – 20102224.

(Historically all of my machines are set with mysql, mysqli and pdo_mysql modules enabled in PHP Selector)

So, for these specific sites I am using nd_mysql, nd_mysqli and nd_pdo_mysql modules instead of mysql, mysqli and pdo_mysql.

Obviously the reason why I never had an issue migrating before is because I was always migrating from one MySQL server to another, never to a MariaDB server.

It’s important to say that I’ve migrated 100s of sites (WordPress sites mainly) to Cloudlinux/cPanel servers running MariaDB and never had an issue.   This only cropped up when I was migrating these ancient Joomla 1.5.x sites, and only when migrating to a Cloudlinux/cPanel server running MariaDB.

I appreciate the support of the Cloudlinux crew.  I still don’t know if its a bug in the MariaDB drivers shipped with Alt-PHP or if the behavior is by design.

 

mysql-mysqli-pdo-mysql       nd_mysql-nd_mysqli-nd_pdo_mysql

 

website-before         website-after

6 comments on Joomla site shows odd characters after migrating to new server

  1. I just want to tell you how eternally grateful I am. I spent days figuring out what the hell was happening (new client), not knowing that there was a migration in the middle. My last chance was the connector libraries and in that moment I found your post.

    Thanks for sharing!

    1. Hi Leonardo,

      You’re quite welcome. I’m glad that documenting my experience has helped somebody else. Incidentally, I had initially figured out a “fix” for this that was basically a kludge, and I was using this method until I realized that I couldn’t just edit code for these sites to make them work. But what I had originally done [before i found out about the MySQL / MariaDB libraries issue] was to edit /libraries/joomla/factory.php and change the “charset” line to reference iso-8859-1 instead of utf-8

      Original: ‘charset’ => ‘utf-8’,
      Modified: ‘charset’ => ‘iso-88659-1’,

      But, since we discovered that using the ND drivers fixes this, there is no reason to edit factory.php and I restored those factory.php files back to referencing utf-8

      Mike

  2. That is so crazy! You are a skinny legend, thanks. I had to migrate an old joomla site and those black squares were driving me insane. That fix would have gone right over my head, thank you thank you thank you.

    1. You’re welcome, Andres. Skinny legend? I wish I were at least one of those two hah. I’m glad my writeup helped you out.

  3. Man!

    I’m here to post my saga with a joomla 1.5 site and cpanel!

    The site in question only works using php 5.2, because of some component who use some deprecated funcions and = & Class “owwww boy”

    Well, the thing was going crazy because mysqlnd in cpanel only works to php 5.3+!!!

    I managed to solve the problems editing the file:

    /public_html/libraries/joomla/database/database

    if you are using in configuration.php the mysql driver you need to put this comandas below line 78.

    mysql_query(“SET character_set_results = ‘utf8’, character_set_client = ‘utf8’, character_set_connection = ‘utf8’, character_set_database = ‘utf8’, character_set_server = ‘utf8′”);

    if you are using mysqli in configuration you need to put below line 78 of mysqli.php at the same folder aboved showed above.

    $this->_resource->set_charset(“utf8”);

    It’s incredible but i have at least 50 clients whoses sites is in j1.5 and they dosen’t what to change!

    Well, this is my contribution to the brave wariors who arrived here in need of some help!

  4. Thank you so very much for sharing your experience! Both tcadm1 and Anselmo Battisti! As I had to use PHP 5.2, Anselmo Battisti was my saviour!

    You’ve saved me from wasting hours of my life if not days!

Leave a Reply to leonardo pinzon Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.