学习路之PHP--webman安装及使用、webman/admin安装
- 一、安装webman
- 二、运行
- 三、安装webman/admin
- 四、效果
- 五、配置Nginx反向代理(生产环境:可选)
- 六、win10运行问题集
- 七、使用
一、安装webman
- 准备:
PHP >= 8.1
Composer >= 2.0
CentOS 7
启用函数:
putenv
proc_open
pcntl_signal_dispatch
pcntl_signal
pcntl_alarm
pcntl_fork
pcntl_wait
shell_exec
exec
- 安装命令
composer create-project workerman/webman:~2.0
二、运行
php start.php start
浏览器访问 http://ip地址:8787
三、安装webman/admin
- 安装扩展
fileinfo - 运行安装
如果是webman是1.x版本执行 composer require -W webman/admin ~1.0
如果是webman是2.x版本执行 composer require -W webman/admin ~2.0
- 访问
http://127.0.0.1:8787/app/admin/ 完成数据库相关配置
四、效果
五、配置Nginx反向代理(生产环境:可选)
- 新建一个站点,php版本选择纯净态即可,反正都是用不上的,域名填写你申请得到的域名,
- 设置伪静态
# 将请求转发到webmanlocation ^~ / {proxy_set_header Host $http_host;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_http_version 1.1;proxy_set_header Connection "";if (!-f $request_filename){proxy_pass http://127.0.0.1:8787;}}# 拒绝访问所有以 .php 结尾的文件location ~ \.php$ {return 404;}# 允许访问 .well-known 目录location ~ ^/\.well-known/ {allow all;}# 拒绝访问所有以 . 开头的文件或目录location ~ /\. {return 404;}
- 启动项目
推荐使用宝塔面板的进程守护管理器,其实就是用supervisord管理后台进程,或者加-d使用默认的守护进程
- 反向代理(可选,做伪静态了不用反向代理) 我没有做反向代理
在你新建的网站下,点击设置,然后添加反向代理,目标URL填写你的webman地址和端口即可
- 效果:
六、win10运行问题集
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.1.0”. You are running 7.4.3. in D:\phpstudy_pro\WWW\webman\webman2.0\vendor\composer\platform_check.php on line 24
解决:php需要8.1。我直接在phpstudy安装了8.2,然后修改根目录\windows.bat
CHCP 65001
D:\phpstudy_pro\Extensions\php\php8.2.9nts\php windows.php
pause
- PHP Warning: ‘C:\windows\SYSTEM32\VCRUNTIME140.dll’ 14.0 is not compatible with this PHP build linked with 14.29 in Unknown on line 0
解决:安装匹配的VC++运行库
https://aka.ms/vs/17/release/vc_redist.x64.exe # 64位系统
https://aka.ms/vs/17/release/vc_redist.x86.exe # 32位系统
- Fatal error: Directive ‘track_errors’ is no longer available in PHP in Unknown on line 0
解决:D:\phpstudy_pro\Extensions\php\php8.2.9nts\php.ini
track_errors=Off
七、使用
- 忘记密码之处理方法
plugin\admin\app\controller\AccountController.php 61行
public function login(Request $request): Response{$this->checkDatabaseAvailable();$captcha = $request->post('captcha', '');if (strtolower($captcha) !== session('captcha-login')) {return $this->json(1, '验证码错误');}$request->session()->forget('captcha-login');$username = $request->post('username', '');$password = $request->post('password', '');// return $this->json(1,password_hash($password, PASSWORD_DEFAULT));//忘记密码之处理方法:直接输出密码密文
- 简化验证码
plugin\admin\app\controller\AccountController.php 196行
public function captcha(Request $request, string $type = 'login'): Response{$builder = new PhraseBuilder(4, '2345678');//abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ //简化验证码