Upgrading Mint for use with PHP 7+

This is a very niche post, but I’m posting it mainly to help people who might be searching Google for the solution to this problem: if you have been using Shaun Inman’s Mint for self-hosted website stats, you may have noticed that it no long works in PHP 7 and above.

When I noticed it broke, I spent several hours trying to figure out why and to fix it as quickly and easily as possible. Essentially, there are two reasons why it doesn’t work anymore:

  1. PHP 7 no longer lets you use "=&" to “assign a new object by reference”. I don’t even really know what this means, but I do know you can solve it simply by removing the &. There is only one place you need to do this in Mint’s code and that is on line 3409 of /mint/app/lib/mint.php where it says $DOM =& new SI_Dom($xml);. This problem was infuriating because it just makes the whole app fail silently, without throwing a single error. I spent a half a day deleting random code just to identify the culprit.
  2. The MySQL API has been deprecated in PHP 7 and Mint uses it for all of its database work. You’re supposed to rewrite all of your queries to use the new mysqli or PDO_MySQL APIs, but after a few hours of trying to do this, I realized my PHP skills were not up to the task and I opted for an easier solution instead. There’s a wrapper you can just include with your Mint install that translates all of the functions on the fly for you. This method is generally “not recommended” by people who actually know what they’re doing, but for a quick fix, it worked perfectly for me. If someone wants to patch Mint correctly, I will gladly post a pointer to it here. Anyway, all you have to do is download that file, upload it to /mint/app/ (next to path.php), call it something like mysql_bridge.php and then add this line right above the first include statement in /mint/index.php: include(MINT_ROOT.'app/mysql_bridge.php');

Voila! You’re done. The whole procedure should take only a few minutes.

2 comments on “Upgrading Mint for use with PHP 7+”. Leave your own?
  1. Mark Nichols says:

    Thank you! I recently migrated to a new host, including both my wife’s Mint and mine. Working with the new host I was able to put some jiggery-pokey stuff into the `.htaccess` file to force PHP 5. Not ideal, but it got things working.

    In `mint.php` there were several other instances of `=&`. I have left those in place for now, only changing the one you specified. And I have the SQL wrapper in place.

    I, too, had spent hours trying to figure out what to update/change in Mint to get it working again. The analysis tooL I downloaded (`php7mar`) found a couple hundred lines that needed changing. The wrapper is far simpler.

    The changes are in place and the htaccess workaround is removed and it all seems to be working. Thanks again!

  2. Mike D. says:

    Hi Mark. Ha! I’m glad this helped someone so quickly! Thought I was the only one who still used Mint. So… to answer your question: &= is still fine to use if it’s not followed by “new”. I think that only happens once in the code (as far I as I could tell). Happy Minting!

Leave a Reply

Your email address will not be published.

Subscribe by Email

... or use RSS