美文网首页
php网站在线安装

php网站在线安装

作者: f09037cb27f7 | 来源:发表于2017-07-31 16:54 被阅读108次

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

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

    第二步:环境检测

    // 常用检测
    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') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
    $allow_url_fopen = (ini_get('allow_url_fopen') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
    $safe_mode = (ini_get('safe_mode') ? '<font color=red>[×]On</font>' : '<font color=green>[√]Off</font>');
    
    $err = 0;
    if (empty($tmp['GD Version'])) {
        $gd = '<font color=red>[×]Off</font>';
        $err++;
    } else {
        $gd = '<font color=green>[√]On</font> ' . $tmp['GD Version'];
    }
    if (function_exists('mysqli_connect')) {
        $mysql = '<span class="correct_span">√</span> 已安装';
    } else {
        $mysql = '<span class="correct_span error_span">√</span> 请安装mysqli扩展';
        $err++;
    }
    if (ini_get('file_uploads')) {
        $uploadSize = '<span class="correct_span">√</span> ' . ini_get('upload_max_filesize');
    } else {
        $uploadSize = '<span class="correct_span error_span">√</span>禁止上传';
    }
    if (function_exists('session_start')) {
        $session = '<span class="correct_span">√</span> 支持';
    } else {
        $session = '<span class="correct_span error_span">√</span> 不支持';
        $err++;
    }
    if(function_exists('curl_init')){
        $curl = '<font color=green>[√]支持</font> ';
    }else{
        $curl = '<font color=red>[×]不支持</font>';
        $err++;
    }
    if(function_exists('file_put_contents')){
        $file_put_contents = '<font color=green>[√]支持</font> ';
    }else{
        $file_put_contents = '<font color=red>[×]不支持</font>';
        $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;
    }
    
    <script type="text/javascript">
    var n=-1;
    var data = <?php echo json_encode($_POST);?>;
    $.ajaxSetup ({ cache: false });
    function reloads(n) {
        var url =  "<?php echo $_SERVER['PHP_SELF']; ?>?step=4&install=1&n="+n;
        $.ajax({
            type: "POST",       
            url: url,
            data: data,
            dataType: 'json',
            beforeSend:function(){
            },
            success: function(msg){
                if(msg.n=='999999'){
                    $('#dosubmit').attr("disabled",false);
                    $('#dosubmit').removeAttr("disabled");              
                    $('#dosubmit').removeClass("nonext");
                    setTimeout('gonext()',2000);
                }
                if(msg.n>=0){
                    $('#loginner').append(msg.msg); 
                    reloads(msg.n); 
                }else{
                    //alert('指定的数据库不存在,系统也无法创建,请先通过其他方式建立好数据库!');
                    alert(msg.msg);
                }            
            }
        });
    }
    function gonext(){
        window.location.href='<?php echo $_SERVER['PHP_SELF']; ?>?step=5';
    }
    $(document).ready(function(){
        reloads(n);
    })
    </script> 
    

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

    相关文章

      网友评论

          本文标题:php网站在线安装

          本文链接:https://www.haomeiwen.com/subject/qglrlxtx.html