ubuntu 安装thinkphp-swoole

环境:系统:ubuntu 18.04.1  php7.2 .33

swoole官方wiki地址:https://wiki.swoole.com

在项目目录中执行命令 composer require thinktop/think-swoole安装报错

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - topthink/think-swoole v3.0.9 requires ext-swoole >=4.4.8 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.8 requires ext-swoole >=4.4.8 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.7 requires ext-swoole >=4.4.8 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.6 requires ext-swoole >=4.4.8 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.5 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.4 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.3 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.2 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.1 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - topthink/think-swoole v3.0.0 requires ext-swoole >=4.0.0 -> the requested PHP extension swoole is missing from your system.
    - Installation request for topthink/think-swoole ^3.0 -> satisfiable by topthink/think-swoole[v3.0.0, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.2/cli/php.ini
    - /etc/php/7.2/cli/conf.d/10-mysqlnd.ini
    - /etc/php/7.2/cli/conf.d/10-opcache.ini
    - /etc/php/7.2/cli/conf.d/10-pdo.ini
    - /etc/php/7.2/cli/conf.d/15-xml.ini
    - /etc/php/7.2/cli/conf.d/20-calendar.ini
    - /etc/php/7.2/cli/conf.d/20-ctype.ini
    - /etc/php/7.2/cli/conf.d/20-curl.ini
    - /etc/php/7.2/cli/conf.d/20-dom.ini
    - /etc/php/7.2/cli/conf.d/20-exif.ini
    - /etc/php/7.2/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.2/cli/conf.d/20-ftp.ini
    - /etc/php/7.2/cli/conf.d/20-gd.ini
    - /etc/php/7.2/cli/conf.d/20-gettext.ini
    - /etc/php/7.2/cli/conf.d/20-iconv.ini
    - /etc/php/7.2/cli/conf.d/20-igbinary.ini
    - /etc/php/7.2/cli/conf.d/20-json.ini
    - /etc/php/7.2/cli/conf.d/20-mbstring.ini
    - /etc/php/7.2/cli/conf.d/20-mysqli.ini
    - /etc/php/7.2/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/7.2/cli/conf.d/20-phar.ini
    - /etc/php/7.2/cli/conf.d/20-posix.ini
    - /etc/php/7.2/cli/conf.d/20-readline.ini
    - /etc/php/7.2/cli/conf.d/20-redis.ini
    - /etc/php/7.2/cli/conf.d/20-shmop.ini
    - /etc/php/7.2/cli/conf.d/20-simplexml.ini
    - /etc/php/7.2/cli/conf.d/20-sockets.ini
    - /etc/php/7.2/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.2/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.2/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.2/cli/conf.d/20-tokenizer.ini
    - /etc/php/7.2/cli/conf.d/20-wddx.ini
    - /etc/php/7.2/cli/conf.d/20-xmlreader.ini
    - /etc/php/7.2/cli/conf.d/20-xmlwriter.ini
    - /etc/php/7.2/cli/conf.d/20-xsl.ini
    - /etc/php/7.2/cli/conf.d/20-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

看问题是没安装swoole扩展,那么安装一下swool

找到官方给的地址 :https://wiki.swoole.com/#/environment

使用pecl安装

$ sudo pecl install swoole
downloading swoole-4.5.4.tgz ...
Starting to download swoole-4.5.4.tgz (1,563,795 bytes)
.....................................................................................................................................................................................................................................................................................................................done: 1,563,795 bytes
379 source files, building
running: phpize
sh: 1: phpize: not found
ERROR: `phpize' failed

发现phpize没有安装,安装:执行命令sudo apt install php7.2-dev

校验phpize是否安装成功

$ phpize
Cannot find config.m4. 
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module

恩,已成功,虽然有错误,但已安装成功

再次尝试安装扩张swoole

$ sudo pecl install swoole
downloading swoole-4.5.4.tgz ...
Starting to download swoole-4.5.4.tgz (1,563,795 bytes)
.....................................................................................................................................................................................................................................................................................................................done: 1,563,795 bytes
379 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
enable sockets supports? [no] : y
enable openssl support? [no] : y
enable http2 support? [no] : y
enable mysqlnd support? [no] : y
building in /tmp/pear/temp/pear-build-rootfAVZC5/swoole-4.5.4
running: /tmp/pear/temp/swoole/configure --with-php-config=/usr/bin/php-config --enable-sockets=y --enable-openssl=y --enable-http2=y --enable-mysqlnd=y
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20170718
checking for PHP installed headers prefix... /usr/include/php/20170718
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking enable debug log... no
checking enable trace log... no
checking enable sockets support... y
checking enable openssl support... y
checking enable http2.0 support... y
checking swoole support... yes, shared
checking enable mysqlnd support... y
checking dir of openssl... no
checking dir of jemalloc... no
checking enable asan... no
checking whether to enable swoole coverage support... no
checking whether to enable Swoole developer build flags... no
checking if compiling with clang... no
checking for accept4 in -lc... yes
checking for signalfd in -lc... yes
checking for eventfd in -lc... yes
checking for epoll_create in -lc... yes
checking for poll in -lc... yes
checking for sendfile in -lc... yes
checking for kqueue in -lc... no
checking for backtrace in -lc... yes
checking for daemon in -lc... yes
checking for mkostemp in -lc... yes
checking for inotify_init in -lc... yes
checking for malloc_trim in -lc... yes
checking for inotify_init1 in -lc... yes
checking for gethostbyname2_r in -lc... yes
checking for ptrace in -lc... yes
checking for getrandom in -lc... yes
checking for pthread_rwlock_init in -lpthread... yes
checking for pthread_spin_lock in -lpthread... yes
checking for pthread_mutex_timedlock in -lpthread... yes
checking for pthread_barrier_init in -lpthread... yes
checking for pthread_mutexattr_setrobust in -lpthread... yes
checking for pthread_mutex_consistent in -lpthread... yes
checking for pcre_compile in -lpcre... yes
checking for gzgets in -lz... no
checking for BrotliEncoderCreateInstance in -lbrotlienc... no
checking for cpu affinity... yes
checking for socket REUSEPORT... yes
checking for futex... yes
checking for ucontext... yes
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking for valgrind... no
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/tmp/pear/temp/pear-build-rootfAVZC5/swoole-4.5.4':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
ERROR: `/tmp/pear/temp/swoole/configure --with-php-config=/usr/bin/php-config --enable-sockets=y --enable-openssl=y --enable-http2=y --enable-mysqlnd=y' failed

又一次报错了,有“C++ preprocessor ‘lib/cpp' fails sanity check"提示,在官方文档中又提到swool是由c/c++编写,再向上翻看会看到检查c++的编译器(自己的定义)g++缺失,那么问题可以定位成缺失c++的编译环境了,安装下g++

$ sudo apt-get install g++

安装好g++后再次执行命令$ sudo pecl install swoole

经过一段时间的编译终于成功了


Build process completed successfully
Installing '/usr/include/php/20170718/ext/swoole/config.h'
Installing '/usr/lib/php/20170718/swoole.so'
install ok: channel://pecl.php.net/swoole-4.5.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=swoole.so" to php.ini

按提示,需要把swoole的扩展库加到php的配置文件php.ini中

那么加一下,执行命令:$php  --ini 查看配置文件位置(已知地址省略本步)

打开php.ini 将extension=swoole.so添加到extension的示例的位置,方便查看,保存退出。

执行命令:

$ php -m | grep swoole

获取到结果那么安装扩张成功,否则就是php的extension的存放位置不正确,可以加上swool.so的绝对路径,如:/usr/lib/php/20170718/swoole.so

接下来 下载thinkphp6.0-swoole

$ composer require topthink/think-swooleUsing version ^3.0 for topthink/think-swoole
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
  - Installing open-smf/connection-pool (v1.0.15): Downloading (100%)         
  - Installing nette/utils (v3.1.3): Downloading (100%)         
  - Installing nette/php-generator (v3.4.1): Downloading (100%)         
  - Installing swoole/ide-helper (4.5.4): Downloading (100%)         
  - Installing symfony/finder (v4.4.13): Downloading (100%)         
  - Installing topthink/think-swoole (v3.0.9): Downloading (100%)         
nette/utils suggests installing ext-intl (to use Strings::webalize(), toAscii(), normalize() and compare())
nette/php-generator suggests installing nikic/php-parser (to use ClassType::withBodiesFrom() & GlobalFunction::withBodyFrom())
Writing lock file
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
File /var/www/html/swoole/config/trace.php exist!
Succeed!

ok 安装成功了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值