1.环境已源码安装php5.6 和php7.3
目录
[root@iZ2zedsf2i1n3fvo7zc64kZ no-debug-non-zts-20190902]# cd /usr/local/php
[root@iZ2zedsf2i1n3fvo7zc64kZ php]# ll
total 8
drwxr-xr-x 9 root root 4096 Apr 24 10:43 56
drwxr-xr-x 9 root root 4096 Apr 24 10:56 74
版本看到的是最新版本:
[root@iZ2zedsf2i1n3fvo7zc64kZ no-debug-non-zts-20190902]# php -v
PHP 7.4.33 (cli) (built: Apr 24 2023 10:56:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
2.下载swoole 4.8.13 php8.0以下的最新版本
https://gitee.com/swoole/swoole/repository/archive/v4.8.13
3.进入目录安装
[root@iZ2zedsf2i1n3fvo7zc64kZ ~]# ll
-rw-r--r-- 1 root root 2875113 May 24 09:45 swoole-v4.8.13.zip
[root@iZ2zedsf2i1n3fvo7zc64kZ ~]# unzip swoole-v4.8.13.zip
[root@iZ2zedsf2i1n3fvo7zc64kZ ~]# cd swoole-v4.8.13/
由于php多版本,考虑swoole扩展安装到哪个版本下
[root@iZ2zedsf2i1n3fvo7zc64kZ swoole-v4.8.13]# whereis phpize
phpize: /usr/local/php/74/bin/phpize
[root@iZ2zedsf2i1n3fvo7zc64kZ swoole-v4.8.13]# /usr/local/php/74/bin/phpize
[root@iZ2zedsf2i1n3fvo7zc64kZ swoole-v4.8.13]# ./configure --with-php-config=/usr/local/php/74/bin/php-config
[root@iZ2zedsf2i1n3fvo7zc64kZ swoole-v4.8.13]# make && make install
安装成功如下图:
creating swoole.la
(cd .libs && rm -f swoole.la && ln -s ../swoole.la swoole.la)
/bin/sh /root/swoole-v4.8.13/libtool --mode=install cp ./swoole.la /root/swoole-v4.8.13/modules
cp ./.libs/swoole.so /root/swoole-v4.8.13/modules/swoole.so
cp ./.libs/swoole.lai /root/swoole-v4.8.13/modules/swoole.la
PATH="$PATH:/sbin" ldconfig -n /root/swoole-v4.8.13/modules
----------------------------------------------------------------------
Libraries have been installed in:
/root/swoole-v4.8.13/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/74/lib/php/extensions/no-debug-non-zts-20190902/
Installing header files: /usr/local/php/74/include/php/
phpize: /usr/local/php/74/bin/phpize
[root@iZ2zedsf2i1n3fvo7zc64kZ swoole-v4.8.13]# cd /usr/local/php/74/lib/php/extensions/no-debug-non-zts-20190902/
[root@iZ2zedsf2i1n3fvo7zc64kZ no-debug-non-zts-20190902]# ll
total 69708
-rwxr-xr-x 1 root root 153728 Apr 24 11:27 mcrypt.so
-rwxr-xr-x 1 root root 4693766 Apr 24 10:56 opcache.a
-rwxr-xr-x 1 root root 2509944 Apr 24 10:56 opcache.so
-rwxr-xr-x 1 root root 641704 Apr 26 14:20 openssl.so
-rwxr-xr-x 1 root root 1801144 Apr 27 17:34 redis.so
-rwxr-xr-x 1 root root 30964904 May 24 10:24 swoole.so
4.配置使用扩展
[root@iZ2zedsf2i1n3fvo7zc64kZ no-debug-non-zts-20190902]# php --ini
Configuration File (php.ini) Path: /usr/local/php/74/etc
Loaded Configuration File: /usr/local/php/74/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
vi /usr/local/php/74/etc/php.ini
最后,编译安装成功后,修改 php.ini
加入
extension=swoole.so
通过 php -m
来查看是否成功加载了 swoole.so
,如果没有可能是 php.ini
的路径不对。
可以使用 php --ini
来定位到 php.ini
的绝对路径,Loaded Configuration File
一项显示的是加载的 php.ini 文件,如果值为 none
证明根本没加载任何 php.ini
文件,需要自己创建。