成功安装 后,建议手动删除 ./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() . '