- How to enable mbstring in PHP?
- Why mbstring is required?
- MBstring Installation
- Installation on Linux Server
- Installation on Windows Server
- MBstring Configuration
- PHP solve mbstring extension missing
- Install mbstring for Linux
- Install mbstring for Windows
- Install mbstring for macOS
- Take your skills to the next level ⚡️
- About
- Search
- Tags
- Php ubuntu how to enable php ext mbstring
- Ubuntu 20.04, PHP 7.4: mbstring installed but not enabled
- Ubuntu 18.04, can’t enable the mbstring PHP extension
- How to install php8.0-mbstring for php8.0? It keeps installing to php7.2
- How do I install php mbstring extension in to Nginx Ubuntu
- STEP 1 — Installing mbstring
- STEP 2 — Restart you server:
How to enable mbstring in PHP?
It is required to have PHP enabled with mbstring (multi-byte string) support for storing and displaying multi-byte characters in PHPKB software. The installation wizard of the multi-language editions of PHPKB knowledge base software will automatically detect if you have PHP enabled with mbstring support. If it is not enabled, you may get an error that says:
Please refer to the tutorial below on how to enable mbstring on your server.
Why mbstring is required?
When we manipulate (trim, split, splice, etc.) strings encoded in a multi-byte encoding, we need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if we apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or end of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.
So, mbstring provides multibyte-specific string functions that help us deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience.
MBstring Installation
Please note that «mbstring» is a non-default PHP extension. This means it is not enabled by default.
Installation on Linux Server
You can find out if this module is installed or not by looking at the list that is produced by this command
If you don’t have this installed on a Linux machine and if you have installed PHP from yum then run this command as a superuser. The command depends on your operating system.
sudo yum install php-mbstring
This command is true for all Red Hat Linux-based distributions using RPM and the ’yum’ package manager; this includes RHEL, Fedora, CentOS, Mandriva, and Intrinsic Linux, among others.
For Debian, Ubuntu distributions, please use the following command.
sudo apt-get install php-mbstring
After that, you will need to restart your Apache service using the following command:
Installation on Windows Server
If you have access to the php.ini, just remove the semicolon character (;) in front of the line below.
Once you have made the changes, don’t forget to restart your web server for the change to take effect.
Note: PHP extensions are not just enabled from php.ini file. First, you need to install that specific extension, i.e. place its DLL file «php-mbstring.dll» into the «/php/ext/» directory if it is not already present there. When you do that, make sure you have the correct build of DLL file. 32-bit, thread-safe PHP binary, built using VC9 for example, would only work with DLL files built using exact same tools and configuration: 32-bit, using VC9, with thread-safety turned on. And of course PHP API version also needs to match. If it doesn’t, once you restart the web server, you will receive ’Error 500 — Server error’ message.
MBstring Configuration
Below is a sample excerpt from php.ini file which contains the configuration of mbstring variables.
[mbstring]
mbstring.language = all
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8
mbstring.encoding_translation = On
mbstring.detect_order = UTF-8
mbstring.substitute_character = none;
mbstring.func_overload = 0
mbstring.strict_encoding = Off
- Applicable To: Standard (Multi-Language) Edition, Enterprise Multi-Language Edition (MySQL), Enterprise Multi-Language Edition (SQL Server)
35 people found this article helpful what about you?
PHP solve mbstring extension missing
Posted on Aug 08, 2022
When running phpMyAdmin, you may see an error that says the mbstring extension is missing as follows:
This error prevents you from opening phpMyAdmin and accessing your database.
To solve this error, you need to have mbstring installed and activated in your PHP configuration.
Depending on your Operating System, there are different ways to install and enable the mbstring extension:
Install mbstring for Linux
For Linux systems, you can install mbstring using apt-get or yum depending on your Linux distribution.
Here’s the command to install mbstring for Debian / Ubuntu or Red Hat Linux:
The package manager should install the right mbstring version based on your PHP version.
If not, you need to specify the version as follows:
Once the extenson is installed, you need to restart your PHP server.
For Apache, run the following command:
Now you can check if the mbstring extension is enabled by running phpinfo() function to see the mbstring enabled:
You can also run the php -m | grep mbstring command to see the extension from the command line:
Now that the mbstring extension is available, you should be able to access phpMyAdmin.
Install mbstring for Windows
For Windows system, you need to enable the mbstring extension from the php.ini file.
Look for the line extension=php_mbstring.dll in your php.ini file as follows:
You need to remove the semicolon before the extension config to enable php_mbstring.dll for Windows.
Once you enable the extension, restart your PHP server. The mbstring extension should now be available on your Windows computer.
If that doesn’t work, search your php.ini file for the extension_dir config.
You should see where PHP look for the extensions as shown below:
You need to see if the php_mbstring.dll exists inside the D:\XAMPP\php\ext path. Copy the extension directory value and paste it to your explorer windows.
If the .dll file is not present, you need to download the PHP Windows build from windows.php.net as shown below:
Extract the downloaded zip file, then look for the php_mbstring.dll file from the ext/ folder. Copy the file to your extension_dir path.
I don’t recommend downloading dll files from the Internet because you may get a virus on your computer.
Restart your PHP server, and now the mbstring extension should be available.
And that’s how you enable mbstring on Windows computers.
Install mbstring for macOS
For macOS, the PHP formula from Homebrew already enabled the mbstring extension during the installation process.
You should have mbstring enabled by default when you install PHP using Homebrew.
But if you install PHP using MacPorts, then you may need to install mbstring separately.
The following command should work when you’re using MacPorts:
You can see the available mbstring version from macports.org.
Now you’ve learned how to enable the PHP mbstring extension on macOS. Good work! 👍
Take your skills to the next level ⚡️
I’m sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I’ll send new stuff straight into your inbox!
About
Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials.
Learn statistics, JavaScript and other programming languages using clear examples written for people.
Search
Type the keyword below and hit enter
Tags
Click to see all tutorials tagged with:
Php ubuntu how to enable php ext mbstring
in Unknown on line 0 or mbstring PHP Warning: PHP Startup: Unable to load dynamic library ‘mbstring’ (tried: /usr/lib/php/20200930/mbstring (/usr/lib/php/20200930/mbstring: cannot open shared object file: No such file or directory) or Solution 1: STEP 1 — Installing PHP mbstring extension is not enabled by default as stated in PHP docs. is just a dependency package the depends on the current release, so on 20.04 it installs but when you’ll upgrade to the next OS release it will be upgraded according to whichever php release will be shipped with it.
Ubuntu 20.04, PHP 7.4: mbstring installed but not enabled
Well, I guess the right package was not installed; this did the trick: sudo apt-get install php7.4-mbstring . This delivered mbstring.so to the 20200930 directory, and phpinfo.php reports it enable.
As you found out — the package was installed in the past but was erased (but not purged, so configuration files were left intact), this is indicated by [residual-config] .
Your setup will be more future proof by installing php-mbstring instead of php7.4-mbstring unless your use case requires this exact release. php-mbstring is just a dependency package the depends on the current release, so on 20.04 it installs php7.4-mbstring but when you’ll upgrade to the next OS release it will be upgraded according to whichever php release will be shipped with it.
Install version specific package. For me i am using php 8.0.16 so i did this and it sorted me out sudo apt-get install php8.0-mbstring
Install mbstring php 7.4 ubuntu Code Example, sudo apt-get install php7.2-mbstring sudo apt-get install libapache2-mod-php7.2 sudo service apache2 restart.
Ubuntu 18.04, can’t enable the mbstring PHP extension
sudo apt-get install php- -y
sudo apt install phpmyadmin php-mbstring php-gettext
sudo systemctl restart apache2
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt install php7.3 php7.3-mbstring
sudo systemctl restart apache2 sudo phpenmod mbstring php -m
How do I install php mbstring extension in to Nginx Ubuntu, for PHP 7.1: sudo apt-get install php7.1-mbstring. STEP 2 — Restart you server: After the installation of mbstring , you may need to restart your
How to install php8.0-mbstring for php8.0? It keeps installing to php7.2
Figured it out thanks to Michal Przybylowicz’s comment.
The website’s repository: https://launchpad.net/~ondrej/+archive/ubuntu/php needs to be added to Ubuntu’s package system. The site lists the commands to do:
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
sudo add-apt-repository ppa:ondrej/apache2
since I run apache2. After that Laravel said that I need the ‘dom’ extension as well. That was solved by:
sudo apt install php8.0-dom
After that Laravel finally installed! Thanks Michal!
@kush solution worked great for me — after +4 hours of trying stuff.
Obviously, also works if you get this errors:
PHP Warning: PHP Startup: Unable to load dynamic library ‘curl’ (tried: /usr/lib/php/20200930/curl (/usr/lib/php/20200930/curl: cannot open shared object file: No such file or directory), /usr/lib/php/20200930/curl.so (/usr/lib/php/20200930/curl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
sudo apt install php8.0-curl or sudo apt install php[your-version]-curl
PHP Warning: PHP Startup: Unable to load dynamic library ‘mbstring’ (tried: /usr/lib/php/20200930/mbstring (/usr/lib/php/20200930/mbstring: cannot open shared object file: No such file or directory)
sudo apt install php8.0-mbstring or sudo apt install php[your-version]-mbstring
How to install PHP `mbstring` extension in Ubuntu?, 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
How do I install php mbstring extension in to Nginx Ubuntu
STEP 1 — Installing mbstring
PHP mbstring extension is not enabled by default as stated in PHP docs. Try these:
sudo apt-get install php5-mbstring
sudo apt-get install php7.0-mbstring
Now you should see mbstring as enabled in a file with below code (check above FelixEve’s answer):
You might need to use the right extension name for your PHP version :
- for PHP 5.6 : sudo apt-get install php5.6-mbstring
- for PHP 7.1 : sudo apt-get install php7.1-mbstring
STEP 2 — Restart you server:
After the installation of mbstring , you may need to restart your server ( apache2 / nginx etc). Just use the following command.
sudo service apache2 restart or sudo service nginx restart
EDIT: See Ajeets answer below for the correct solution
I don’t think mbstring (like OpenSSL) depends on an extension, it should just be built into PHP. I’m running Raspbian and NginX and if I create a file with
and look at it then I see:
How to install php8.0-mbstring for php8.0? It keeps installing to php7.2, The php8.0-mbstring is provided from this repository : launchpad.net/~ondrej/+archive/ubuntu/php · Thank you for that information. Would that