Last Updated: February 25, 2016
·
2.664K
· mejt

Enable PHP extensions on Heroku via Composer

Last time I had interesting problem when I was deploying my Symfony Project to Heroku.

I use FosUserBundle for manage accounts and sometimes I saw blank page - it was PHP Error.

I looked into logs and I found error message:

Fatal error: Call to undefined function FOS\UserBundle\Util\mb_convert_case() in /application/vendor/bundles/FOS/UserBundle/Util/Canonicalizer.php on line 18

Conclusion is simple: mbstring (multi-byte string) extension is required but this is disabled on my hosting.

Unfortunately you can't modify php.ini file on Heroku and you need add the extension by another way.

How to enable PHP extensions on Heroku?

I assume that you use Composer, so add the extension should be easy.

Go to your project and open composer.json file and find require section.

For example:

"require": {
    "php": ">=5.3.3",
    "twig/extensions": "~1.0"
},

Add to this section name of your extension which you want enable (in my case I added mbstring). Result should look like below:

"require": {
    "php": ">=5.3.3",
    "twig/extensions": "~1.0",
    "ext-mbstring": "*"
},

Next step is update your composer.lock

Go to console and type:

$ composer update

After update composer you should commit your changes and push to your heroku remote.

After deploying process all will work fine.

Thanks!

2 Responses
Add your response

It would be enabled automatically if FOSUserBundle declared the dependency. I added a Pull Request here: https://github.com/FriendsOfSymfony/FOSUserBundle/pull/1698

over 1 year ago ·

Hi @dzuelke well done, however I think my protip can be useful for another similar issues.

over 1 year ago ·