What is the PHP mbstring extension, and what is the best way to install it on Ubuntu 14.04?

up vote 135 down vote accepted

EDIT: Dylan Pierce has confirmed that you can already install some PHP 7 extensions in the same way you would for PHP 5. For mbstring in particular, you can execute:

sudo apt-get install php7.0-mbstring

To complement sparkmood's answer, this now works for PHP 7 if you already imported ondrej's PPA for it.

sudo apt-get install libapache2-mod-php7.0

Don't forget, either PHP 7 is available through ubuntu's official repositories or you will need an external PPA.

  • After installing this package, where is the mbstring extension? I can't find it in /etc/php/7.0/mods-available like the others. I've tried uncommenting the extension in php.ini but it doesn't know the the path to the extension. – Dylan Pierce Feb 24 '16 at 23:29
  • 16
    I've figured it out: sudo apt-get install php7.0-mbstring Also works for other php extensions you might need like: sudo apt-get install php7.0-zip sudo apt-get install php7.0-dom I really like how brainless it is to install/activate these modules. I just wish I didn't have to go on an internet wide goose chase for them. – Dylan Pierce Feb 25 '16 at 14:26
  • 1
    Why is nobody fighting this version-in-name stuff? -_- – erikbwork Aug 16 '16 at 16:28
  • 2
    I believe that as soon as version 7 covers all of the old 5 libraries, you won't have to write 7 to get the latest and greatest. Not doing so would probably break build scripts or cause unexpected behavior. – goncalotomas Aug 17 '16 at 15:13
  • 2
    You can just use package php-mbstring without the version number – pd12 Jan 11 at 3:21

mbstring is built in libapache2-mod-php5 package, so you can use this command for installing :

sudo apt-get install libapache2-mod-php5

As described in package details :

 dba dom ereg exif fileinfo filter ftp gettext hash iconv json libxml
 mbstring mhash openssl pcre Phar posix Reflection session shmop SimpleXML
 soap sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xml
 xmlreader xmlwriter zip zlib.
  • I have already installed apache2 on my server now if I install "libapache2-mod-php5" on my server will it any problem. – Rohit Bind Jul 4 '14 at 11:03
  • When I run your line, it break my LAMP - l have to re-install :( – SIDU Aug 25 '16 at 4:19
sudo apt-get install php-mbstring

I have installed mbstring in php7.0-fpm (7.0.15-0ubuntu0.16.04.4)

  • This is correct for Debian Stretch. No need to add the version number. Internally a sub-package with version number is loaded. – Jpsy Sep 21 '17 at 9:06
  • I have added version because i have tested on above version. thanks for you comment – Nanhe Kumar Sep 21 '17 at 10:20
  • This is vastly superior to specifying the version on the cli as it seems to adapt to the installed version. – Félix Gagnon-Grenier Feb 9 at 19:01

In my case it was already installed, but I just needed to do phpenmod mbstring, followed by apachectl graceful.

If you're using php 5.6

Install php 5.6 mbstring package:

sudo apt-get install php5.6-mbstring

Then add the following line to the bottom of your php.ini file:

extension=php5.6-mbstring.so

Restart apache:

sudo service apache2 restart

To find your php.ini file, create a file and insert the following line:

<?php phpinfo(); ?>

Then open with a browser to see where your php.ini file is located.

For Ubuntu 14.04 extension mbstring should be built in.

For Ubuntu 16.04:

sudo apt-get install php7.0-mbstring

See also Introduction to Multibyte String

It requires adding another source for apt for install in 18.04..

Download Page for php7.2-mbstring_7.2.7-0ubuntu0.18.04.2_amd64.deb on AMD64 machines

If you are running Ubuntu, it is strongly suggested to use a package manager like aptitude or synaptic to download and install packages, instead of doing so manually via this website.

You should be able to use any of the listed mirrors by adding a line to your /etc/apt/sources.list like this:

deb http://security.ubuntu.com/ubuntu bionic-security main universe

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.