學習路之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 //簡化驗證碼