首页 > 解决方案 > Codeigniter 应用程序安装程序

问题描述

我正在使用 Codeigniter 构建一个 Web 应用程序,它将在 localhost 上运行。我使用CI 安装程序作为应用程序安装程序。我尝试修改它的代码,以便它也可以更改 config.php 上的 base.url()。但是,结果总是

无法写入数据库配置文件,请chmod application/config/database.php文件为777

并清空 config.php 和 database.php。有人可以帮忙吗?

我的修改代码:

core_class.php

<?php class Core {

// Function to validate the post data
function validate_post($data)
{
    /* Validating the hostname, the database name and the username. The password is optional. */
    return !empty($data['hostname']) && !empty($data['username']) && !empty($data['database']);
}

// Function to show an error
function show_message($type,$message) {
    return $message;
}

// Function to write the config file
function write_config($data) {

    // Database path
    $dbtemplate_path    = 'config/database.php';
    $dboutput_path  = '../application/config/database.php';

    // Config path
    $configtemplate_path    = 'config/config.php';
    $configoutput_path  = '../application/config/config.php';

    // Open the file
    $database_file = file_get_contents($dbtemplate_path);
    $config_file = file_get_contents($conftemp_path);

    $db  = str_replace("%hostname%",$data['hostname'],$db_file);
    $db  = str_replace("%username%",$data['username'],$db);
    $db  = str_replace("%password%",$data['password'],$db);
    $db  = str_replace("%database%",$data['database'],$db);

    $conf  = str_replace("%baseurl%",$data['baseurl'],$conf_file);

    // Write the new config file
    $database = fopen($dboutput_path,'w+');
    $config = fopen($configoutput_path,'w+');

    // Chmod the file, in case the user forgot
    @chmod($dboutput_path,0777);
    @chmod($configoutput_path,0777);

    // Verify file permissions
    if(is_writable($dboutput_path)) {
        if(is_writable($configoutput_path)) {
            // Write the file
            if(fwrite($database,$db)) {
                if (fwrite($config, $conf)) {
                    return true;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    }else{
        return false;
    }
}

}

标签: phpcodeigniter

解决方案


无法写入数据库配置文件,请chmod application/config> /database.php 文件为777

表示由于权限问题,无法修改 database.php 文件。

要解决此问题,您需要按照声明“请将 chmod application/config/database.php 文件更改为 777

因此,在您的终端中找到此文件并执行以下操作:

sudo chmod 777 application/config/database.php

推荐阅读