Add mbstring extensions to PHP in a Linux environment

Source: Internet
Author: User
Tags phpinfo

1, today in the development of the project using a PHP function (mb_strcut), run the code when prompted to error "Call to Undefind function Mb_strcut", first check the function name is not written wrong, is not php.ini in the extension, and then went to phpinfo see did not load mb_strcut, backstage learned that this extension in the official build by mbstring

2, go to PHP official Pecl Home Search unexpectedly search, mdzz,what the hell, because the PHP installation package with all the extension, so the landlord with wget download a php5.6.24 source package, PHP official http://php.net/ downloads.php Enter the list to choose a PHP source package you need, because the landlord server version is 5.6.24 so decisive download 5.6.24, if downloaded with wget, the default download directory will be the current directory, weget command format simple: wget [url] (rather than download a PHP 5.6.25 package directly so wget http://hk1.php.net/get/php-5.6.25.tar.bz2/from/this/mirror) will be downloaded after the completion of a mirror file, Then use TAR-ZXVF mirror extract to get a folder, into the folder, find Ext, this folder contains PHP extension source files, find the extension you need, landlord need mbstring, find, we can use Phpize to install. Phpize is officially provided by a dynamic Add extension tool to learn more about the degree of Niang phpize

3, first I want to determine the current system exists phpize, and can use, we whereis phpize, you can see the search results, such as the landlord is/usr/bin/phpize, congratulations, you can directly use, everyone's directory may be all different, General Phpize is contained in the/usr/bin below, determined the phpize command execution path, we enter the need to compile the installation of the extension directory, the landlord is to enter the mbstring, after entering the directory in the current position after the command/usr/bin/phpize command execution is completed, There will be a few more files in the directory, there are configure. , and then enter the./configure--with-php-config=/usr/local/php/bin/php-config Command, note that there is a point in front of the amount, if the error indicates that your php-config path and my inconsistency, Can Whereis Php-config, find this file, and then replace the correct path, in the case of no error, we executed sequentially, make and do install command completed, it will prompt you a path, this path is our compilation of good extension, For example, the building of the landlord's extension in/usr/lib64/php/modules, we enter this directory, we can see the extension just generated, under Linux extension suffix is. So, the landlord of the micro-mbstring.so, this step is done

4, this step we need to modify the php.ini configuration file, the same whereis php.ini find the php.ini file is located in the directory, usually under the/etc directory, find the configuration file, with the Vi/etc/php.ini command or vim/etc/ php.ini command to open this file, the default is normal mode, we use the Vim shortcut G quickly navigate to the bottom of the character to add a line extension=mbstring.so this line is to open you just build the extension, there is a problem if you do not use the default location to store the extension, Please copy the generated. So file to the default folder, and if you declare extension_dir in the current profile, put the extension file in the declared folder so that the file can be loaded. Add extension = mbstring This step is last night.

5, the last step needs to restart the server, restart includes 2 parts, because the landlord is using LNMP, so the need to restart is nginx and PHP-FPM, if you use lamp so need to restart is Apche and PHP-FPM, If the PHP-FPM does not need to restart the PHP-FPM, open Nginx can use the management commands Nginx, the same use Whereis nginx, find nginx command execution directory, the landlord is/usr/sbin/nginx, input/usr/ Sbin/nginx-s Reload after restart Nginx service, the front path must be correct, may be your and landlord's not the same, next restart PHP-FPM, restart PHP-FPM, we first use the command Ps-aux |grep php-fpm Get the current system contains the PHP-FPM process list, we need to load the php-fpm.conf file that process of the process number, the number of the second column is the process number, find the process number, use kill [here to fill in the process number], such as the landlord is 31411, is kill 31411, to do this is to stop the process of php-fpm, and then we whereis php-fpm view the path of the command executed PHP-FPM, the landlord is/USR/SBIN/PHP-FPM, execute/usr/sbin/ After PHP-FPM can restart the PHP-FPM, after the launch to Phpinfo (), you can see that we added the extension is already in the list. Now that we've added extensions to PHP, we're done. If it does not appear after installation, you need to carefully troubleshoot which step is wrong. Also has the landlord's mailbox is [email protected], have what question can send me the mail.

Add mbstring extensions to PHP in a Linux environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.