前情提要
这里主要记录一下一些基本操作记录
这里我们使用宝塔面板安装,我们需要从软件商店中准备如下工具
- Nginx
- PHP8 + Swoole4
- Supervisor 管理器 2.2
- iterm2
拉取代码
我们这里用的是 coding
| cd /www/wwwroot |
| git clone git@e.coding.net:dotdotbear/kwh/project.git |
| cd project |
| |
| |
| composer config -g repo.packagist composer https://mirrors.aliyun.com/composer |
| |
| composer install -vvv |
| |
| composer install -vvv --ignore-platform-reqs |
| |
| |
| |
| |
| |
| cp .env.example .env |
Supervisord 安装与配置
基本上,在宝塔中已经提供了基础的 Supervisord 服务。可以直接使用它
常用命令
- supervisorctl status // [当前运行服务状态]
- supervisorctl stop service_name // [停止服务]
- supervisorctl start service_name // [启动服务]
- supervisorctl restart service_name // [重启服务]
- supervisorctl reload // [重载配置文件并重启]
- supervisorctl reread // [读取当前运行配置和 program 配置文件的差异]
- supervisorctl update // [重载配置文件并重启]
启动配置
| [program:hyperf] |
| command=/www/server/php/80/bin/php bin/hyperf.php start |
| directory=/www/wwwroot/hyperf-project/ |
| autorestart=true |
| startsecs=3 |
| startretries=3 |
| stdout_logfile=/www/server/panel/plugin/supervisor/log/hyperf.out.log |
| stderr_logfile=/www/server/panel/plugin/supervisor/log/hyperf.err.log |
| stdout_logfile_maxbytes=2MB |
| stderr_logfile_maxbytes=2MB |
| user=root |
| priority=999 |
| numprocs=1 |
| process_name=%(program_name)s_%(process_num)02d |
Hyperf 常用函数
获取 Driver 队列
| |
| |
| |
| |
| public static function getDriver($driver = 'default') |
| { |
| return ApplicationContext::getContainer()->get(DriverFactory::class)->get($driver); |
| } |
获取 Logger 实例
| |
| |
| |
| |
| |
| |
| public static function get(string $name = 'default'): LoggerInterface |
| { |
| return ApplicationContext::getContainer()->get(LoggerFactory::class)->get($name, $name); |
| } |
获取 Redis 实例
| public static function get($app = 'default') |
| { |
| $container = ApplicationContext::getContainer(); |
| $redis = $container->get(RedisFactory::class)->get($app); |
| return $redis; |
| } |
其他问题
如何修改宝塔默认 PHP 版本
ln -sf /www/server/php/74/bin/php /usr/bin/php
putenv() has been disabled for security reasons
进入 php 管理界面,打开禁用函数, 删除即可
或者进入对应 php 版本,查看 disable_functions
版本问题 ?
安装 PHP8 且 安装 > Swoole4
可以使用自定义 php 版本执行
| /www/server/php/74/bin/php bin/hyperf.php start |
| /www/server/php/80/bin/php bin/hyperf.php start |
composer 问题 ?
| |
| composer install -vvv |
| |
| |
| omposer install -vvv --ignore-platform-reqs |
| |
| |
| composer dump |
swoole 问题 ?
- php.ini 配置
- swoole.use_shortname = ‘Off’
参考文章