Cannot Initialize mbstring with PHP 7
Asked Answered
K

5

42

Whenever I try to access phpMyAdmin, I receive the following error:

"The mbstring extension is missing. Please check your PHP configuration."

I am running a LEMP stack on a CentOS 7 server. I have elected to use PHP 7 for this installation. I have not experienced this error on identical set-ups running earlier versions of PHP.

extension_loaded('mbstring') returns false even though mbstring.ini (/etc/php.d/) contains:

; Enable mbstring extension module
extension=mbstring.so

I am 100% sure that the mbstring module is installed on my server.

I'm completely stumped so if anyone has any ideas whatsoever, please let me know. Thanks.

Kwa answered 26/12, 2015 at 13:10 Comment(5)
Have you looked at phpinfo(); ?Launceston
@Andrea Yep, it follows the theme with no mention of mbstring at all.Kwa
in that case, mbstring isn't installed and working. extension= shouldn't go in mbstring.ini btw, I think it should go in php.iniLaunceston
Not with PHP 7, no. From php.ini: Note: packaged extension modules are now loaded via the .ini files found in the directory /etc/php.d; these are loaded by default. @AndreaKwa
I had this problem on DigitalOcean with PHP8. Solved with the top-answer. I think this is a version-independent solution.Farleigh
K
5

A solution was reached with the following method:

I put extension=mbstring.so inside php.ini even though that is no longer the method PHP uses by default to load modules.

From php.ini itself:

Note: packaged extension modules are now loaded via the .ini files found in the directory /etc/php.d; these are loaded by default.

It seemed to fix my problem. I would still be interested to hear if anyone else has a different take on this matter.

Kwa answered 26/12, 2015 at 19:52 Comment(2)
Perhaps the distribution of PHP 7 you used does not use the same configuration locations?Launceston
I had already installed php7.0-mbstring but for some reason phpenmod mbstring did not enable it. I had to manually enable it using this method. Additionally, my environment required a sudo service apache2 restart for the change to take effect.Bannerol
O
86

For those who have debian :

 sudo apt-get install php7.0-mbstring

Otherwise in centos (tested in centos 6.6)

sudo yum install php70w-mbstring

and as @mpen said you can activate it

sudo phpenmod mbstring
Orthography answered 9/3, 2016 at 13:23 Comment(6)
PS: It can be enabled with sudo phpenmod mbstringJigging
I needed to restart apache too service httpd restartChoker
For CentOS 7 + PHP 7, the package name was php70u-mbstring. If you get No package php70w-mbstring available, you have to do sudo yum list | grep "\-mbstring" to find the corresponding package.Choker
yum install php70-mbstring did it for me on an Amazon Linux InstanceJosiejosler
I just installed php7 and had the same issue. Much appreciated, Chopchop!Alternate
@DRSDavidSoft you should post your comment as an answer it solved my problem with php 5.6Diphtheria
K
5

A solution was reached with the following method:

I put extension=mbstring.so inside php.ini even though that is no longer the method PHP uses by default to load modules.

From php.ini itself:

Note: packaged extension modules are now loaded via the .ini files found in the directory /etc/php.d; these are loaded by default.

It seemed to fix my problem. I would still be interested to hear if anyone else has a different take on this matter.

Kwa answered 26/12, 2015 at 19:52 Comment(2)
Perhaps the distribution of PHP 7 you used does not use the same configuration locations?Launceston
I had already installed php7.0-mbstring but for some reason phpenmod mbstring did not enable it. I had to manually enable it using this method. Additionally, my environment required a sudo service apache2 restart for the change to take effect.Bannerol
C
2

For PHP7 on centos

try this yum install php70-mbstring

Catawba answered 30/4, 2018 at 5:46 Comment(1)
This is the correct answer if you have php 7.0 Note, first do a php -v to find your version.Hanzelin
U
0

I had this problem for a long time. I found the correct way (for me) to correct it... and it's fairly simple :)

Juste add "universe" on the xenial-updates

# cat /etc/apt/sources.list.d/*
deb [arch=amd64] http://fr.archive.ubuntu.com/ubuntu/ xenial-backports main
deb [arch=amd64] http://fr.archive.ubuntu.com/ubuntu/ xenial main universe
deb [arch=amd64] http://fr.archive.ubuntu.com/ubuntu/ xenial-proposed main
deb [arch=amd64] http://security.ubuntu.com/ubuntu xenial-security main
deb [arch=amd64] http://fr.archive.ubuntu.com/ubuntu/ xenial-updates main **universe**
Underquote answered 22/11, 2016 at 10:28 Comment(0)
L
-1

run sudo apt-get update, sudo apt-get upgrade before installing with sudo apt-get install php-mbstring.

I had the same problem today and found this way.

Lina answered 7/3, 2017 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.