【问题标题】:CodeIgniter project not work on Linux-based remote serverCodeIgniter 项目不适用于基于 Linux 的远程服务器
【发布时间】:2016-05-16 03:39:57
【问题描述】:

我在 Windows XAMPP 上使用 CodeIgniter 开发了一个项目,该项目有效。但不适用于基于 Linux 的远程服务器。

我收到错误:

无法加载请求的文件:home.php

控制器: home.php:

public function index(){
  $this->load->view('home');
}

.htaccess:

RewriteEngine on
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

【问题讨论】:

  • 您是直接调用 home.php 文件还是包含在另一个 php 文件中?在您的 php 和 http 服务器上启用日志并检查。看起来您的脚本在您定义的路径上找不到文件。尝试使用文件的完整路径。

标签: php linux .htaccess codeigniter


【解决方案1】:

在 codeIgniter 3 + 版本中,如果出现以下错误,需要进行一些检查。


  • 找不到错误 404 页面
  • 无法加载请求的文件

先检查。

  • 确保您的文件名只有第一个字母大写
  • 确保您的班级名称只有首字母大写
  • 这也适用于模型。

警告:有时即使小写可能在某些 localhost 某些其他操作系统上工作,但当文件或类为小写时可能会导致错误,但对每个人来说可能并不相同。 p>

Controller

文件名: Home.php

<?php

class Home extends CI_Controller {

     public function __construct() {
        parent::__construct();
        $this->load->model('model_example');
     }

     public function index(){
        // $data['results'] = $this->model_example->get_results();
        $this->load->view('home');
     }
}

视图的文件夹结构

application

application > views > home.php

Models

文件名: Model_example.php

<?php

class Model_example extends CI_Model {

    public function get_results() {
      // Some Code Here.
    }
}

在你的 config.php 上

$config['base_url'] = 'http://localhost/your_project_name/';

【讨论】:

    【解决方案2】:

    您应该能够使用 Putty (http://www.putty.org/) 之类的工具通过脚本安装新版本的 Codeigniter,然后将您网站的文件添加到安装中,而不是直接上传 codeigniter 站点。

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

    用于安装新版 CI 的脚本会因您使用的 Linux 平台而异。 wget 用于 ubuntu。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-03
      • 2012-09-09
      • 2012-12-13
      • 2017-07-16
      相关资源
      最近更新 更多