当前位置: 首页 > 工具软件 > CatchAdmin > 使用案例 >

CatchAdmin实战教程(二) 安装与更新

乐正涵忍
2023-12-01

CatchAdmin框架为前后端分离架构,安装一共分为两部分:后端安装、前端安装;后台接口直接访问则无效,需要借助常见的API测试工具(ApiPostPostmanApiFox)进行接口测试。

环境要求

  • PHP >= 7.2.*

  • Mysql >= 5.7.0

  • PDO Extension

  • MBstring Extension

  • CURL Extension

  • ZIP Extension

  • Composer

后端安装

友情提示: 以下操作无论是 Composer扩展操作还是 php think xx操作 或者 yarm xx操作都是在其根目录下操作的。

Composer安装

安装 CatchAdmin 需确保安装 Composer ,已安装请忽略该步骤。

强烈推荐参考: Composer安装手册

## 快捷方式安装如下:
# 1.下载 Composer 安装包
curl -sS https://install.phpcomposer.com/installer | php

Git方式下载(推荐)

# 1.git拉取 CatchAdmin代码
git clone https://gitee.com/jaguarjack/catchAdmin && cd catchAdmin

# 2.配置 Composer 阿里云源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 3.Composer安装扩展 
composer install --ignore-platform-reqs

Composer方式下载

# Composer下载CatchAdmin代码
composer create-project jaguarjack/catchadmin:dev-master catchAdmin

安装CatchAdmin

php think catch:install 

  • 安装过程
D:\phpstudy_pro\WWW\PHPProject\MyProject\catchAdmin>php think catch:install
environment begin to check...
php version 7.4.3
mbstring extension is installed
json extension is installed
openssl extension is installed
pdo extension is installed
xml extension is installed
 environment checking finished
 # 设置应用地址
  first, you should set app domain: :
 > 192.168.1.99:9090

# 是否设置数据库信息
  Did You Need to Set Database information? (Y/N): :
 > Y

# 设置数据库编码格式:不填默认(utf8mb4)
  please input database charset, default (utf8mb4)::
 >
# 设置数据库名
  please input database name: :
 > catchadmins
# 设置数据库连接IP
  please input database host, default (127.0.0.1)::
 >
# 设置数据库连接端口
  please input database host port, default (3306)::
 >
# 设置数据库表前缀
  please input table prefix, default (null)::
 > catch_

# 设置数据库用户名
  please input database username default (root): :
 > root

# 设置数据库密码
  please input database password: :
 > root

 create database catchadmins successfully
 module [permissions] installed successfully
 module [system] installed successfully
 project is installed, welcome!

 /-------------------- welcome to use -------------------------\
|               __       __       ___       __          _      |
|   _________ _/ /______/ /_     /   | ____/ /___ ___  (_)___  |
|  / ___/ __ `/ __/ ___/ __ \   / /| |/ __  / __ `__ \/ / __ \ |
| / /__/ /_/ / /_/ /__/ / / /  / ___ / /_/ / / / / / / / / / / |
| \___/\__,_/\__/\___/_/ /_/  /_/  |_\__,_/_/ /_/ /_/_/_/ /_/  |
|                                                              |
 \ __ __ __ __ _ __ _ __ enjoy it ! _ __ __ __ __ __ __ ___ _ @ 2017 ~ 2021
 版本: 2.6.0
 初始账号: catch@admin.com
 初始密码: catchadmin

启动后台

# 默认端口:80
php think run 

# 指定端口请使用
php think run -p 端口号

# windows环境下示范:
> php think run -p 9090
ThinkPHP Development server is started On <http://127.0.0.1:9090/>
You can exit with `CTRL-C`

# 友情提醒:在开发环境下,为了方便前端测试,在不同本机的情况,请使用本机的IP:port,否则对方无法访问;
# 同机上测试可以使用127.0.0.1:端口,不推荐!

env配置

# 复制.example.env 一份命名 .env
# 最新版会自动生成该.env文件
APP_DEBUG = false  #应用debug模式

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai   #配置时区
DOMAIN = http://192.168.1.99:9090  #配置后台API地址

# 配置数据库
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = catchadmins
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8mb4
DEBUG = true
PREFIX = catch_

[LANG]
default_lang = zh-cn


[JWT]
SECRET=5afa097ade8316485c6dd44ca64d08d6

初始化后台

php think catch:install -r

前端的安装

前端主要由 vue-element-admin搭建,搭建之前请了解Vue如何部署环境以及教程

配置yarm源

# 由于外网访问速度受限,往往会失败,因此采用国内淘宝源
yarn config set registry https://registry.npm.taobao.org/

下载项目

git clone https://github.com/yanwenwu/catch-admin-vue.git

配置开发模式

# 文件名:.env.development
# just a flag
ENV = 'development'

# base api :为后台配置的地址
VUE_APP_BASE_API = 'http://192.168.1.99:9090'

安装项目

yarn install

项目启动

npm run dev
  • 启动过程
> npm run dev

> vue-element-admin@4.4.0 dev D:\phpstudy_pro\WWW\CompanyProject\Codes\Web\server
> vue-cli-service serve

 INFO  Starting development server...
98% after emitting CopyPlugin

 DONE  Compiled successfully in 11042ms                                                                                                                                                                             下午4:48:50


  App running at:
  - Local:   http://localhost:9527/
  - Network: http://192.168.1.99:9527/

  Note that the development build is not optimized.
  To create a production build, run yarn build.

 类似资料: