成功安装 后,建议手动删除 ./public/install目录。
如果需要安装,请手动删除./runtime/_install.lock文件。'; include dirname(__FILE__) . D_S . '_error.php'; exit(0); } switch ($step) { //第一步:环境检测 case 1: //-1:必须但不支持 0:可选但不支持 1:完美支持 $checkList = array( 'php' => array('name' => 'PHP 版本', 'status' => -1, 'tip' => '建议使用PHP 5.3.3及以上版本,推荐使用PHP 7'), 'opcache' => array('name' => 'Opcache', 'status' => -1, 'tip' => '开启opcache后,将无法生成在线接口文档,需要设置opcache.enable=0关闭opcache'), 'pdo' => array('name' => '数据库模块', 'status' => -1, 'tip' => '建议使用PDO扩展,否则NotORM无法使用PDO进行数据库操作'), //'memcache' => array('name' => 'Memcache扩展', 'status' => 0, 'tip' => '无此扩展时,不能使用Memcache缓存'), //'mcrypt' => array('name' => 'Mcrypt扩展', 'status' => 0, 'tip' => '无此扩展时,不能使用mcrypt进行加密处理'), 'config' => array('name' => '配置目录权限', 'status' => -1, 'tip' => '配置文件目录缺少写入权限,无法写入配置,将会导致安装失败,需要手动添加写入权限。'), 'runtime' => array('name' => '运行时目录权限', 'status' => -1, 'tip' => '运行时目录缺少写入权限,将不能写入日记和进行文件缓存,需要手动添加写入权限。'), 'uploads' => array('name' => '文件上传目录权限', 'status' => -1, 'tip' => '文件上传目录缺少写入权限,将不能上传文件,需要手动添加写入权限。'), ); if (version_compare(PHP_VERSION, '5.3.3', '>=')) { $checkList['php']['status'] = 1; } if (class_exists('PDO', false) && extension_loaded('PDO')) { $checkList['pdo']['status'] = 1; } if (ini_get('opcache.enable') === false || ini_get('opcache.enable') == '0') { $checkList['opcache']['status'] = 1; } // if (class_exists('Memcache', false) && extension_loaded('memcache')) { // $checkList['memcache']['status'] = 1; // } // if (extension_loaded('mcrypt')) { // $checkList['mcrypt']['status'] = 1; // } $runtimePath = dirname(__FILE__) . implode(D_S, array('', '..', '..', 'runtime')); $runtimePath = file_exists($runtimePath) ? realpath($runtimePath) : $runtimePath; $checkList['runtime']['tip'] = $runtimePath . '
' . $checkList['runtime']['tip']; if (is_writeable($runtimePath)) { $checkList['runtime']['status'] = 1; } $configPath = dirname(__FILE__) . implode(D_S, array('', '..', '..', 'config')); $configPath = file_exists($configPath) ? realpath($configPath) : $configPath; $checkList['config']['tip'] = $configPath . '
' . $checkList['config']['tip']; if (is_writeable($configPath)) { $checkList['config']['status'] = 1; } $publicPath = dirname(__FILE__) . implode(D_S, array('', '..', '..', 'public', 'uploads')); $publicPath = file_exists($publicPath) ? realpath($publicPath) : $publicPath; $checkList['uploads']['tip'] = $publicPath . '
' . $checkList['uploads']['tip']; if (is_writable($publicPath)) { $checkList['uploads']['status'] = 1; } include dirname(__FILE__) . D_S . '_step1.php'; break; //第2步:系统配置 case 2: include dirname(__FILE__) . D_S . '_step2.php'; break; //第3步:接口请求 case 3: if (empty($_POST['doSubmit']) || empty($_POST)) { header('Location: ./?step=1'); exit(0); } //数据库配置文件 $search = array( '{project}', '{host}', '{name}', '{user}', '{password}', '{port}', '{charset}', '{prefix}', ); $replace = array( 'phalapi_pro', $_POST['host'], $_POST['name'], $_POST['user'], $_POST['password'], $_POST['port'], 'utf8mb4', // $_POST['charset'], $_POST['prefix'], ); $configDbsContent = str_replace($search, $replace, getConfigDbsTpl()); file_put_contents( dirname(__FILE__) . implode(D_S, array('', '..', '..', 'config', 'dbs.php')), $configDbsContent ); // 应用配置 $appCfgFile = dirname(__FILE__) . implode(D_S, array('', '..', '..', 'config', 'app.php')); $configAppContent = str_replace( array('*#FD2F9DM~E*', '9DfnseJ%sD#', '果果云'), array(createRandStr(12), createRandStr(12), !empty($_POST['project_name']) ? str_replace("'", '', $_POST['project_name']) : '果果云'), file_get_contents($appCfgFile) ); @file_put_contents($appCfgFile, $configAppContent); // 创建数据库 $sql = "CREATE DATABASE IF NOT EXISTS {$_POST['name']} DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;"; sqlExcute($_POST['host'] . ':' . $_POST['port'], $_POST['user'], $_POST['password'], $sql); // 导入数据库 $sqlFile = dirname(__FILE__) . implode(D_S, array('', '..', '..', 'data', 'phalapi_pro.sql')); require_once dirname(__FILE__) . implode(D_S, array('', '..', '..', 'public', 'init.php')); $sqlContent = str_replace('`pp_', '`' . $_POST['prefix'], file_get_contents($sqlFile)); $sqlArr = explode(";\n", str_replace(";\r\n", ";\n", $sqlContent)); // 兼容windows系统的换行 // 开启调试,避免安装过程中连接不上,可以相撞看原因 \PhalApi\DI()->debug = true; foreach ($sqlArr as $sql) { $sql = trim($sql); if (empty($sqlArr)) { continue; } try { \PhalApi\DI()->notorm->demo->executeSql($sql); } catch (Exception $ex) { $error = $ex->getTraceAsString(); $error = $ex->getMessage() . '
' . str_replace("\n", '
', $error); include dirname(__FILE__) . D_S . '_error.php'; die(); } } // 创建管理员 $userDomain = new \Base\Domain\User(); $userDomain->register($_POST['admin_user'], $_POST['admin_pass'], '', '超级管理员', '', 0, '', \Base\Domain\UserType::MEMBER_LEVEL_SUPER_ADMIN); touch($runtimePath . D_S . '_install.lock'); //请求链接 $apiUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/docs.php'; include dirname(__FILE__) . D_S . '_step3.php'; break; default: include dirname(__FILE__) . D_S . '_start.php'; } function createRandStr($len, $chars = null) { if (!$chars) { $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; } return substr(str_shuffle(str_repeat($chars, rand(5, 8))), 0, $len); } function getConfigDbsTpl() { $configDbs = << 2015-02-09 */ return array( /** * DB数据库服务器集群 */ 'servers' => array( 'db_master' => array( //服务器标记 'host' => '{host}', //数据库域名 'name' => '{name}', //数据库名字 'user' => '{user}', //数据库用户名 'password' => '{password}', //数据库密码 'port' => '{port}', //数据库端口 'charset' => '{charset}', //数据库字符集 'pdo_attr_string' => false, // 数据库查询结果统一使用字符串,true是,false否 'driver_options' => array( // PDO初始化时的连接选项配置 // 若需要更多配置,请参考官方文档:https://www.php.net/manual/zh/pdo.constants.php ), ), ), /** * 自定义路由表 */ 'tables' => array( //通用路由 '__default__' => array( 'prefix' => '{prefix}', 'key' => 'id', 'map' => array( array('db' => 'db_master'), ), ), /** 'demo' => array( //表名 'prefix' => '', //表名前缀 'key' => 'id', //表主键名 'map' => array( //表路由配置 array('db' => 'db_master'), //单表配置:array('db' => 服务器标记) array('start' => 0, 'end' => 2, 'db' => 'db_master'), //分表配置:array('start' => 开始下标, 'end' => 结束下标, 'db' => 服务器标记) ), ), */ ), ); EOT; return $configDbs; } function sqlExcute($servername, $username, $password, $sql) { // 创建连接 $conn = mysqli_connect($servername, $username, $password); // 检测连接 if ($conn) { // 执行sql if ($conn->query($sql) === TRUE) { return true; } $conn->close(); // die("Connection failed: " . mysqli_connect_error()); } return false; }