Codeigniter blank page and error 500 in apache log?
Asked Answered
C

8

9

I spent over 5 hours yesterday trying to figure out whats wrong with my setup. In the ci213/application/controllers and views directories I have a simple site.php controller and test.php view. I'm out of ideas as to why this site wont load. Anyone have suggestions on what I could look for next? Maybe logging it's working properly? If I could get better log errors I could have more to work with.

I figured it has to be something with codeigniter since I have an index.php and index.html at apaches root (/var/www) and also an index2.php at the sites root (/var/www/vhosts/srp-local/htdocs), when I go to localhost/index.(php|html) or srp-local/index2.php the pages load and display properly so php and apache are working.

Trying to load the site I get a blank page so I figured it has to be something with CI. I'm tailing all the log files and the only one that gets an update is the site access.log with the following error.

127.0.0.1 - - [23/Mar/2013:09:00:28 -0600] "GET / HTTP/1.1" 500 381 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0"

config.php

$config['base_url'] = 'http://srp-local/'; # My hosts file is configured for this.
$config['log_threshold'] = 4;
$config['log_path'] = '/var/www/vhosts/srp-local/logs/ci_error.log';

controllers/site.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller
{
    public function index()
    {
        $this->load->view('test');
    }
}

views/test.php

<html>
<head>
</head>
<body>
<?php echo "PHP is working and the 'test' view was loaded"; ?>
</body>
</html>

Apache Root

/var/www/vhosts
$ ll
drwxrwsr-x  6 krizzo www-data 4096 Mar 22 10:45 it355
drwxrwsr-x  6 krizzo www-data 4096 Mar 22 17:45 srp-local

htdocs is the webroot for srp-local and it's index.php is referred to the ci213 folder.

/var/www/vhosts
$ ll srp-local/
drwxrwsr-x 2 krizzo www-data 4096 Mar 22 17:06 cgi-bin
drwxrwsr-x 4 krizzo www-data 4096 Mar 22 17:14 ci213
drwxrwsr-x 2 krizzo www-data 4096 Mar 22 17:19 logs
drwxrwsr-x 5 krizzo www-data 4096 Mar 22 17:26 htdocs

All log locations/permissions

/var/log/apache2/
    -rw-rw-rw- 1 www-data adm     0 Mar 23 08:52 php_errors.log
    -rw-r----- 1 root     adm 12191 Mar 23 09:32 access.log
    -rw-r----- 1 root     adm  4858 Mar 23 09:32 error.log

/var/www/vhosts/srp-local/logs/
    -rw-r--r-- 1 root   www-data  3227 Mar 22 19:42 error.log
    -rw-rw-r-- 1 krizzo www-data     0 Mar 23 09:37 ci_error.log
    -rw-r--r-- 1 root   www-data 12983 Mar 23 09:38 access.log

php.ini file settings

error_reporting = E_ALL & ~E_DEPRECATED
log_errors = On
error_log = /var/log/apache2/php_errors.log
Chavarria answered 23/3, 2013 at 15:55 Comment(2)
enable error reporting in php.ini (or via htaccess or your script), set it to E_ALL, and then check php error logSemitrailer
I did have error logging enabled in my php.ini file. From phpinfo() I see "error_log: /var/log/apache2/php_errors.log" and "log_error: On".Chavarria
C
10

I finally found something that pointed me in the right direction. These two posts mentioned how CI uses the @ in the database module might be causing that issue.

php return 500 error but no error log
CodeIgniter project loads blank webpage

I disabled auto-loading the database module and the site works. Now I just have to figure out the database error I was getting that might be causing CI to fail. I'll update this answer once I figure it out.

Update: I checked the account/password and access for the database everything was working. The issue was the php mysql driver was not installed. This is my first time really using an Ubuntu system and I thought that the mysql driver would be installed with the default php package, which I was incorrect about.

After installing php5-mysqlnd and enabling the database library in CI's autoload everything works properly now. The fact that I was not getting any errors is really making me consider changing frameworks.

Chavarria answered 24/3, 2013 at 16:51 Comment(3)
Haha, oh wow lucky I finally came across this. Fresh CentOS 6.4 install and there was nothing in any apache error log about the 500 errors for my CI site. doing a 'yum install php-mysql' fixed it all, blerrrgPretension
@Pretension You're my life-saver!Okinawa
if mysql driver is also installed and you are getting error, then check the mysql driver. for me, its msqli, not mysql.Balkhash
F
10

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

If you are on a shared hosting platform and do not have access to directories other than 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;

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.

Frigidaire answered 7/3, 2015 at 22:44 Comment(2)
You saved my life!Petree
Likewise. Advice on how to return more useful error messages should be the first piece of advice.Moonseed
E
4

Here is another reason why errors might not be visible:

I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.

Turned out the 500 was due to a semi colon missing in database config :-)

Engrail answered 19/12, 2013 at 7:27 Comment(0)
A
0

In my case (a cart class) it was a matter of URL, look at

/var/log/apache2/error.log

if you have something like

[client 127.0.0.1] File does not exist: ...

Then you have to prefix your class name by '/index.php/' like this

http://localhost/codeigniter/index.php/cart
Anissaanita answered 21/3, 2014 at 13:44 Comment(0)
I
0

I was also struggling with this issue.

On my new server i didn't have the php mb_string module installed.

yum install php-mbstring and then service httpd restart

Inrush answered 20/3, 2016 at 4:17 Comment(0)
O
0

in my case, the error was not displaying because display errors in php setting was not set to active. After setting it to active php error was displayed with the problem that was causing the 500 error.
Display Error

Omaromara answered 12/8, 2016 at 10:18 Comment(0)
N
0

In my case, I check the error log located in the folder logs/ of your CI project.
It happened to be a database-related error.

Noemi answered 23/7, 2020 at 4:51 Comment(0)
H
-1

I checked the php version which was 7.0.xx so I downgraded to php 5.6.xx and used the following steps to get it working for me.

sudo a2dismod proxy_fcgi proxy; sudo service apache2 restart
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
Hippocrates answered 19/1, 2018 at 11:51 Comment(1)
It doesn't make any sense to install two different versions of php. Probably you need to reinstall packages related to php5.6Tybalt

© 2022 - 2024 — McMap. All rights reserved.