CodeIgniter 500 Internal Server Error
Asked Answered
L

13

13

I downloaded a PHP script written using CodeIgniter. when I run it from the localhost, on going to the admin folder, it shows localhost again. Also when running from my web host, it shows a 500 Internal Server Error.

I run the site from http://localhost/myproj It works. Then when I try to go to the admin page which is at http://localhost/myproj/administrator, it gives a 500 Internal Server Error.

I read here that this might be due to a wrong code in the .htaccess file. This is my present .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php

Please help me. I know it might be a very small problem, but I'm unable to find the error.

Livvi answered 11/9, 2011 at 11:22 Comment(0)
A
35

The problem with 500 errors (with CodeIgniter), with different apache settings, it displays 500 error when there's an error with PHP configuration.

Here's how it can trigger 500 error with CodeIgniter:

  1. Error in script (PHP misconfigurations, missing packages, etc...)
  2. PHP "Fatal Errors"

Please check your apache error logs, there should be some interesting information in there.

Argufy answered 12/9, 2011 at 23:43 Comment(6)
thank you, this helped me figure out the server's rewrite_module was not loaded.Vanderpool
This also helped me, turns out a hook i had installed was using a function from a helper that wasn't loaded! That's hours of my life spent debugging that i want back.Musician
Please check your apache error logs +1 i just could not find out what my error is until i see thisBroadfaced
Error logs did the trick. In Ubuntu 16.04, apache logs can be found /var/log/apache2Murcia
thank you, in centos7 the problem I found the cause on /var/log/httpdJudo
My problem was in the log, the .env file was not readable and all I had to do was use chmod command in centos 7Disgorge
M
5

Just in case somebody else stumbles across this problem, I inherited an older CodeIgniter project and had a lot of trouble getting it to install.

I wasted a ton of time trying to create a local installation of the site and tried everything. In the end, the solution was simple.

The problem is that older CodeIgniter versions (like 1.7 and below), don't work with PHP 5.3. The solution is to switch to PHP 5.2 or something older.

Macnair answered 27/8, 2012 at 12:41 Comment(0)
B
4

You're trying to remove index.php from your site URL's, correct?

Try setting your $config['uri_protocol'] to REQUEST_URI instead of AUTO.

Blatman answered 12/9, 2011 at 4:9 Comment(1)
Thankyou so much. After hours of searching, this was the problem to my solutionMentality
L
4

Make sure your root index.php file has the correct permission, its permission must be 0755 or 0644

Latonia answered 15/10, 2019 at 11:10 Comment(2)
this is not worked for me.Tibbitts
@IlhamSafeek try to use other solutions mentioned on this page. Check your PHP version as well.Latonia
P
3

Try this to your .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule >
Peltry answered 21/3, 2018 at 13:46 Comment(0)
P
2

remove comment in httpd.conf (apache configuration file):

LoadModule rewrite_module modules/mod_rewrite.so 
Poirer answered 24/10, 2016 at 16:46 Comment(0)
R
1

Whenever I run CodeIgniter in a sub directory I set the RewriteBase to it. Try setting it as /myproj/ instead of /.

Raddie answered 11/9, 2011 at 11:37 Comment(7)
Tried it. But still same error. When I check the Log file on my web host, I see the following error. Severity: Notice --> Undefined index: LOGIN_USERNAMELivvi
What is your $config['base_url'] and $config['uri_protocol'] set to in the /config/config.php? Also, is the LOGIN_USERNAME something in your CI code or maybe in your web root?Raddie
$config['base_url'] = "localhost/myproj"; $config['uri_protocol'] = "AUTO"; I removed the LOGIN_USERNAME variable from the code.Livvi
Try blanking out the base_url. Also, in your /index.php file make sure define('ENVIRONMENT', 'development'); is set to development and that in your php.ini your display_errors is set to On.Raddie
Tried everything but still no luck. I'm facing the same problem.Livvi
Check into your error logs again to see if there are any errors. Something should be logged with that type of error.Raddie
This was the log details in the wamp folder (access.log file) 127.0.0.1 - - [11/Sep/2011:18:47:46 +0530] "GET /myproj/administrator HTTP/1.1" 200 4629 127.0.0.1 - - [11/Sep/2011:18:47:46 +0530] "GET /myproj/index.php?img=gifLogo HTTP/1.1" 400 543 127.0.0.1 - - [11/Sep/2011:18:47:46 +0530] "GET /myproj/index.php?img=pngFolderGo HTTP/1.1" 400 543 127.0.0.1 - - [11/Sep/2011:18:47:46 +0530] "GET /myproj/index.php?img=pngPlugin HTTP/1.1" 400 543Livvi
H
1

I know I am late, but this will help someone.

Check if rewrite engine is enabled.

If not, enable rewrite engine and restart server.

sudo a2enmod rewrite
sudo service apache2 restart
Hordein answered 1/9, 2016 at 2:16 Comment(0)
D
1

if The wampserver Version 2.5 then change apache configuration as

httpd.conf (apache configuration file): From

#LoadModule rewrite_module modules/mod_rewrite.so** 

To ,delete the #

LoadModule rewrite_module modules/mod_rewrite.so** 

this working fine to me

Dahomey answered 5/9, 2017 at 7:57 Comment(0)
B
1

Pretty late to the party but, i think the best approach to 500 internal server errors in CodeIgniter would be to enable the error log functionality in the Config.php file in the config folder and set a threshold value i.e. $config['log_threshold'] = 1,2,3,4 depending on the logs you want to view.

Banish answered 23/8, 2021 at 15:12 Comment(0)
F
0

This probably isn't relevant any more to this thread, but hopefully helpful to somebody. I've had 500 errors for the past hour as I had a controller return an array not supported by the php version ran on my (crappy) server. Seems trivial but had the hallmarks of a codeigniter error.

I had to use:

class emck_model extends CI_Model {

    public function getTiles(){

        return array(...);

    }

} 

Instead of

class emck_model extends CI_Model {

    public function getTiles(){

        return [...];

    }

}

Cheers

Fissionable answered 29/8, 2013 at 0:23 Comment(0)
P
0

This works fine for me

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule >
Passageway answered 27/8, 2019 at 18:20 Comment(0)
M
0

If your are using local server, this problem is faced in Wampserver when the essential modules are not enable.

You can Enable them with:

Left click on Wampsever icon

Go to APACHE -> APACHE MODULES

scroll down and find "rewrite_module" and "headers_module"

Then mark them check

It will restart automatically. Done.

enter image description here

Milieu answered 24/12, 2022 at 17:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.