Linux centos 安装Workerman 重启

一、安装  官方手册

http://doc.workerman.net/315116

Linux centos 安装Workerman 重启_第1张图片

 

1.1、 安装错误:

 WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update

Linux centos 安装Workerman 重启_第2张图片

解决办法:

pecl channel-update pecl.php.net

参考:https://blog.csdn.net/guo_qiangqiang/article/details/103586000

1.2 错误:

Warning: popen() has been disabled for security reasons in OS/Guess.php

警告:出于安全原因,popen()已经在OS/Guess.php中被禁用

Warning: popen() has been disabled for security reasons in OS/Guess.php on line 241
PHP Warning:  popen() has been disabled for security reasons in /www/server/php/56/lib/php/OS/Guess.php on line 241

Warning: popen() has been disabled for security reasons in /www/server/php/56/lib/php/OS/Guess.php on line 241

Warning: fgets() expects parameter 1 to be resource, null given in OS/Guess.php on line 242
PHP Warning:  fgets() expects parameter 1 to be resource, null given in /www/server/php/56/lib/php/OS/Guess.php on line 242

Warning: fgets() expects parameter 1 to be resource, null given in /www/server/php/56/lib/php/OS/Guess.php on line 242

Warning: pclose() expects parameter 1 to be resource, null given in OS/Guess.php on line 251
PHP Warning:  pclose() expects parameter 1 to be resource, null given in /www/server/php/56/lib/php/OS/Guess.php on line 251

Warning: pclose() expects parameter 1 to be resource, null given in /www/server/php/56/lib/php/OS/Guess.php on line 251

Warning: readlink() has been disabled for security reasons in OS/Guess.php on line 257
PHP Warning:  readlink() has been disabled for security reasons in /www/server/php/56/lib/php/OS/Guess.php on line 257

Warning: readlink() has been disabled for security reasons in /www/server/php/56/lib/php/OS/Guess.php on line 257
downloading event-2.5.6.tgz ...
Starting to download event-2.5.6.tgz (141,226 bytes)
..............................done: 141,226 bytes
50 source files, building

Warning: putenv() has been disabled for security reasons in PEAR/Builder.php on line 310
PHP Warning:  putenv() has been disabled for security reasons in /www/server/php/56/lib/php/PEAR/Builder.php on line 310

Warning: putenv() has been disabled for security reasons in /www/server/php/56/lib/php/PEAR/Builder.php on line 310
running: phpize

Warning: popen() has been disabled for security reasons in PEAR/Builder.php on line 465
PHP Warning:  popen() has been disabled for security reasons in /www/server/php/56/lib/php/PEAR/Builder.php on line 465

Warning: popen() has been disabled for security reasons in /www/server/php/56/lib/php/PEAR/Builder.php on line 465
ERROR: failed to run `phpize'

解决办法:

popen readlink putenv三个函数在php.ini里将popen函数禁用了

Linux centos 安装Workerman 重启_第3张图片

Linux centos 安装Workerman 重启_第4张图片

或者在这里添加

Linux centos 安装Workerman 重启_第5张图片

disable_functions中去掉对应三个函数,重启服务

Linux centos 安装Workerman 重启_第6张图片

参考:https://www.cnblogs.com/lxhyty/p/11237433.html

 

1.3 继续安装 pecl install event (重点关注1.2.3地方输入的值

Linux centos 安装Workerman 重启_第7张图片

三个地方按上面来操作

Linux centos 安装Workerman 重启_第8张图片

 

二 安装Event扩展

 

注意目前libevent扩展不支持php7,php7用户只能使用Event扩展。Linux centos 安装Workerman 重启_第9张图片

 

yum install libevent-devel
pecl install channel://pecl.php.net/libevent-0.1.0 //提示libevent installation [autodetect]: 时按回车
echo extension=libevent.so > /etc/php.d/libevent.ini

Linux centos 安装Workerman 重启_第10张图片

 

四、测试是否成功




    
    
    Title




注意:每次修改Workerman,都要重新启动

Linux centos 安装Workerman 重启_第11张图片Linux centos 安装Workerman 重启_第12张图片

 

五、Workerman TP5 php代码测试启动

要启动Workerman,首先需要有一个启动入口文件,里面定义了服务监听的端口及协议。

可以参考入门指引--简单开发实例部分

这里以我们自己的项目为例,它的启动入口为server.php。

server.php文件是自己写的php文件,路径放到项目中,

Linux centos 安装Workerman 重启_第13张图片

进入项目根目录后再命令启动

宝塔操作方法:

Linux centos 安装Workerman 重启_第14张图片

Linux centos 安装Workerman 重启_第15张图片

启动

以debug(调试)方式启动

php server.php start

以daemon(守护进程)方式启动

php server.php start -d

停止

php server.php stop

重启

php start.php restart

平滑重启

php server.php reload

查看状态

php server.php status

 

4.1 错误:pcntl_fork() has been disabled for security reasons in file 

由于安全原因,pcntl_fork()在第1515行文件/xxxxxx/vendor/workerman/workerman/Worker.php中被禁用

Linux centos 安装Workerman 重启_第16张图片

Linux centos 安装Workerman 重启_第17张图片

 

四、给Workerman 配置SSL证书,就是域名那个SSL证书

 

创建wss服务
问:

Workerman如何创建一个wss服务,使得客户端可以用过wss协来连接通讯,比如在微信小程序中连接服务端。

答:

wss协议实际是websocket+SSL,就是在websocket协议上加入SSL层,类似https(http+SSL)。 所以只需要在websocket协议的基础上开启SSL即可支持wss协议。

方法一 ,直接用Workerman开启SSL
准备工作:

1、Workerman版本不小于3.3.7

2、PHP安装了openssl扩展

3、已经申请了证书(pem/crt文件及key文件)放在磁盘任意目录

代码:

 array(
        // 请使用绝对路径
        'local_cert'                 => '磁盘路径/server.pem', // 也可以是crt文件
        'local_pk'                   => '磁盘路径/server.key',
        'verify_peer'                => false,
        // 'allow_self_signed' => true, //如果是自签名证书需要开启此选项
    )
);
// 这里设置的是websocket协议(端口任意,但是需要保证没被其它程序占用)
$worker = new Worker('websocket://0.0.0.0:443', $context);
// 设置transport开启ssl,websocket+ssl即wss
$worker->transport = 'ssl';
$worker->onMessage = function($con, $msg) {
    $con->send('ok');
};

Worker::runAll();

参考:http://doc.workerman.net/faq/secure-websocket-server.html

在代码中配置对应SSL证书的路径:宝塔SSL证书路径/www/server/panel/vhost/ssl/www.xxx.com/

Linux centos 安装Workerman 重启_第18张图片

 

你可能感兴趣的:(宝塔,linux系统,thinkphp5)