centos7怎么搭建swoole_http_server 已经安装了php输入yum install php-swoole提示No package php-swoole available
如果输入yum install php-swoole提示No package php-swoole available,则说明当前yum源中没有php-swoole的安装包,需要手动安装swoole。
安装swoole的步骤如下:
- 安装epel源:
yum install epel-release
- 安装swoole依赖:
yum install gcc gcc-c++ autoconf automake libtool make
- 下载swoole源码:
wget https://github.com/swoole/swoole-src/archive/master.zip
- 解压源码:
unzip master.zip
cd swoole-src-master
- 编译安装:
phpize
./configure
make
make install
- 修改php.ini文件,添加swoole扩展:
extension=swoole.so
- 重启php-fpm服务:
service php-fpm restart
- 编写swoole_http_server代码:
<?php
$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->on("start", function ($server) {
echo "Swoole http server is started at http://0.0.0.0:9501\n";
});
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
$http->start();
- 运行swoole_http_server:
php your_file_name.php
- 访问http://ip:9501即可看到Hello World的输出。
原文地址: https://www.cveoy.top/t/topic/bunA 著作权归作者所有。请勿转载和采集!