Call to undefined function Symfony\Polyfill\Mbstring\iconv_strlen()

It may also happen that you are using an outdated version of PHP, or one that was compiled without iconv.

To check that, run php --ri iconv with any SSH software, like Putty, etc.

If it shows Extension 'iconv' not present., your problem is in PHP. Then you have a few options:

  • Run php -v to check your PHP version, and update it if necessary
  • Or compile PHP again with iconv
  • Or enable iconv on WHM/cPanel, if you use them
  • Or ask your hosting company for support

If you use WHM with the CentOS 7 operating system you will encounter errors like this when typing "composer" on the console:

Fatal error: Uncaught Error: Call to undefined function Symfony\Polyfill\Mbstring\iconv() in phar:///opt/cpanel/composer/bin/composer/vendor/symfony/polyfill-mbstring/Mbstring.php:661 Stack trace:

0 phar:///opt/cpanel/composer/bin/composer/vendor/symfony/polyfill-mbstring/bootstrap.php(48): Symfony\Polyfill\Mbstring\Mbstring::mb_strwidth('help', 'ASCII')

......

The solution is to install the iconv package using WHM:

Enter to your WHM then type "EasyApache 4" then click "EasyApache 4" and click "Customize". you can see in the picture

EasyApache 4

Select PHP Extensions, type "iconv" in the search and check the version of php that you will use to install the iconv package. see in the picture

PHP Extensions

Choose Review

Review

Click Provision

Provision

To ensure that the iconv package is installed you can use this command "php --ri iconv" if the results are like this in the picture. then the iconv package has succeeded. try typing the composer again so you don't get any more errors

php --ri iconv


Symfony provides an iconv-polyfill for cases like that. Just add it as requirement to your project, and you should be fine:

composer require symfony/polyfill-iconv

Here is a solution to your problem (command line is for CentOS) :

EasyApache