CodeIgniter PHP Apache 500 内部服务器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6674689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:58:17  来源:igfitidea点击:

CodeIgniter PHP Apache 500 Internal Server Error

phpapache.htaccesscodeignitermod-rewrite

提问by alex

I did a project in CodeIgniter. It's working fine on my localhost, but giving "500 Internal Server Error" on the remote server. This is my .htaccessfile content:

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

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

回答by Madan Sapkota

Open httpd.conf generally located in Apache installation directory in windows

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

/apache/conf/httpd.conf

/apache/conf/httpd.conf

and

/etc/httpd/httpd.conf

/etc/httpd/httpd.conf

in Unix based systems. httpd.conf is an Apache configuration file which stores various information about the server.

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

Search for the module mod_rewrite.soor (mod_rewrite.cin rare cases). mod_rewrite module is developed to rewrite the requested URLs on the fly. Most of the time you will find in commented state.

搜索模块mod_rewrite.so或(mod_rewrite.c在极少数情况下)。mod_rewrite 模块被开发用于即时重写请求的 URL。大多数情况下,您会发现处于评论状态。

#LoadModule rewrite_module modules/mod_rewrite.*

#LoadModule rewrite_module modules/mod_rewrite.*

Here #character represents that it is commented or disabled.

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

LoadModule rewrite_module modules/mod_rewrite.*

LoadModule rewrite_module modules/mod_rewrite.*

Remove #and restart the Apache Http Server using the command apache -k restartin windows or service httpd restartin unix systems. You also use XAMPP/Wamp UI to restart Apache in windows systems.

在 windows 或unix 系统中#使用命令删除并重新启动 Apache Http Server 。您还可以使用 XAMPP/Wamp UI 在 Windows 系统中重新启动 Apache。apache -k restartservice httpd restart

Next create .htaccessfile in root directory where your CodeIgniter project is located and paste following code

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

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

# Rewrite engine
RewriteEngine On

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

Next Find CodeIgniter configuration file, generally located in it's configuration directory.

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

./application/config/config.php

./application/config/config.php

Open the file and make $config['index_page']value empty. which looks like this

打开文件并将$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'] = '';

Now the story is ended. Everything should work fine. You can find more information about httpd.config at Apache Module mod_rewrite. Hope this helps you. Thanks!!

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

回答by jahackbeth

Posting this, just in case it helps somebody...

Other answers to this question assume that you have access to apache's configuration files. But if you are on a shared hosting platform and do not have access to directories other than the ones where you are supposed to host your files: the trick was to force php to throw all errors even if apache could not.

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

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

Open "index.php" that resides in the root folder of your codeigniter installation;

打开位于 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;
......

Making the above change immediately started displaying what was wrong with the code and I was able to fix it and get it up and running.

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

Don't forget to set your codeigniter environment to "production" once you're done fixing it.

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

回答by jaydisc

It's likely that the reason is explained in the error_log. Is there an error_log in the root directory of the web site? Is there a logs folder somewhere else? The reason will be detailed in there.

原因很可能在 error_log 中有解释。网站根目录下有error_log吗?其他地方是否有日志文件夹?原因将在那里详细说明。

回答by Hamed

try this out :

试试这个:

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

Probably you have problem with your htaccessfile. It's helped me as well.

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

回答by ShivarajRH

I solved this error.

我解决了这个错误。

I was given different database name, I have changed with following steps:

我得到了不同的数据库名称,我已经按照以下步骤进行了更改:

  1. I have created database in server using cpanel
  2. I have created a user
  3. I have assigned the previously created database to user
  4. I changed database settings with username and dbname etc.
  1. 我已经使用 cpanel 在服务器中创建了数据库
  2. 我创建了一个用户
  3. 我已将先前创建的数据库分配给用户
  4. 我使用用户名和 dbname 等更改了数据库设置。