Home >php教程 >php手册 >Add mbstring extension to php in Linux environment

Add mbstring extension to php in Linux environment

WBOY
WBOYOriginal
2016-08-20 08:47:37977browse

1. Today, I used a PHP function (mb_strcut) when developing a project. When running the code, an error message "call to undefind function mb_strcut" was prompted. First, check that the function name is not written incorrectly. Is it because the extension is not enabled in php.ini? Later, I went to phpinfo to see that mb_strcut was not loaded. I learned in the background that this extension is officially built by mbstring

2. When searching on the official php pecl homepage, I couldn’t find MDZZ, what the hell. Since the php installation package contains all the extensions, the author used wget to download a php5.6.24 source code package. The official php download address is http ://php.net/downloads.php Enter the list and select a PHP source package you need. Since the version used by the host's server is 5.6.24, download 5.6.24 decisively. If you use wget to download, the default download directory will be the current one. Directory, the weget command format is very simple: wget [url] (It is better to download a PHP 5.6.25 package directly like wget http://hk1.php.net/get/php-5.6.25.tar.bz2/from/this /mirror) After downloading, you will get a mirror file, and then use tar -zxvf mirror to decompress it to get a folder. Enter the folder and find ext. This folder contains the source file of the PHP extension. Find the extension you need. , after finding the mbstring that the poster needs, we can use phpize to install it. phpize is an official tool for dynamically adding extensions. Learn more about phpize

3. First of all, I need to make sure that phpize exists in the current system and can be used. We can see the search results by whereis phpize. For example, the poster’s is /usr/bin/phpize. Congratulations, you can use it directly. Everyone’s directory It may be different. Generally, phpize is included under /usr/bin. After determining the execution path of the phpize command, we enter the extension directory that needs to be compiled and installed. The author just enters mbstring. After entering the directory, enter the command /usr/bin at the current location. After the /phpize command is executed, there will be several more files in the directory, including configure.., and then enter the ./configure --with-php-config=/usr/local/php/bin/php-config command. Note that the preceding There is a point. If an error is prompted, it means that your php-config path is inconsistent with mine. You can use whereis php-config to find this file, and then change it to the correct path. If no error is reported, we execute it in sequence. , after the make and make install commands are executed, it will prompt you for a path. In this path are the good extensions we compiled. For example, the extension generated by the original poster is in /usr/lib64/php/modules. When we enter this directory, You can see the extension just generated. The suffix of the extension under Linux is .so. The original poster’s micro is mbstring.so. This step is done

4. In this step, we need to modify the php.ini configuration file. Also use whereis php.ini to find the directory where the Php.ini file is located, usually under the /etc directory. After finding the configuration file, use the vi /etc/php.ini command Or open this file with the vim /etc/php.ini command. The default is normal mode. We use the vim shortcut key G to quickly locate the bottom of the character and add a line extension=mbstring.so. This line is to start the extension you just generated. There is another question. If you are not using the default location to store extensions, please copy the .so file you just generated to the default folder. If you declared extension_dir in the current configuration file, put the extension file in the declared folder, so that Extension files can be loaded into. After adding extension = mbstring, this step last night

5. The last step requires restarting the server. Restarting includes 2 parts. Because the poster uses LNMP, nginx and php-fpm need to be restarted. If you use Lamp, apche and php-fpm need to be restarted. If not, There is no need to restart php-fpm to enable php-fpm. To enable nginx, you can use the management command that comes with nginx. Also use whereis nginx to find the nginx command execution directory. The original poster is /usr/sbin/nginx, enter /usr/sbin/ Restart the nginx service after nginx -s reload. The previous path must be correct. Yours may be different from the original poster. Next, restart php-fpm and restart php-fpm. We first use the command ps -aux |grep php-fpm Get the list of processes including php-fpm in the current system. What we need is the process number of the process that loaded the php-fpm.conf file. The number in the second column is the process number. After finding the process number, use kill [fill in what you just said here process number], for example, the poster's is 31411, which is kill 31411. This will stop the php-fpm process, and then we use whereis php-fpm to view the path of the command executed by php-fpm. The poster's is /usr/sbin /php-fpm, you can restart php-fpm after executing /usr/sbin/php-fpm. After starting, go to phpinfo(). You can see that the extension we added is already in the list. At this point we have completed adding extensions to php. If it still does not appear after installation, you need to carefully check which step you did wrong. Also, the email address of the original poster is jeefs-@outlook.com. If you have any questions, you can send me an email.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:1.1 Object-orientedNext article:1.1 Object-oriented