WSL下Ubuntu18 搭建Swoole运行环境

改编自:https://www.cq8912.cn/archives/139.html

0. apt换源

sudo passwd root

su root

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak && sudo vim /etc/apt/sources.list

apt update && apt upgrade

 

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

 

1. 安装基本的php及扩展


apt-get install php7.2 php7.2-curl php7.2-gd php7.2-gmp php7.2-json php7.2-mysql php7.2-opcache php7.2-readline php7.2-sqlite3 php7.2-tidy php7.2-xml php7.2-bcmath php7.2-bz2 php7.2-intl php7.2-mbstring php7.2-mcrypt php7.2-soap php7.2-xsl php7.2-zip
//失败则用:sudo apt install php7.2 php7.2-curl php7.2-gd php7.2-json php7.2-mysql php7.2-opcache php7.2-dev php-pear

其中:
* php-gmp(会自动安装) : 是一个数学扩展,“These functions allow for arbitrary-length integers to be worked with using the GNU MP library” 提供了一组方法,可以(通过GUN MP库)用来处理任意长度的integers
* php-readline(会自动安装) : 实现了访问 GNU Readline 库的接口. 这些函数提供了可编辑的命令行
* php-pear : 通过pecl安装swoole时要用到
* php-dev : 使用phpize来扩展php模块(即swoole)时用到

2. 安装swoole相关依赖

若不需要打开swoole这些模块,则不需要安装依赖依赖

sudo apt install libhiredis-dev

如果需要支持http2,需要安装nghhtp2,apt/源码安装各试了几次,编译swoole时遇到一些坑,暂时用不到先放着。

3.下载并安装swoole

   1)pecl install swoole
   echo 'extension=swoole.so' >> /etc/php/7.2/mods-available/swoole.ini
   cd /etc/php/7.2/cli/conf.d/ && ln -s ../../mods-available/swoole.ini 20-swoole.ini
   //cd /etc/php/7.2/fpm/conf.d/ && ln -s ../../mods-available/swoole.ini 20-swoole.ini


2)编译参考官方文档

根据官方文档,特别注意:
  • BashOnWindows 环境下必须关闭 daemonize 选项
  • 低于17101WSL,源码安装configure后需要修改 config.h 关闭 HAVE_SIGNALFD
 关闭 HAVE_SIGNALFD
vim config.h
//找到HAVE_SIGNALFD,注释掉,改成0还是最终运行时还是会报错【但是不影响执行】.根据其他博客中的说法:在第二步解压tgz文件后,修改config.m4文件也可以【直接删除HAVE_SIGNALFD一行即可】
/* have signalfd */
/*#define HAVE_SIGNALFD 1*/

其它扩展

pecl install redis
echo 'extension=redis.so' >> /etc/php/7.2/mods-available/redis.ini
cd /etc/php/7.2/cli/conf.d/ && ln -s ../../mods-available/redis.ini 20-redis.ini

 

最后,php -m查看已经安装成功

posted @ 2019-09-25 11:40  luckc#  阅读(829)  评论(0编辑  收藏  举报