Home  >  Article  >  Backend Development  >  How to install extensions in php under linux?

How to install extensions in php under linux?

PHPz
PHPzOriginal
2020-09-25 16:02:552050browse

Installation method: 1. Download the PHP extension file and use the "tar zxfv compressed package name" command to decompress it; 2. Use the cd command to enter the directory where the extension file is decompressed; 3. Use "make" and "make test" command to test; 4. Use "make install" command to install.

How to install extensions in php under linux?

The general development environment is on Windows, and it is easy to install extensions. Just throw the downloaded .dll file under ext and change php.ini File. Done.

There are two installation methods on Linux

1.Compile and install

//下载文件
#wget http://pecl.php.net/get/zip-1.12.4.tgz
//解压文件
#tar zxfv zip-1.12.4.tgz
//进入到解压文件目录
#cd zip-1.12.4
//检查系统配置开始配置,指定安装 PHP 的时候的配置
#./configure --with-php-config=/usr/local/php-5.2.17/bin/php-config
//编译
#make
//测试
#make test
//安装
#make install

2.pecl Installation method (transfer: https://blog.csdn.net/ren593669257/article/details/88070293)

①First check whether there is pecl or pear under /usr/local/php/bin/ (Installing php-pear is to use phpize in pecl) If not, use yum to install (yum install php-pear,php-devel)

②Update the pecl library pecl channel-update pecl.php. net

③Install the corresponding extension pecl install redis (if the path to php is not added to the environment variable, you need to use the absolute address)

④Generally, extensions installed through pecl are automatically added to php. ini is configured. If the installed extension is not queried through phpinfo() or php-m, add the corresponding so file to php.ini (extension=redis.so) and restart php-fpm

pear (php-pear is installed to use phpize in pecl) If not, use yum to install (yum install php-pear,php-devel)

What is phpize and its usage (redirected to: https://www.cnblogs.com/houss/p/11341280.html)

Application scenarios
In the process of using php, we often need to add some PHP extension libraries. But it is quite troublesome to recompile PHP, so at this time we can use phpize to add extensions to PHP. And the extension library compiled by phpize can be enabled or disabled at any time, which is more flexible.

Usage method
extension is the extension package to be mounted

1. wget extension.tar.gz downloads the corresponding extension package and decompresses it.
2. cd extension/switch to the extension directory
3. /php/bin/phpize Run the phpize file in the PHP installation directory. At this time, the corresponding configure file will be generated in the extension directory.
4. /configure --with-php-config=/php/bin/php-config Run configuration. If you only have one version of php installed on your server, you do not need to add --with-php-config. The following parameters are just to tell phpize which version of the extension to build on.
5. Make && make install Compile module
After compiling the module, you need to enable php. Just add extension.so to the php.ini file and open it. Restart the php service.

Function
In fact, phpize is a running script. Its main function is to detect the PHP environment and generate the corresponding configure file in a specific directory, which is generated after makeinstall. The so file will be automatically loaded into the php extension directory.

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of How to install extensions in php under linux?. For more information, please follow other related articles on the PHP Chinese website!

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