CodeIgniter PHP Apache 500 Internal Server Error CodeIgniter PHP Apache 500 Internal Server Error apache apache

CodeIgniter PHP Apache 500 Internal Server Error


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

/apache/conf/httpd.conf

and

/etc/httpd/httpd.conf

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

Search for the module mod_rewrite.so or (mod_rewrite.c in 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.

#LoadModule rewrite_module modules/mod_rewrite.*

Here # character represents that it is commented or disabled.

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. You also use XAMPP/Wamp UI to restart Apache in windows systems.

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

# index file can be index.php, home.php, default.php etc.DirectoryIndex index.php# Rewrite engineRewriteEngine On# condition with escaping special charsRewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

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

./application/config/config.php

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

/*  |--------------------------------------------------------------------------  | 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!!


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.

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

/*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.


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.