likeadmin(PHP-SaaS版本) 系统框架 网址(https://www.likeadmin.cn/) 在 SAAS 平台-代码生成器里生成代码报错 is_dir(): open_basedir restriction in effect. File(/home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/src/api/) is not within the allowed path(s): (/home/www/local.chineseherb.cn/likeadmin_php_saas-master/server/:/tmp/)

likeadmin(PHP-SaaS版本) 系统框架 网址(https://www.likeadmin.cn/) 在 SAAS 平台-代码生成器里生成代码报错 is_dir(): open_basedir restriction in effect. File(/home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/src/api/) is not within the allowed path(s): (/home/www/local.chineseherb.cn/likeadmin_php_saas-master/server/:/tmp/)
用户545179374
01月04日
|
浏览 44
后端
前端
程序员
开发编程

该错误是由于PHP的open_basedir安全限制导致。生成器试图访问的目录不在允许的路径列表中。

解决方案:

  1. 检查并修改 open_basedir 配置

    • 找到你的PHP配置文件(如 php.ini)。
    • 搜索 open_basedir 指令。
    • 将报错中需要访问的目录路径(/home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/src/api/)添加到允许的路径列表中。多个路径用冒号分隔。
    • 修改后重启PHP服务(如PHP-FPM或Apache)。

    示例修改:
    将原来的:

    复制代码
    open_basedir = /home/www/local.chineseherb.cn/likeadmin_php_saas-master/server/:/tmp/
    

    修改为:

    复制代码
    open_basedir = /home/www/local.chineseherb.cn/likeadmin_php_saas-master/server/:/home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/:/tmp/
    

    (建议包含整个 admin 目录,而不仅是 api 子目录,以确保其他相关操作正常。)

  2. 临时在代码中设置(不推荐用于生产环境)
    如果无法修改全局配置,可以在生成器执行的入口文件(通常是 server/public/index.php)顶部添加:

    复制代码
    ini_set('open_basedir', '/home/www/local.chineseherb.cn/likeadmin_php_saas-master/server/:/home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/:/tmp/');
    
  3. 检查目录权限
    确保Web服务器进程(如 www-datanginx 用户)对 /home/www/local.chineseherb.cn/likeadmin_php_saas-master/admin/src/api/ 目录有读写权限。

主要原因: SAAS版代码生成器需要将生成的代码文件写入到 admin 应用目录,而默认的 open_basedir 配置只允许访问 server 目录。

请通过【🔍追问按钮】发送完整错误截图

我要提问
复制内容
分享给好友
AI编程问答网 免责声明:
以上内容除特别注明外均来源于网友提问,AI编程问答网回答,权益归原著者所有;
 
下一篇:import _ from "lodash" // satisfies instanceof,val is Type export type req_t = (fun: string, ...argArray: any[]) => Promise<any> export type res_t<T extends object> = { [K in keyof T]: T[K] extends (fun: string, ...argArray: any[]) => Promise<infer R> ? R : never }[keyof T] export function callObjProxy<T>(req: req_t): T { function proxy2(prevPath: string[]): any { return new Proxy(() => { }, { get(target, propKey) { if (typeof propKey !== 'string') { return undefined } const next = [...prevPath, propKey] return proxy2(next); }, apply(target, thisArg, argArray) { const fun = prevPath.join( '.') return req(fun, ...argArray); } }); } return proxy2([]) as T; } export interface callObjSend_t { catch(str: string): void } export async function callObj<T extends Record<string, any>>(binObj: T, ...args: any[]) { function sendErrmsg(str: string) { return ["catch", str] } try { const [funpath, ...funParams] = args || [] console.log("callObj", ...args) if (typeof funpath !== "string") { return sendErrmsg("callObj funpath不是string") } // 1. 解析路径 const p = funpath.replace(/[\[\]]/g, '.').split('.').filter(Boolean); if (p.length === 0) { return sendErrmsg("callObj 路径不存在") } // 2. 获取方法 const fun = _.get(binObj, p); if (typeof fun !== "function") { return sendErrmsg(`callObj 指定路径不是函数: ${funpath}`) } // 3. 获取方法的直接父对象(this 上下文) const parentPath = p.slice(0, -1); const context = parentPath.length > 0 ? _.get(binObj, parentPath) : binObj; if (context == null) { return sendErrmsg(`callObj 方法上下文不存在: ${funpath}`) } // 4. 正确执行 // console.log("callObj", { funpath, funParams }) const data = await fun.apply(context, funParams); // const data = await fun(...funParams); //Cannot read properties of undefined (reading 'broModules') return data } catch (err) { // console.log("callObj error", { funpath, funParams, err }) if (isError(err)) { return sendErrmsg(err.message) } else { return sendErrmsg("callObj未知错误".concat(String(err))) } } }