1. 安装php swoole 宇润 / PHP 环境一把梭安装工具集
// 安装php | |
$ wget https://gitee.com/yurunsoft/php-env/raw/master/apt-php.sh && bash apt-php.sh// 安装 redis 扩展 | |
$ wget https://gitee.com/yurunsoft/php-env/raw/master/php-redis.sh && bash php-redis.sh// 安装 composer | |
$ wget https://gitee.com/yurunsoft/php-env/raw/master/composer.sh && bash composer.sh// 安装 swoole | |
$ wget https://gitee.com/yurunsoft/php-env/raw/master/install-swoole.sh && bash install-swoole.shco// 查看php.ini文件 添加 swoole.use_shortname="off" | |
$ php --ini | |
// 报错 4核8G 1. 解决方法 https://wenda.swoole.com/detail/1072722. 编译时选择no | |
g++: fatal error: Killed signal terminated program cc1plus | |
compilation terminated. | |
make: *** [Makefile:204: ext-src/swoole_client_coro.lo] Error 1 | |
g++: fatal error: Killed signal terminated program cc1plus | |
compilation terminated. | |
make: *** [Makefile:192: ext-src/php_swoole.lo] Error 1 | |
g++: fatal error: Killed signal terminated program cc1plus | |
compilation terminated.// 查看php /composer/ swoole是否安装成功 | |
$ php -v | |
$ composer -v | |
$ php --ri swoole | |
swoole | |
Swoole => enabledAuthor => Swoole Team <team .com> | |
Version => 4.6.7 | |
Built => May 28 2021 17:15:13 | |
coroutine => enabled with boost asm contextepoll => enabledeventfd => enabledsignalfd => enabledcpu_affinity => enabledspinlock => enabledrwlock => enabledopenssl => OpenSSL 1.1.1f 31 Mar 2020 | |
dtls => enabledhttp2 => enabledpcre => enabledzlib => 1.2.11 | |
mutex_timedlock => enabledpthread_barrier => enabledfutex => enabledmysqlnd => enabledasync_redis => enabled | |
Directive => Local Value => Master Value | |
swoole.enable_coroutine => On => On | |
swoole.enable_library => On => On | |
swoole.enable_preemptive_scheduler => Off => Off | |
swoole.display_errors => On => On | |
swoole.use_shortname => Off => Off | |
swoole.unixsock_buffer_size => 8388608 => 8388608 |
2. 安装hyperf
composer create-project hyperf/hyperf-skeleton hyperf | |
composer update -o |
3. 安装supervisor
$ sudo apt-get install -y supervisor | |
// 返回如下 需要更新: | |
Reading package lists... Done | |
Building dependency tree | |
Reading state information... Done | |
E: Unable to locate package supervisor | |
// 更新 | |
$ sudo apt-get update | |
// 生成默认配置文件 | |
$ echo_supervisord_conf > /etc/supervisord.conf | |
// 搜索原配置 | |
;[include] | |
;files = relative/directory/*.ini | |
// 修改如下 如无文件 自行创建 | |
[include] | |
files = etc/supervisor/conf.d/*.conf | |
// 使用默认文件启动supervisor | |
$ supervisord -c /etc/supervisord.conf | |
// 添加配置[program:hyperf] | |
process_name=%(program_name)s_%(process_num)02d | |
command=php /var/www/hyperf/bin/hyperf.php start | |
autostart=true | |
autorestart=true | |
user=root | |
startsecs=10 | |
startretries=3 | |
redirect_stderr=true | |
stdout_logfile=/tmp/hyperf.error.log | |
// 查看所有进程的状态 | |
$ supervisorctl status | |
// 重新启动配置中的所有程序 | |
$ sudo supervisorctl reread | |
// 配置文件修改后使用该命令加载新的配置 | |
$ sudo supervisorctl update | |
// 启动服务 | |
$ sudo supervisorctl start hyperf:* | |
// 停止服务 | |
$ supervisorctl stop hyperf:* | |