php - 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;
}
}
}
解决方案
无法写入数据库配置文件,请chmod application/config> /database.php 文件为777
表示由于权限问题,无法修改 database.php 文件。
要解决此问题,您需要按照声明“请将 chmod application/config/database.php 文件更改为 777 ”
因此,在您的终端中找到此文件并执行以下操作:
sudo chmod 777 application/config/database.php
推荐阅读
- python - 循环遍历系列时搜索多个子字符串。(蟒蛇/熊猫)
- java - 用spring boot开发的一个问答网站添加5分钟倒计时
- elasticsearch - 为什么弹性搜索 Junit 测试在 /tmp 文件夹中创建 jna 文件夹?
- audio - 为 Google 任务的任务完成添加声音 (TasksBoard)
- android - Android ContentValues put 方法
- python - 从自己的训练检查点加载用于推理的 MMDetection 会产生垃圾检测
- html - 您可以使用 RTE 创建自定义 MailChimp 模板块吗?
- python - 尝试标准化图像数组时出现内存错误
- ubuntu - 允许使用 Squid(转发代理)的经过身份验证的用户访问除某些选定网站外的所有用户的所有网站
- javascript - 对数组进行排序以将元素从一个位置移动到另一个位置,同时保持“order”字段相同