2020-10-24 20:46:14 +08:00
|
|
|
?> 如果仅是体验该项目, 请访问演示站点[hyperf-admin](http://hyperf-admin.daodao.run/)
|
2020-07-06 17:30:07 +08:00
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
## 前端的安装
|
2020-06-16 22:33:55 +08:00
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 环境依赖
|
|
|
|
|
# 1. node ^v11.2.0 https://nodejs.org/zh-cn/download/
|
|
|
|
|
# 2. npm ^6.4.1
|
2020-06-17 07:49:45 +08:00
|
|
|
git clone https://github.com/hyperf-admin/hyperf-admin-frontend.git
|
2020-06-17 08:54:59 +08:00
|
|
|
cd hyperf-admin-frontend
|
2020-06-16 22:33:55 +08:00
|
|
|
npm i
|
|
|
|
|
npm run dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
!> 请根据实际情况修改`vue.config.js`中的代理 `proxy.target`地址
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 打包
|
|
|
|
|
npm run build:prod
|
|
|
|
|
npm run build:test
|
|
|
|
|
```
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
## 后端的安装
|
2020-06-16 22:33:55 +08:00
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
#### 1. 初始化一个`hypef`项目
|
2020-06-16 22:33:55 +08:00
|
|
|
```shell
|
2020-08-10 11:55:02 +08:00
|
|
|
# 环境依赖 php ^7.2 composer swoole
|
2020-06-17 07:49:45 +08:00
|
|
|
composer create-project hyperf/hyperf-skeleton hyperf-admin
|
|
|
|
|
cd hyperf-admin
|
2020-10-24 20:46:14 +08:00
|
|
|
```
|
2020-06-23 20:35:50 +08:00
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
#### 2. 移除`hyperf-skeleton`中的日志配置, 因为 `admin` 底层已配置
|
2021-02-05 18:04:28 +08:00
|
|
|
|
|
|
|
|
底层的日志配置见 [base-utils/ConfigProvider](https://github.com/hyperf-admin/hyperf-admin/blob/master/src/base-utils/src/ConfigProvider.php#L22)
|
2020-10-24 20:46:14 +08:00
|
|
|
```shell
|
|
|
|
|
rm config/autoload/logger.php
|
2020-06-16 22:33:55 +08:00
|
|
|
```
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
#### 3. 安装`hyperf-admin`的依赖DB信息
|
|
|
|
|
|
|
|
|
|
!> hyperf-admin 为分包的模式, 此处引入的是完整仓库, 实际项目请按需引入
|
|
|
|
|
|
|
|
|
|
全部的`mysql` 表结构及及基础数据详见 [demo/db](https://github.com/hyperf-admin/hyperf-admin-demo/tree/master/docker/db)
|
|
|
|
|
|
|
|
|
|
#### 4. 修改项目`.env`
|
|
|
|
|
```shell
|
2020-06-19 06:03:04 +08:00
|
|
|
APP_NAME=hyperf-admin
|
|
|
|
|
ENV=dev
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
# Redis链接信息
|
2020-06-19 06:03:04 +08:00
|
|
|
REDIS_HOST=localhost
|
|
|
|
|
REDIS_AUTH=(null)
|
|
|
|
|
REDIS_PORT=6379
|
|
|
|
|
REDIS_DB=0
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
# hyperf-admin 依赖的核心db
|
2020-06-19 06:03:04 +08:00
|
|
|
HYPERF_ADMIN_DB_HOST=localhost
|
|
|
|
|
HYPERF_ADMIN_DB_PORT=3306
|
|
|
|
|
HYPERF_ADMIN_DB_NAME=hyperf_admin
|
|
|
|
|
HYPERF_ADMIN_DB_USER=root
|
|
|
|
|
HYPERF_ADMIN_DB_PWD=root
|
|
|
|
|
|
|
|
|
|
LOCAL_DB_HOST=localhost
|
|
|
|
|
```
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
#### 5. 安装`hyperf-admin`扩展包
|
|
|
|
|
```shell
|
|
|
|
|
composer require hyperf-admin/hyperf-admin
|
|
|
|
|
```
|
2021-01-28 14:52:02 +08:00
|
|
|
|
|
|
|
|
如果存在依赖包的版本号问题, 注意, 请使用 composer2
|
|
|
|
|
```shell
|
|
|
|
|
composer require hyperf-admin/hyperf-admin:0.2.0 --with-all-dependencies
|
|
|
|
|
```
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
!> hyperf-admin 为分包模式, 实际应用中请根据情况安装
|
|
|
|
|
|
|
|
|
|
#### 6. 初始化`validation`的依赖文档
|
|
|
|
|
```shell
|
|
|
|
|
php bin/hyperf.php vendor:publish hyperf/translation
|
|
|
|
|
php bin/hyperf.php vendor:publish hyperf/validation
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 7. 设置用户密码的加密`key`, 配置节点`password.salt`
|
|
|
|
|
```shell
|
2020-06-23 20:35:50 +08:00
|
|
|
// config/config.php
|
|
|
|
|
|
|
|
|
|
'password' => [
|
2020-08-10 11:55:02 +08:00
|
|
|
'salt' => env('HYPERF_ADMIN_PWD_SALT', 'c093d70f088499c3a837cae00c042f14'), // 用 md5(time()) 获取 salt
|
2021-02-04 11:22:47 +08:00
|
|
|
]
|
2020-10-24 20:46:14 +08:00
|
|
|
```
|
2020-06-23 20:35:50 +08:00
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
#### 8. 启动
|
|
|
|
|
```shell
|
|
|
|
|
# 启动 热重启参考 https://github.com/daodao97/hyperf-watch
|
|
|
|
|
composer watch
|
2020-06-23 20:35:50 +08:00
|
|
|
```
|
|
|
|
|
|
2021-02-04 11:22:47 +08:00
|
|
|
## 生产环境nginx配置
|
2020-06-16 22:33:55 +08:00
|
|
|
|
|
|
|
|
```nginx
|
2020-06-17 07:49:45 +08:00
|
|
|
upstream backend {
|
|
|
|
|
server 127.0.0.1:9511;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
2020-08-10 11:55:02 +08:00
|
|
|
server_name hyperf-admin.com; # 设置自己的 domain
|
2020-06-17 07:49:45 +08:00
|
|
|
index index.html;
|
2020-06-17 16:15:51 +08:00
|
|
|
root /opt/www/hyperf-admin-front/dist;
|
2020-06-17 07:49:45 +08:00
|
|
|
access_log /usr/local/var/log/nginx/hyperf-admin.access.log;
|
|
|
|
|
error_log /usr/local/var/log/nginx/hyperf-admin.error.log;
|
|
|
|
|
|
|
|
|
|
location ~ /api/(.*) {
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Connection "keep-alive";
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header Host hyperf-admin.com;
|
|
|
|
|
proxy_pass http://backend/$1$is_args$args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location / {
|
2020-06-17 16:15:51 +08:00
|
|
|
root /opt/www/hyperf-admin-front/dist/default;
|
2020-06-17 07:49:45 +08:00
|
|
|
index index.html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location ~ /(.*) {
|
|
|
|
|
set $module $1;
|
|
|
|
|
if ($module ~* '^$') {
|
|
|
|
|
set $module default;
|
|
|
|
|
}
|
|
|
|
|
try_files $uri $uri/ /$module/index.html;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-16 22:33:55 +08:00
|
|
|
```
|
2020-07-06 17:30:07 +08:00
|
|
|
|
|
|
|
|
浏览器打开 [http://youdomain.com:8081/default/#/dashboard](http://youdomain.com:8081/default/#/dashboard) 即可访问
|
|
|
|
|
|
2020-10-24 20:46:14 +08:00
|
|
|
默认账号 `daodao`, 密码 `a1a1a1`
|