php网站在线安装

个人研究开源系统的方法,文章还在整理中 ............

第一步:安装向导,使用协议

第二步:环境检测

// 常用检测
if (phpversion() < 5) {
    die('本系统需要PHP5+MYSQL >=5.0环境,当前PHP版本为:' . phpversion());
}

$phpv = @ phpversion();
$os = PHP_OS;
//$os = php_uname();
$tmp = function_exists('gd_info') ? gd_info() : array();
$server = $_SERVER["SERVER_SOFTWARE"];
$host = (empty($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_HOST"] : $_SERVER["SERVER_ADDR"]);
$name = $_SERVER["SERVER_NAME"];
$max_execution_time = ini_get('max_execution_time');
$allow_reference = (ini_get('allow_call_time_pass_reference') ? '[√]On' : '[×]Off');
$allow_url_fopen = (ini_get('allow_url_fopen') ? '[√]On' : '[×]Off');
$safe_mode = (ini_get('safe_mode') ? '[×]On' : '[√]Off');

$err = 0;
if (empty($tmp['GD Version'])) {
    $gd = '[×]Off';
    $err++;
} else {
    $gd = '[√]On ' . $tmp['GD Version'];
}
if (function_exists('mysqli_connect')) {
    $mysql = ' 已安装';
} else {
    $mysql = ' 请安装mysqli扩展';
    $err++;
}
if (ini_get('file_uploads')) {
    $uploadSize = ' ' . ini_get('upload_max_filesize');
} else {
    $uploadSize = '禁止上传';
}
if (function_exists('session_start')) {
    $session = ' 支持';
} else {
    $session = ' 不支持';
    $err++;
}
if(function_exists('curl_init')){
    $curl = '[√]支持 ';
}else{
    $curl = '[×]不支持';
    $err++;
}
if(function_exists('file_put_contents')){
    $file_put_contents = '[√]支持 ';
}else{
    $file_put_contents = '[×]不支持';
    $err++;
}

第三步:输入数据库配置,数据库名称、前缀、帐号、密码,管理员信息

提交信息用ajaxy验证,避免链接返回需要重新输入

$dbName = strtolower(trim($_POST['dbName']));
$_POST['dbport'] = $_POST['dbport'] ? $_POST['dbport'] : '3306';
if ($_GET['testdbpwd']) {
    $dbHost = $_POST['dbHost'];
    $conn = @mysqli_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd'],NULL,$_POST['dbport']);          
    if (mysqli_connect_errno($conn)){               
        die(json_encode(0));                
    } else {
        $result = mysqli_query($conn,"SELECT @@global.sql_mode");               
        $result = $result->fetch_array();
        $version = mysqli_get_server_info($conn);
        if ($version >= 5.7) 
        {
            if(strstr($result[0],'STRICT_TRANS_TABLES') || strstr($result[0],'STRICT_ALL_TABLES') || strstr($result[0],'TRADITIONAL') || strstr($result[0],'ANSI'))             
                exit(json_encode(-1));
        }
        $result = mysqli_query($conn,"select count(table_name) as c from information_schema.`TABLES` where table_schema='$dbName'");
        $result = $result->fetch_array();
        if($result['c'] > 0)
            exit(json_encode(-2));
        
        exit(json_encode(1));
    }
}

第四步:导入数据库

ajax方式执行,可以长时间执行很多个表,先让n等于-1,后台接收识别到先建立数据库名称
读取数据库文件,拆分执行sql方法

//读取数据文件
$sqldata = file_get_contents(SITEDIR . 'install/' . $sqlFile);
$sqlFormat = sql_split($sqldata, $dbPrefix);  // $dbPrefix为数据表的前缀
function sql_split($sql, $tablepre) {
    if ($tablepre != "tp_")
        $sql = str_replace("tp_", $tablepre, $sql);
          
    $sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
    
    $sql = str_replace("\r", "\n", $sql);
    $ret = array();
    $num = 0;
    $queriesarray = explode(";\n", trim($sql));
    unset($sql);
    foreach ($queriesarray as $query) {
        $ret[$num] = '';
        $queries = explode("\n", trim($query));
        $queries = array_filter($queries);
        foreach ($queries as $query) {
            $str1 = substr($query, 0, 1);
            if ($str1 != '#' && $str1 != '-')
                $ret[$num] .= $query;
        }
        $num++;
    }
    return $ret;
}
 

第五步:安装完成,提示跳转后台和首页

你可能感兴趣的:(php网站在线安装)