一、安装swoole准备工作。
1、选择自己的安装方式,我这里选择用git安装下载安装包。
安装git
yum install git
.
完成之后,从GitHub上下载swoole的源码。
#安装最新的源码包。
git clone https://github.com/swoole/swoole-src.git
下载完成,查看-》运行phpize 生成。configure文件
查看:
benchmark swoole_client_coro.cc swoole_postgresql_coro.h
build.sh swoole_config.h swoole_process.c
clear.sh swoole_coroutine.cc swoole_process_pool.c
CMakeLists.txt swoole_coroutine.h swoole_redis.c
config.m4 swoole_coroutine_util.c swoole_redis_coro.c
core-tests swoole_event.c swoole_redis_server.c
CREDITS swoole_http_client.c swoole_ringqueue.c
examples swoole_http_client_coro.c swoole_runtime.cc
include swoole_http_client.h swoole_serialize.c
LICENSE swoole_http.h swoole_serialize.h
make.sh swoole_http_server.c swoole_server.c
package.xml swoole_http_v2_client.c swoole_server_port.c
php7_wrapper.h swoole_http_v2_client_coro.c swoole_socket_coro.c
php_swoole.h swoole_http_v2_client.h swoole_table.c
README.md swoole_http_v2_server.c swoole_timer.c
src swoole_lock.c swoole_trace.c
swoole_async.c swoole_memory_pool.c swoole_websocket_server.c
swoole_atomic.c swoole_mmap.c tests
swoole_buffer.c swoole_msgqueue.c thirdparty
swoole.c swoole_mysql.c tools
swoole_channel.c swoole_mysql_coro.c travis
swoole_channel_coro.cc swoole_mysql.h Version2.md
swoole_client.c swoole_postgresql_coro.c
运行:
/usr/local/php7.2.9/bin/phpize
成功显示:
acinclude.m4 src swoole_mysql.c
aclocal.m4 swoole_async.c swoole_mysql_coro.c
benchmark swoole_atomic.c swoole_mysql.h
build swoole_buffer.c swoole_postgresql_coro.c
build.sh swoole.c swoole_postgresql_coro.h
clear.sh swoole_channel.c swoole_process.c
CMakeLists.txt swoole_channel_coro.cc swoole_process_pool.c
config.guess swoole_client.c swoole_redis.c
config.m4 swoole_client_coro.cc swoole_redis_coro.c
config.sub swoole_config.h swoole_redis_server.c
configure.ac swoole_coroutine.cc swoole_ringqueue.c
core-tests swoole_coroutine.h swoole_runtime.cc
CREDITS swoole_coroutine_util.c swoole_serialize.c
examples swoole_event.c swoole_serialize.h
include swoole_http_client.c swoole_server.c
install-sh swoole_http_client_coro.c swoole_server_port.c
LICENSE swoole_http_client.h swoole_socket_coro.c
ltmain.sh swoole_http.h swoole_table.c
Makefile.global swoole_http_server.c swoole_timer.c
make.sh swoole_http_v2_client.c swoole_trace.c
missing swoole_http_v2_client_coro.c swoole_websocket_server.c
mkinstalldirs swoole_http_v2_client.h tests
package.xml swoole_http_v2_server.c thirdparty
php7_wrapper.h swoole_lock.c tools
php_swoole.h swoole_memory_pool.c travis
README.md swoole_mmap.c Version2.md
run-tests.php swoole_msgqueue.c
多了几个文件。但是没有configure文件。原因:
#没有安装autoconf
yum -y install autoconf
#安装成功
#再次运行
/usr/local/php7.2.9/bin/phpize
#查看生成的文件
acinclude.m4 Makefile.global swoole_coroutine_util.c swoole_process_pool.c
aclocal.m4 make.sh swoole_event.c swoole_redis.c
autom4te.cache missing swoole_http_client.c swoole_redis_coro.c
benchmark mkinstalldirs swoole_http_client_coro.c swoole_redis_server.c
build package.xml swoole_http_client.h swoole_ringqueue.c
build.sh php7_wrapper.h swoole_http.h swoole_runtime.cc
clear.sh php_swoole.h swoole_http_server.c swoole_serialize.c
CMakeLists.txt README.md swoole_http_v2_client.c swoole_serialize.h
config.guess run-tests.php swoole_http_v2_client_coro.c swoole_server.c
config.h.in src swoole_http_v2_client.h swoole_server_port.c
config.m4 swoole_async.c swoole_http_v2_server.c swoole_socket_coro.c
config.sub swoole_atomic.c swoole_lock.c swoole_table.c
configure swoole_buffer.c swoole_memory_pool.c swoole_timer.c
configure.ac swoole.c swoole_mmap.c swoole_trace.c
core-tests swoole_channel.c swoole_msgqueue.c swoole_websocket_server.c
CREDITS swoole_channel_coro.cc swoole_mysql.c tests
examples swoole_client.c swoole_mysql_coro.c thirdparty
include swoole_client_coro.cc swoole_mysql.h tools
install-sh swoole_config.h swoole_postgresql_coro.c travis
LICENSE swoole_coroutine.cc swoole_postgresql_coro.h Version2.md
ltmain.sh swoole_coroutine.h swoole_process.c
#可以看到有configure文件
运行:
./configure --help
显示:
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
Optional Features and Packages:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-libdir=NAME Look for libraries in .../NAME rather than .../lib
--with-php-config=PATH Path to php-config php-config
--enable-swoole-debug Enable swoole debug
--enable-trace-log Enable swoole trace log
--enable-sockets Do you have sockets extension?
--enable-async-redis Do you have hiredis?
--enable-coroutine-postgresql Do you install postgresql?
--enable-openssl Use openssl?
--enable-http2 Use http2.0?
--enable-thread Experimental: Use thread?
--enable-hugepage Experimental: Use hugepage?
--enable-swoole Enable swoole support
--enable-swoole-static Enable swoole static compile support
--with-swoole With swoole support
--with-libpq-dir=DIR Include libpq support (requires libpq >= 9.5)
--with-openssl-dir=DIR Include OpenSSL support (requires OpenSSL >= 0.9.6)
--with-phpx-dir=DIR Include PHP-X support
--with-jemalloc-dir=DIR Include jemalloc support
--enable-mysqlnd Do you have mysqlnd?
--enable-asan Enable asan
--enable-picohttpparser Experimental: Do you have picohttpparser?
--enable-timewheel Experimental: Enable timewheel heartbeat?
--enable-debug, compile with debug symbols
--enable-shared=PKGS Build shared libraries default=yes
--enable-static=PKGS Build static libraries default=yes
--enable-fast-install=PKGS
Optimize for fast installation default=yes
--with-gnu-ld Assume the C compiler uses GNU ld default=no
--disable-libtool-lock Avoid locking (might break parallel builds)
--with-pic Try to use only PIC/non-PIC objects default=use both
--with-tags=TAGS Include additional configurations automatic
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to the package provider.
在执行swoole的时候打出调试的信息
./configure --with-php-config=/usr/local/php7.2.9/bin/php-config
显示:
creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: creating ./config.status
config.status: creating config.h
运行:
make
成功
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'.
运行
make install
结果:
Installing shared extensions: /usr/local/php7.2.9/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files: /usr/local/php7.2.9/include/php/
#完成,可以看到swoole.so扩展的位置
cd /usr/local/php7.2.9/lib/php/extension/no-debug-non-zts-20170718/
$ ll
#显示
-rwxr-xr-x 1 root root 3581340 Aug 22 00:07 opcache.a
-rwxr-xr-x 1 root root 1971336 Aug 22 00:07 opcache.so
-rwxr-xr-x 1 root root 9534576 Aug 24 22:39 swoole.so
打开php.ini加上extension=swoole
最后cd /home/study/swoole/examples/server/
运行php echo.php
没有报错证明成功。
到此swoole安装成功。