# apiadmin **Repository Path**: xuebusi/apiadmin ## Basic Information - **Project Name**: apiadmin - **Description**: 从https://gitee.com/apiadmin/ApiAdmin克隆过来自己学习的php服务端项目 - **Primary Language**: PHP - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2018-12-29 - **Last Updated**: 2021-02-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 从 https://gitee.com/apiadmin/ApiAdmin 克隆过来自己学习的php服务端项目 该项目是服务端项目(前后端分离),对应的前端项目: https://gitee.com/apiadmin/ApiAdmin-WEB #### 我已经将ApiAdmin和ApiAdmin-WEB这两个项目的zip包放到了zip目录下面。 ### 项目部署环境[以我的mac操作系统在本地部署为例]: ``` Apache + php + mysql Mac电脑默认的apache网站根目录是 /Library/WebServer/Documents,将ApiAdmin项目直接通过git克隆到该目录即可. ``` #### mac操作系统Apache版本: ``` B000000067100V:~ v_shiyanjun$ apachectl -v Server version: Apache/2.4.33 (Unix) Server built: Apr 3 2018 23:45:11 ``` #### mac操作系统php版本: ``` B000000067100V:~ v_shiyanjun$ php -v PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0 PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies ``` #### mac系统将项目放到如下目录: ``` B000000067100V:~ v_shiyanjun$ cd /Library/WebServer/Documents/ B000000067100V:Documents v_shiyanjun$ pwd /Library/WebServer/Documents B000000067100V:Documents v_shiyanjun$ ls -ll total 19184 drwxrwxrwx 18 root wheel 576 12 29 11:11 ApiAdmin ``` #### 数据库和redis ``` 在MySQL数据库中创建名为apiadmin_new的数据库,然后执行data/apiadmin_3.0.8.sql脚本来创建表并初始化数据. 修改application/database.php中的数据库配置信息. ``` ### 测试登录接口: ``` 请求URL[不要直接在浏览器地址栏中测试该接口,必须是POST请求]: http://localhost/apiadmin/public/index.php/admin/login/index 请求方式: POST 请求头: Content-Type=application/json;charset=UTF-8 请求参数: { "username": "root", "password": "123456" } 返回成功结果: { "code": 1, "msg": "登录成功", "data": { "headImg": "", "access": [ "admin/Login/index", "admin/Login/logout", "admin/Menu/changeStatus", "admin/Menu/add", "admin/Menu/edit", "admin/Menu/del", "admin/User/getUsers", "admin/User/changeStatus", "admin/User/add", "admin/User/edit", "admin/User/del", "admin/Auth/changeStatus", "admin/Auth/delMember", "admin/Auth/add", "admin/Auth/edit", "admin/Auth/del", "admin/Auth/getGroups", "admin/Auth/getRuleList", "admin/App/changeStatus", "admin/App/getAppInfo", "admin/App/add", "admin/App/edit", "admin/App/del", "admin/InterfaceList/changeStatus", "admin/InterfaceList/getHash", "admin/InterfaceList/add", "admin/InterfaceList/edit", "admin/InterfaceList/del", "admin/Fields/request", "admin/Fields/response", "admin/Fields/add", "admin/Fields/upload", "admin/Fields/edit", "admin/Fields/del", "admin/InterfaceGroup/add", "admin/InterfaceGroup/edit", "admin/InterfaceGroup/del", "admin/InterfaceGroup/getAll", "admin/InterfaceGroup/changeStatus", "admin/AppGroup/add", "admin/AppGroup/edit", "admin/AppGroup/del", "admin/AppGroup/getAll", "admin/AppGroup/changeStatus", "admin/Menu/index", "admin/User/index", "admin/Auth/index", "admin/App/index", "admin/AppGroup/index", "admin/InterfaceList/index", "admin/InterfaceGroup/index", "admin/Log/index", "admin/Log/del", "admin/InterfaceList/refresh", "admin/Index/upload", "admin/User/own", "admin/App/refreshAppSecret" ], "id": 1, "username": "root", "nickname": "root", "apiAuth": "dc60e1d226267be57ea2b6ce8e3f147b" } } 返回错误结果: { "code": -7, "msg": "用户名密码不正确", "data": [] } ``` ### 对应的前端项目部署 #### 前端项目地址 ``` https://gitee.com/apiadmin/ApiAdmin-WEB.git 将前端项目ApiAdmin-WEB克隆到本地任意目录。 ``` #### 统一环境 ``` B000000067100V:ApiAdmin-WEB v_shiyanjun$ node -v v8.9.4 B000000067100V:ApiAdmin-WEB v_shiyanjun$ npm -v 5.6.0 ``` #### 修改config.js ``` 将build/config.js中的baseUrl的值改成http://localhost/apiadmin/public/index.php/admin/ 例如,我的的build/config.js的配置如下: let config = { env: 'development', baseUrl: 'http://localhost/apiadmin/public/index.php/admin/' }; export default config; ``` #### 修改webpack.prod.config.js ``` 修改build/webpack.prod.config.js中module.exports里面的publicPath的值为:http://localhost/dist/ 比如我的配置(仅截取要修改的部分)如下: output: { publicPath: 'http://localhost/dist/', // 修改 https://iv...admin 这部分为你的服务器域名 filename: '[name].[hash].js', chunkFilename: '[name].[hash].chunk.js' } ``` #### 打包 ``` 进入到前端项目ApiAdmin-WEB里面,使用npm install命令安装依赖,然后用npm run build打包: B000000067100V:ApiAdmin-WEB v_shiyanjun$ npm run build > apiadmin-web@1.3.1 build /Users/v_shiyanjun/WebstormProjects/ApiAdmin-WEB > webpack --progress --hide-modules --config build/webpack.prod.config.js clean-webpack-plugin: /Users/v_shiyanjun/WebstormProjects/ApiAdmin-WEB/dist/* has been removed. Happy[happybabel]: Version: 5.0.0. Threads: 4 (shared pool) Happy[happybabel]: All set; signaling webpack to proceed. Hash: 5fb20d09e396a48b9ff9 Version: webpack 3.12.0 Time: 35018ms Asset Size Chunks Chunk Names 11.5fb20d09e396a48b9ff9.chunk.js 10.8 kB 11 [emitted] d535a25a79fb1365ae814b61e88fae71.ttf 198 kB [emitted] a2c4a261a239aa84463dc70e4bac9b9a.svg 555 kB [emitted] [big] d0f4064f9cf44072e125e9002e321927.jpg 15.8 kB [emitted] bf988a761acc1c7f09511daf951a5bef.jpg 11.2 kB [emitted] 25ca98628a140fbbcf4d904b8abeb50a.png 3.72 kB [emitted] 1ef95f727ba081d3a43fa9aeb91220f1.png 3.11 kB [emitted] 0.5fb20d09e396a48b9ff9.chunk.js 839 kB 0 [emitted] [big] 1.5fb20d09e396a48b9ff9.chunk.js 5.58 kB 1 [emitted] 2.5fb20d09e396a48b9ff9.chunk.js 4.22 kB 2 [emitted] 3.5fb20d09e396a48b9ff9.chunk.js 9.84 kB 3 [emitted] 4.5fb20d09e396a48b9ff9.chunk.js 8.58 kB 4 [emitted] 5.5fb20d09e396a48b9ff9.chunk.js 6.07 kB 5 [emitted] 6.5fb20d09e396a48b9ff9.chunk.js 10.8 kB 6 [emitted] 7.5fb20d09e396a48b9ff9.chunk.js 8.18 kB 7 [emitted] 8.5fb20d09e396a48b9ff9.chunk.js 10.1 kB 8 [emitted] 9.5fb20d09e396a48b9ff9.chunk.js 8.39 kB 9 [emitted] 10.5fb20d09e396a48b9ff9.chunk.js 13.3 kB 10 [emitted] 99ac3308dd8ee14f749f51538d0d5b9e.woff 198 kB [emitted] 12.5fb20d09e396a48b9ff9.chunk.js 4.19 kB 12 [emitted] 13.5fb20d09e396a48b9ff9.chunk.js 3.69 kB 13 [emitted] 14.5fb20d09e396a48b9ff9.chunk.js 4.84 kB 14 [emitted] 15.5fb20d09e396a48b9ff9.chunk.js 12.5 kB 15 [emitted] 16.5fb20d09e396a48b9ff9.chunk.js 8.14 kB 16 [emitted] main.5fb20d09e396a48b9ff9.js 93.6 kB 17 [emitted] main vender-exten.5fb20d09e396a48b9ff9.js 131 kB 18 [emitted] vender-exten vender-base.5fb20d09e396a48b9ff9.js 705 kB 19 [emitted] [big] vender-base main.5fb20d09e396a48b9ff9.css 251 kB 17 [emitted] [big] main td_icon.ico 4.29 kB [emitted] fonts/ionicons.eot 121 kB [emitted] fonts/ionicons.ttf 189 kB [emitted] fonts/ionicons.svg 334 kB [emitted] [big] fonts/ionicons.woff 67.9 kB [emitted] g.css 212 kB [emitted] y.css 212 kB [emitted] r.css 212 kB [emitted] ../index.html 784 bytes [emitted] Child html-webpack-plugin for "../index.html": 1 asset Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js?minimize!node_modules/autoprefixer-loader/index.js!node_modules/iview/dist/styles/iview.css: Asset Size Chunks Chunk Names d535a25a79fb1365ae814b61e88fae71.ttf 198 kB [emitted] 99ac3308dd8ee14f749f51538d0d5b9e.woff 198 kB [emitted] a2c4a261a239aa84463dc70e4bac9b9a.svg 555 kB [emitted] [big] B000000067100V:ApiAdmin-WEB v_shiyanjun$ ``` #### 部署 ``` 打包成功之后,在项目根目录下会生成dist目录,里面包含一个dist文件夹(里面是字体、样式、js和图片等静态文件)和一个index.html文件, 将静态文件都dist目录和index.html文件直接复制到/Library/WebServer/Documents目录下,然后在浏览器直接访问 http://localhost即可进入登录页, 输入用户名root密码123456即可。 ``` #### 遇到的问题 ``` 1.python版本问题 由于我的mac笔记本原来默认的pthon版本是2.7,后来自己安装了一个3.7的python,并添加到了环境变量。 执行npm install没有遇到啥问题,而在执行npm run dev的时候报python环境变量错误,解决版本是修改$PATH环境变量, 由于mac默认的python一般是在/usr/bin目录下,所以修改我的/etc/paths文件,确保/usr/bin在/usr/local/bin之前。 比如我的/etc/paths中的配置如下: /usr/bin /usr/local/bin /bin /usr/sbin /sbin 2.node版本问题 原来我的node版本是10.x,在执行npm run dev的时候报错,所以将版本降到了8.x就好了。 3.目录权限不足问题 在部署的过程中很多地方经常会遇到权限问题,使用如下命令对目录下所有文件授权: sudo chmod -R 777 目录名 另外在mac系统命令行终端执行一些命令的时候只要是遇到权限问题,一定要在命令前使用sudo,一般都能解决问题。 4.数据库和redis问题 在部署项目之前要创建好mysql数据库并初始化好基础数据,并安装好redis数据库,保证数据库和redis的连接信息配置无误。 ```