FastAdmin支持php7.4的教程

蓝色大肥鱼:这篇文章记录了让 FastAdmin 在 PHP 7.4 下正常安装运行的过程。作者用 PHP 内置服务器启动项目,安装时遇到 PHP 7.4 不再支持花括号访问数组/字符串成员的报错,通过开启 debug、查看日志定位到 ThinkPHP 的 Query.php,把 {} 改成 [] 后安装成功,并附上重复安装时入口文件的小 bug 修复。

AI 摘要 DeepSeek v4.1 Flash

本文最后更新于 2026年11月10日 下午

从安装到运行,一条龙走到底。

1. 前置

默认你们已经安装了 NodeJS 和 Composer。

php命令行版本:7.4.*

ThinkPHP:5.0.24

1.1. 下载安装

>表示执行命令

1
2
3
4
5
6
7
8
9
10
11
# 设置过国内镜像源的请忽略
> npm config set registry https://registry.npm.taobao.org

# 安装过bower的请忽略
> npm i -g bower

# 安装FastAdmin
> git clone https://gitee.com/karson/fastadmin.git fa_test
> cd fa_test
> bower install
> composer install

1.2. 运行访问

1
2
3
4
# 启动FastAdmin
> php -S 127.0.0.1:8080 -t public
[Tue Dec 1 19:35:46 2020] PHP 7.4.13 Development Server (http://127.0.0.1:8080) started
# 出现如上所述,表示 php 内置 Server 启动成功

打开浏览器,访问http://127.0.0.1:8080出现安装页面。

2. 安装

数据库,管理员信息填写完成,点击安装。出现如下所述。

php7.4开始不再支持使用花括号 {} 来访问数组和字符串成员。

出现问题就要解决,把 {} 改成 [] 就可以了。那么改那个文件呢?

引用一下我的开发三步走,后来人就可以站在前辈们铺好的路上了。

第一步,debug
第二步,看文档
第三步,翻源码

2.1. 开启debug

1
> cp .env.sample .env

编辑.env,改成如下内容。

1
2
3
4
5
6
7
8
9
10
11
[app]
debug = true
trace = true

[database]
# hostname = 192.168.1.101
# database = fastadmin
# username = root
# password = root
# hostport = 3306
# prefix = fa_

2.2. 找到错误位置

编辑application/admin/command/Install.php: 132-138行

1
2
3
4
5
6
7
8
try {
$adminName = $this->installation($mysqlHostname, $mysqlHostport, $mysqlDatabase, $mysqlUsername, $mysqlPassword, $mysqlPrefix, $adminUsername, $adminPassword, $adminEmail, $siteName);
} catch (\PDOException $e) {
throw new Exception($e->getMessage());
} catch (\Exception $e) {
\think\Log::error($e); // 在这里打印错误日志
return $output(0, $e->getMessage());
}

日志如下:

1
2
3
4
5
6
7
8
9
10
11
[ error ] think\exception\ErrorException::__set_state(array(
'severity' => 8192,
'data' =>
array (
),
'message' => 'Array and string offset access syntax with curly braces is deprecated',
'string' => '',
'code' => 0,
'file' => 'thinkphp/library/think/db/Query.php',
'line' => 400,
// 后面的就可以忽略了

message和安装页的错误提示是一样的

错误位置是thinkphp/library/think/db/Query.php的400行。

找到就可以修改了,把 {} 改成 [] 即可。

2.3. 安装成功

修改完后不用刷新页面,直接点击安装。安装成功!

3. 结尾

简单的用了一下,暂时还没发现别的问题。稳定性待测。

FastAdmin 支持 php7.4 教程完毕

Violet_ice紫冰 写于 2020-12-1 21:12:26

4. 番外

写的时候发现了一个小bug。重复安装完成后,由于 $adminName 为空字符串。所以点进入后台是跳到前台的。

文件application/admin/command/Install.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 200行
$adminFile = ROOT_PATH . 'public' . DS . 'admin.php';
# 下面是我加的,都重装了,入口文件还是改个名比较好。
# 因为本身工作目录就在public,所以不需要用chdir()。
# php的glob能不能使用正则,这一点我没研究明白。有没有懂行的大佬,麻烦告知一下。
if (!is_file($adminFile)) {
$files = glob('*.php');
foreach ($files as $file) {
if (preg_match('/^[a-zA-Z]{10}\.php$/', $file, $flag)) {
$adminFile = ROOT_PATH . 'public' . DS . $flag[0];
break;
}
}
unset($files); // 数组开销比较大用完就删掉,$file字符串就无所谓了。
}

# 248行
$adminName = '';
if (is_file($adminFile)) {
$adminName = Random::alpha(10) . '.php';
rename($adminFile, ROOT_PATH . 'public' . DS . $adminName);
}

FastAdmin支持php7.4的教程
https://www.vlice.cn/po/14821968b84a/
作者
Violet_ice紫冰
发布于
2020年12月28日
更新于
2026年11月10日
许可协议