由于最近在学习小程序的开发,前台后台一起开发,确实有点麻烦,尤其是一个人的情况下,找到了本文中的fusio,主要是PHP的,自己用的比Python熟悉,Python也可以用,这个感觉简单点。改天再测试python的微服务。
So:记录一下安装的流水章,有不对的希望可以在下面反馈。
关于fusion
Fusio 是一个开源 API 管理平台,可帮助创建创新的 API 解决方案。通过 Fusio,您可以快速构建最先进的 API,设置开发人员门户并通过您的 API 获利。
Fusio 可帮助您处理以下用例:
- API Product
Fusio 可帮助您创建出色的 API 产品,除了构建 API 之外,它还提供了一个开发人员门户,开发人员可以在其中注册,并提供了一种通过 API 获利的方法。 - API Gateway
Fusio 可用作内部 API 和微服务的网关。它能处理所有常见功能,如授权、速率限制和模式验证。 - SPA Backend
Fusio 可用作后端,使用流行的 Javascript 框架(如 Angular、React 或 Vue)构建 SPA。它提供了一个强大的代码生成器,可以自动为您的 API 生成 SDK。 - API Builder
Fusio 有助于根据不同的数据源自动生成 API,即可以基于数据库或文件系统生成完整的 REST API。 - API Framework
对于更复杂的用例,您还可以使用 Fusio 作为框架从头开始构建完整的 API。这意味着您可以构建自定义操作,在其中可以使用广泛的 PHP 生态系统来解决您的任务。
本人多次测试public/install.php的自动安装脚本,都无法自动安装,即使安装成功,用户登陆也会登陆失败。所以本文主要是手动安装的过程。
安装前置条件:
宝塔面板:免费版8.0.6
Composer version 2.8.2
PHP version 8.2.22 (/www/server/php/82/bin/php)
nginx :1.22.1
PHP 需要启用 putenv(),启用方法如下:
在【宝塔面板】的【软件商店】中搜索PHP,点击已安装–>PHP-8.2.22–>安装扩展–>fileinfo和mcrypt。
接着点击【配置文件】查找 disable_functions 配置项,如果 disable_functions 列表中包含 putenv,将其删除。保存修改,重启 PHP服务。
在/www/wwwroot下创建文件夹fusio,在新建的fusio目录下执行下面的命令
composer create-project fusio/fusio
修改当前目录下的'.env'文件只需要修改三行就可以
APP_URL="http://你的域名"
APP_APPS_URL="http://你的域名/apps"
APP_CONNECTION="pdo-mysql://数据库用户名:数据库密码@localhost/数据库名"
php bin/fusio migrate --插入数据库
php bin/fusio adduser --添加用户
#Choose the role of the account [1=Administrator, 2=Backend, 3=Consumer]: 1 <--这里选择1
#Enter the username: admin <--输入用户名
#Enter the email: ******@gmail.com <--输入管理员邮箱
#Enter the password: 12345678 <--输入密码
#Repeat the password: 12345678 <--输入二次确认的密码
#Created user admin successful <--新建用户完成
#目录不要换,还是在当前目录执行下面的命令安装应用程序即fusio
#安装fusio
php bin/fusio marketplace:install fusio
--等待完成即可
--下面可选安装,安装使用的源是github.com 有一定几率会失败,多事几次就好
#安装developer
php bin/fusio marketplace:install developer
#安装account
php bin/fusio marketplace:install account
#安装redoc
php bin/fusio marketplace:install redoc
#安装swagger-ui
php bin/fusio marketplace:install swagger-ui
至此基本安装完成,
点击之前新增的网站的【设置】–>【网站目录】–>设置网站目录为‘/www/wwwroot/fusio/public’ 保存。
设置【伪静态】,选择模板thinkPHP保存。如果没有thinkPHP的模板则伪静态设置为下面的代码
location ~* (runtime|application)/{
return 403;
}
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
注意要设置伪静态,否者fusio登录的时候会提示错误‘Could not authenticate’,可能我使用脚本安装不成功也是这个问题。
【配置文件】的最后一个花括号前添加如下配置
# 处理PHP文件的请求
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
# 特定于/apps/路径的请求处理
location ~ ^/apps/(.+)/ {
index index.html index.php;
try_files $uri $uri/ /apps/$1/index.html;
}
访问你的域名,结果与官网结果一致就完成安装。结果参照官网结果【DEMO】
下面是官方的安装步骤【官方安装文档】
Setup
Manual Setup
- Adjust the configuration file
Open the file.envin the Fusio directory and change the keyAPP_URLto the domain pointing to the public folder. Also insert the database credentials to theAPP_CONNECTIONkeys. - Execute the installation command
The installation script inserts the Fusio database schema into the provided database. It can be executed with the following commandphp bin/fusio migrate. - Create administrator user
After the installation is complete you have to create a new administrator account. Therefor you can use the following commandphp bin/fusio adduser. Choose as account type “Administrator”.