简体   繁体   中英

Codeigniter displays a blank page in localhost

I have cloned an application from Bitbucket and when run the application through localhost, it displays a complete blank page. When i downloaded a new codeigniter project from their website and run, it works fine and no issue. But when i run this pulled project, it displays only blank page and no errors, everything was blank.

I am working in Ubuntu 16.04 with php version 7.0

The same project works fine in another system with same configuration as above said but when pulled in new in another system it doesn't work and displays a blank page.

The base url was, $config['base_url'] = 'http://localhost/school-erp/';

Index.php file looks like,

switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
    break;

    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        if (version_compare(PHP_VERSION, '5.3', '>='))
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        }
        else
        {
            error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
        }
    break;

    default:
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

The setting model is as follows,

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Setting_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    /**
     * This funtion takes id as a parameter and will fetch the record.
     * If id is not provided, then it will fetch all the records form the table.
     * @param int $id
     * @return mixed
     */
    public function get($id = null) {

        $this->db->select('sch_settings.id,sch_settings.lang_id,sch_settings.is_rtl,sch_settings.timezone,
          sch_settings.name,sch_settings.email,sch_settings.phone,languages.language,
          sch_settings.address,sch_settings.dise_code,sch_settings.date_format,sch_settings.currency,sch_settings.currency_symbol,sch_settings.start_month,sch_settings.session_id,sch_settings.image,sessions.session'
        );
        $this->db->from('sch_settings');
        $this->db->join('sessions', 'sessions.id = sch_settings.session_id');
        $this->db->join('languages', 'languages.id = sch_settings.lang_id');
        if ($id != null) {
            $this->db->where('sch_settings.id', $id);
        } else {
            $this->db->order_by('sch_settings.id');
        }
        $query = $this->db->get();
        if ($id != null) {
            return $query->row_array();
        } else {
            return $query->result_array();
        }
    }

    /**
     * This function will delete the record based on the id
     * @param $id
     */
    public function remove($id) {
        $this->db->where('id', $id);
        $this->db->delete('sch_settings');
    }

    /**
     * This function will take the post data passed from the controller
     * If id is present, then it will do an update
     * else an insert. One function doing both add and edit.
     * @param $data
     */
    public function add($data) {
        if (isset($data['id'])) {
            $this->db->where('id', $data['id']);
            $this->db->update('sch_settings', $data);
        } else {
            $this->db->insert('sch_settings', $data);
            return $this->db->insert_id();
        }
    }

    public function getCurrentSession() {
        $session_result = $this->get();
        return $session_result[0]['session_id'];
    }

    public function getCurrentSessionName() {
        $session_result = $this->get();
        return $session_result[0]['session'];
    }

    public function getCurrentSchoolName() {
        $session_result = $this->get();
        return $session_result[0]['name'];
    }

    public function getStartMonth() {
        $session_result = $this->get();
        return $session_result[0]['start_month'];
    }

    public function getCurrentSessiondata() {
        $session_result = $this->get();
        return $session_result[0];
    }

    public function getDateYmd() {
        return date('Y-m-d');    }

    public function getDateDmy() {
        return date('d-m-Y');
    }

}

What could be the error and kindly help to solve it.

You need to check few things:

  • base_url
  • htaccess RewriteBase
  • permissions
  • add error_reporting(1) in index.php and see what errors are reporting

In case 'production': change ini_set('display_errors', 0); to ini_set('display_errors', 1); in index.php

Lot of things could be happening:

1) You must have an .htaccess file on your project root label (school-erp in this case). Open the .htaccess file and paste:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) school-erp/$1$2 [R=301,NE,L]

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

2) Check your database.php file. You can find it in school-erp -> application -> config -> database.php

It is extremely important the same database name, password and user in this file and on your DBMS have the database created with these same parameters. Remember codeigniter won't show any page if you have a config string on database.php that currently not match with what you have on your DBMS.

3) Open a terminal as root user then change directory to the current path of your project which this way:

cd var/www/

Then you must give the necesary permisions to school-erp folder and all contained in it. You can do it using this instruction:

chmod 667 school-erp -R

Be carefull with the permision code you give to your files... chmod 777 isn't appropiate to production enviroments (I don't even use it on my localhost).

4) Your current base_url will work if you have this folder structure (I will post it as a path):

var/www/school-erp

Why I say this? because some server instalations come with an extra folder level. This folder is called normally "html". If this happens the path will be changed to:

var/www/html/school-erp

Which means you will need to change your base_url too.

5) Check in the other system the navigation bar of the browser when you enter to the index of the project (localhost/school-erp) if it doesn't appear "index.php" in the url it means that the server is rewriting the url so you will have to follow step 1) I posted on this answer plus turning on the a2enmod rewrite of apache server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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