一、swoole源码下载
Swoole官网下载:https://www.swoole.com/,我们用源代码(开源中国) 库下载:
这里用git直接将源代码包克隆到本地
root@5ee6bfcc1310:/work/study/softpackage# git clone git@gitee.com:swoole/swoole.git
或者直接用curl直接下载,然后解压缩包:
curl https://gitee.com/swoole/swoole/repository/archive/master.zip
二、swoole源码安装
swoole和php的源码安装基本一样,但是 swoole 没有 configure
安装文件,这就需要我们使用PHP自带的工具 phpize
(phpize用来添加扩展模块的,可以建立PHP的外挂模块) 来生成这样的文件。
进入 swoole源码包目录下,然后执行/work/study/soft/php/bin/phpize
命令:
swoole# /work/study/soft/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
这时我们查看swoole源码包,会生成多个文件,其中就有 configure
文件。
编译:
swoole# ./configure --with-php-config=/work/study/soft/php/bin/php-config
swoole# make && make install
--with
表示指定安装的php版本,如果系统中有多个php版本的话,需要指定
编译结果:
...
PATH="$PATH:/sbin" ldconfig -n /work/study/softpackage/swoole/modules
----------------------------------------------------------------------
Libraries have been installed in:
/work/study/softpackage/swoole/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: /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files: /work/study/soft/php/include/php/
root@5ee6bfcc1310:/work/study/softpackage/swoole#
扩展放在了 /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
目录下了,我们查看该目录:
root@5ee6bfcc1310:/work/study/soft/php/bin# cd /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
root@5ee6bfcc1310:/work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718# ls -l
total 21820
-rwxr-xr-x 1 root root 5227454 Aug 27 18:07 opcache.a
-rwxr-xr-x 1 root root 2413144 Aug 27 18:07 opcache.so
-rwxr-xr-x 1 root root 14696248 Aug 28 11:06 swoole.so
swoole.so
这个文件就是我们编译后的扩展文件。
三、PHP支持Swoole
php如果要使用扩展类库,必须在 php.ini
文件中做一些配置才能使用,否则会报错找不到该类文件。
编辑php.ini
文件
root@5ee6bfcc1310:/work/study/soft/php/lib# vim php.ini
extension 扩展新增一行:
extension=swoole
检查一下,是否有swoole扩展:
root@5ee6bfcc1310:/work/study/soft/php/lib# php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
我们可以看到PHP的扩展已经有 swoole,至此,我们的PHP和Swoole安装编译完成 ^_^。
四、源码编译安装curl
在运行php curl_init
的时候报出这样的错误:
Warning: PHP Startup: Unable to load dynamic library 'curl' (tried: /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/curl (/work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/curl: cannot open shared object file: No such file or directory), /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/curl.so
是因为curl扩展没有安装导致的,所以这里对源码进行编译安装。
1、进入php源码包目录,执行phpize生成配置文件
cd /work/study/softpackage/php-7.2.21/ext/
查看扩展包:
root@5ee6bfcc1310:/work/study/softpackage/php-7.2.21/ext# ls -l
total 16
drwxr-xr-x 10 root root 340 Jul 30 17:21 bcmath
drwxr-xr-x 11 root root 374 Jul 30 17:21 bz2
drwxr-xr-x 17 root root 578 Jul 30 17:21 calendar
drwxr-xr-x 21 root root 714 Jul 30 17:21 com_dotnet
drwxr-xr-x 13 root root 442 Aug 28 01:49 ctype
drwxr-xr-x 12 root root 408 Jul 30 17:21 curl
drwxr-xr-x 13 root root 442 Aug 28 01:45 date
drwxr-xr-x 39 root root 1326 Jul 30 17:21 dba
drwxr-xr-x 110 root root 3740 Aug 28 01:50 dom
drwxr-xr-x 10 root root 340 Jul 30 17:21 enchant
drwxr-xr-x 12 root root 408 Jul 30 17:21 exif
-rwxr-xr-x 1 root root 9415 Jul 30 17:21 ext_skel
-rw-r--r-- 1 root root 1165 Jul 30 17:21 ext_skel_win32.php
drwxr-xr-x 20 root root 680 Aug 28 01:50 fileinfo
drwxr-xr-x 22 root root 748 Aug 28 01:52 filter
drwxr-xr-x 11 root root 374 Jul 30 17:21 ftp
drwxr-xr-x 14 root root 476 Jul 30 17:21 gd
drwxr-xr-x 8 root root 272 Jul 30 17:21 gettext
drwxr-xr-x 12 root root 408 Jul 30 17:21 gmp
drwxr-xr-x 72 root root 2448 Aug 28 01:53 hash
drwxr-xr-x 22 root root 748 Aug 28 01:53 iconv
drwxr-xr-x 9 root root 306 Jul 30 17:21 imap
drwxr-xr-x 14 root root 476 Jul 30 17:21 interbase
drwxr-xr-x 37 root root 1258 Jul 30 17:21 intl
drwxr-xr-x 30 root root 1020 Aug 28 01:53 json
drwxr-xr-x 10 root root 340 Jul 30 17:21 ldap
drwxr-xr-x 12 root root 408 Aug 28 01:46 libxml
drwxr-xr-x 24 root root 816 Jul 30 17:21 mbstring
drwxr-xr-x 25 root root 850 Jul 30 17:21 mysqli
drwxr-xr-x 55 root root 1870 Jul 30 17:21 mysqlnd
drwxr-xr-x 18 root root 612 Jul 30 17:21 oci8
drwxr-xr-x 11 root root 374 Jul 30 17:21 odbc
我们可以看到有许多扩展,进入curl扩展目录,执行命令:
cd /work/study/softpackage/php-7.2.21/ext/curl
/work/study/soft/php/bin/phpize
2、调用configure生成Makefile文件
./configure --with-php-config=/work/study/soft/php/bin/php-config
生成Makefile
文件的时候出现这样的问题:curl version 7.10.5 or later is required to compile php with curl support
,
可更新系统扩展即可:
Ubuntu:sudo apt-get install libcurl4-gnutls-dev
CentOS:sudo yum install curl-devel
3、编译并安装
make && make install
安装成功:
Installing shared extensions: /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
在PHP安装目录查看扩展包:
root@5ee6bfcc1310:/work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718# ls -l
total 22248
-rwxr-xr-x 1 root root 438152 Sep 7 16:30 curl.so
-rwxr-xr-x 1 root root 5227454 Aug 28 02:07 opcache.a
-rwxr-xr-x 1 root root 2413144 Aug 28 02:07 opcache.so
-rwxr-xr-x 1 root root 14696248 Aug 28 19:06 swoole.so
4、php.ini开启扩展
extension=curl
五、安装phpredis扩展
1、下载
wget https://github.com/phpredis/phpredis/archive/5.0.0.tar.gz
更改名字
mv 5.0.0.tar.gz phpredis-5.0.0.tar.gz
解压:
tar -zvx phpredis-5.0.0.tar.gz
进入解压目录生成配置文件:
/work/study/softpackage# cd phpredis-5.0.0
/work/study/softpackage/phpredis-5.0.0# /work/study/soft/php/bin/phpize
./configure --with-php-config=/work/study/soft/php/bin/php-config
make && make install
在 php.ini 文件中开启扩展:
extension=redis
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。