繁体   English   中英

CodeIgniter PHP Apache 500 内部服务器错误

[英]CodeIgniter PHP Apache 500 Internal Server Error

我在 CodeIgniter 做了一个项目。 它在我的本地主机上运行良好,但在远程服务器上给出“500 内部服务器错误”。 这是我的.htaccess文件内容:

RewriteEngine On
RewriteBase /ezgov
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

打开 httpd.conf 一般位于 Apache 安装目录中 windows

/apache/conf/httpd.conf

/etc/httpd/httpd.conf

在基于 Unix 的系统中。 httpd.conf 是一个 Apache 配置文件,其中存储了有关服务器的各种信息。

搜索模块mod_rewrite.so或(在极少数情况下为mod_rewrite.c )。 mod_rewrite 模块用于动态重写请求的 URL。 大多数情况下,您会在评论中找到 state。

#LoadModule rewrite_module modules/mod_rewrite.*

这里#字符表示它被注释或禁用。

LoadModule rewrite_module modules/mod_rewrite.*

Remove # and restart the Apache Http Server using the command apache -k restart in windows or service httpd restart in unix systems. 您还可以使用 XAMPP/Wamp UI 在 windows 系统中重新启动 Apache。

接下来在 CodeIgniter 项目所在的根目录中创建.htaccess文件并粘贴以下代码

# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php

# Rewrite engine
RewriteEngine On

# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

接下来找到CodeIgniter配置文件,一般位于其配置目录下。

./application/config/config.php

打开文件并使$config['index_page']值为空。 看起来像这样

/*
  |--------------------------------------------------------------------------
  | Index File
  |--------------------------------------------------------------------------
  |
  | Typically this will be your index.php file, unless you've renamed it to
  | something else. If you are using mod_rewrite to remove the page set this
  | variable so that it is blank.
  |
 */
$config['index_page'] = '';

现在故事结束了。 一切都应该正常工作。 您可以在Apache 模块 mod_rewrite找到有关 httpd.config 的更多信息。 希望这对您有所帮助。 谢谢!!

发布这个,以防万一它对某人有帮助......

此问题的其他答案假定您有权访问 apache 的配置文件。 但是,如果您在共享托管平台上并且无权访问您应该托管文件的目录以外的目录:诀窍是强制 php 抛出所有错误,即使 apache 不能。

打开位于 codeigniter 安装的根文件夹中的“index.php”;

/*switch to development environment*/
define('ENVIRONMENT', 'development');

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
        {
            case 'development':
            error_reporting(E_ALL);
            /*added line below*/
            ini_set('display_errors', '1');
            break;
......

进行上述更改后立即开始显示代码有什么问题,我能够修复它并启动并运行它。

完成修复后,不要忘记将 codeigniter 环境设置为“生产”。

error_log 中可能解释了原因。 web站点的根目录下是否有error_log? 其他地方有日志文件夹吗? 原因会在里面详述。

试试这个:

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

可能您的htaccess文件有问题。 它也帮助了我。

我解决了这个错误。

我被赋予了不同的数据库名称,我通过以下步骤进行了更改:

  1. 我已经使用 cpanel 在服务器中创建了数据库
  2. 我创建了一个用户
  3. 我已将先前创建的数据库分配给用户
  4. 我用用户名和数据库名等更改了数据库设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM