Add mbstring extension and linuxmbstring extension to php in Linux

Source: Internet
Author: User

Add mbstring extension and linuxmbstring extension to php in Linux

1. Today, a php function (mb_strcut) is used in the development project, and an error "call to undefind function mb_strcut" is prompted when running the code. First, check whether the function name is correct, is it php. I didn't enable the extension in ini. Later I went to phpinfo and saw that mb_strcut was not loaded. The background found that the extension was officially built by mbstring.

2. I couldn't find it on the official pecl homepage of php. MDZZ, what the hell. Because the php installation package contains all the extensions, I used wget to download a php5.6.24 source code package, php official http://php.net/downloads.php to enter the list to select a php source package you need, because the landlord server version is 5.6.24 so decisive download 5.6.24, if you use wget download, the default download directory will be the current directory, weget command format is very simple: wget [url] (it is better to download a php 5.6.25 package directly so wget http://hk1.php.net/get/php-5.6.25.tar.bz2/from/this/mirror) after the download will get a mirror file, use tar-zxvf mirror to decompress a folder, enter the folder, and find ext. The folder contains the php extension source file and find the extension you need. The mbstring that the landlord needs. After finding it, we can use phpize to install it. Phpize is an official tool for dynamically adding extensions. For more information, see phpize.

3. First, I want to confirm that the current system has phpize and can use it. We can see the search result through whereis phpize. For example, the author is/usr/bin/phpize. Congratulations, you can use it directly. The directories of each person may be different. Generally, phpize is included in/usr/bin. After you confirm the phpize Command Execution path, we enter the extension directory to be compiled and installed, and the landlord enters the mbstring directory. after entering the Directory and entering the command/usr/bin/phpize command at the current location, there will be several more files in the directory, configure .., enter. /configure -- with-php-config =/usr/local/php/bin/php-config command. Note that there is a dot number in front. If an error is prompted, it indicates that your php-config path is inconsistent with mine. You can find this file in whereis php-config and change it to the correct path. If no error is reported, we execute the make and make install commands in sequence. After the command is executed, it will prompt you a path, which contains the compiled extensions, for example, the extension generated by the landlord is in/usr/lib64/php/modules. When we enter this directory, we can see the extension just generated. The extension under Linux is. so, the author's micro mbstring. so, this step is done.

4. In this step, we need to modify php. the ini configuration file also uses whereis php. ini find Php. the directory where the INI file is located, usually under the/etc directory. After finding the configuration file, use vi/etc/php. ini command or vim/etc/php. ini command to open this file, the default mode is normal, we use the vim shortcut G to quickly locate the character at the bottom to add a line extension = mbstring. so is to enable the extension you just generated. If you are not using the default location storage extension, please generate the extension just now. copy the so file to the default folder. If you declare extension_dir in the current configuration file, put the extension file in the declared folder so that the extension file can be loaded. This step is last night after extension = mbstring is added.

5. In the last step, you need to restart the server. The restart includes two parts: nginx and php-fpm, because the landlord uses LNMP, if you use Lamp, you need to restart apche and php-fpm. If you do not enable php-fpm, you do not need to restart php-fpm. To enable nginx, you can use the built-in nginx management command, similarly, use whereis nginx to find the nginx Command Execution directory. The main directory is/usr/sbin/nginx. Enter/usr/sbin/nginx-s reload and restart the nginx service, the preceding path must be correct. Maybe you are different from the original one. Restart php-fpm and php-fpm, we first use the command ps-aux | grep php-fpm to obtain the list of php-fpm processes in the current system. What we need is the process Number of the process that loads the php-fpm.conf file, the number in the second column is the process number. After finding the process number, use kill [enter the preceding Process number]. For example, kill 31411 is the main program, which stops the php-fpm process, then we can view the path of the Command executed by php-fpm in whereis php-fpm. The main figure is/usr/sbin/php-fpm, run/usr/sbin/php-fpm and restart php-fpm. After the startup, go to phpinfo (). The added extension is in the list. Now we have added extensions to php. If it still does not appear after installation, You need to carefully check which step is wrong. There is also the landlord's mailbox is jeefs-@outlook.com, what problems can be sent to me.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.