安装环境:
linux系统:CentOS 7.9.2009 64bit
php版本:php-7.4.19
nginx版本:nginx-1.20.0 stable version
什么是php扩展?
就是php核心并不支持的功能,通过扩展的方式进行扩展PHP的功能。
有哪些常见的扩展呢?
像GD库,mysql,json,sqlite3等库,还有OPcache,PCRE,PDO等,这些扩展库是绑定在 PHP 发行包中的,所以这些只要–enable或–with启用就可以了,而我们现在要说的是须额外编译安装的扩展。
1、redis扩展
下载地址:
# wget
# tar xf redis-5.3.4.tgz
# cd redis-5.3.4
# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装成功后的提示信息:
Libraries have been installed in:
/root/redis-5.3.4/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/ld.so.conf’
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
Build complete.
Don’t forget to run ‘make test’.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
可以查看到扩展目录下多了 redis.so
# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902
opcache.a opcache.so redis.so
把扩展添加到php配置文件中:
# vim /etc/php.ini
extension=redis.so
重启php-fpm
# systemctl restart php-fpm
可以在站点目录下创建一个phpinfo.php的页面
<?php
phpinfo();
?>
查看安装的扩展成功与否,访问,能够查找到redis的信息则说明已经安装上了。
2、swoole扩展
安装前必须保证系统已经安装了下列软件 php-7.0 或更高版本 gcc-4.8 或更高版本 make autoconf pcre (CentOS系统可以执行命令:yum install pcre-devel)
下载地址:
# wget
# tar xf swoole-4.6.7.tgz
# cd swoole-4.6.7
# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装成功后的提示信息:
Libraries have been installed in:
/root/swoole-4.6.7/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/ld.so.conf’
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
Build complete.
Don’t forget to run ‘make test’.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing header files: /usr/local/php/include/php/
同样的把扩展添加到php配置文件中,重启php-fpm服务:
# vim /etc/php.ini
extension=swoole.so
重启php-fpm
# systemctl restart php-fpm
确认扩展安装情况:
还有其他的扩展安装,也是按这个方法来,大家应该都能举一反三了吧。