Ubuntu hyperf 部署記錄

莫名私下裡發表於2021-05-28

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/107272
 2. 編譯時選擇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 => enabled
    Author => Swoole Team <team@swoole.com>
    Version => 4.6.7
    Built => May 28 2021 17:15:13
    coroutine => enabled with boost asm context
    epoll => enabled
    eventfd => enabled
    signalfd => enabled
    cpu_affinity => enabled
    spinlock => enabled
    rwlock => enabled
    openssl => OpenSSL 1.1.1f  31 Mar 2020
    dtls => enabled
    http2 => enabled
    pcre => enabled
    zlib => 1.2.11
    mutex_timedlock => enabled
    pthread_barrier => enabled
    futex => enabled
    mysqlnd => enabled
    async_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:*
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章