How to enable PHP MBString Extension on Ubuntu?

The PHP MBString extension is used to handle multibyte strings, which is essential for supporting different character encodings in your web applications. In this guide, we will show you how to enable the PHP MBString extension on Ubuntu.

Note: These instructions are for Ubuntu 18.04 and 20.04. Some steps may differ for other Ubuntu versions.

Step 1: Update the Package List

Open a terminal window and run the following command to update the package list:

sudo apt update

This command fetches the latest package information from the configured repositories and updates the local package list.

Step 2: Install the PHP MBString Extension

After updating the package list, install the PHP MBString extension using the following command:

sudo apt install -y php-mbstring

If you have a specific PHP version installed, such as PHP 7.4, install the corresponding MBString extension:

sudo apt install -y php7.4-mbstring
root@geek:~# sudo apt install -y php7.4-mbstring
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 39 not upgraded.
Need to get 396 kB of archives.
After this operation, 1,079 kB of additional disk space will be used.
Get:1 bionic/main amd64 php7.4-mbstring amd64 [396 kB]
Fetched 396 kB in 0s (1,193 kB/s)       
Selecting previously unselected package php7.4-mbstring.
(Reading database ... 121676 files and directories currently installed.)
Preparing to unpack .../ ...
Unpacking php7.4-mbstring ( ...
Setting up php7.4-mbstring ( ...

Creating config file /etc/php/7.4/mods-available/mbstring.ini with new version
Processing triggers for libapache2-mod-php7.4 ( ...
Processing triggers for php7.4-cli ( ...

Step 3: Restart the Web Server

After installing the PHP MBString extension, you need to restart your web server for the changes to take effect. If you’re using Apache, restart the service with the following command:

sudo systemctl restart apache2

If you’re using Nginx, restart the Nginx and PHP-FPM services:

sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm

Replace php7.4-fpm with the appropriate PHP-FPM version if you’re using a different PHP version.

See also  How to Install DiG on Ubuntu

Step 4: Verify the PHP MBString Extension is Enabled

To verify that the PHP MBString extension is enabled, create a PHP file called info.php in your web server’s document root (e.g., /var/www/html/) with the following content:


Now, visit http://your_server_ip/info.php in your web browser, and you should see the PHP information page. Look for the “mbstring” section, which confirms that the MBString extension is enabled.

After verifying the extension is enabled, don’t forget to remove the info.php file, as it can expose sensitive information about your server:

sudo rm /var/www/html/info.php


You have now successfully enabled the PHP MBString extension on your Ubuntu system. This extension allows your web applications to handle multibyte strings and provides better support for different character encodings.

See also  How to Check SELinux Status on Ubuntu

If you have any questions, comments, or suggestions for improvement, please feel free to share your thoughts in the comments section below. Your feedback is invaluable to us, and it helps us create better and more informative content for our users.


Leave a Reply

Your email address will not be published. Required fields are marked *