Trouble Shooting Codeigniter on localhost

To run codeigniter on localhost on a Windows Machine

Don’t forget to a) stop and restart your servers if you change server config.
b) Force a browser reload when getting all pages

If your not familiar with this, its the first place to start:

Codeigniter is a php MVC framework

behind the scenes everything goes through index.php and working with the rewrite rule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]

URI Segments

The segments in the URL, in following with the Model-View-Controller approach, usually represent:

controller class that should be invoked.
class function, or method, that should be called.
represent the ID and any variables that will be passed to the controller. / controller-class / controller-method / arguments

You do not directly access php files like / application / controllers / about

if you want to access something, you use a url


in application/controllers there is a file Portfolio.php that has this class definition

class Portfolio extends Public_Controller

CI knows by convention ( classes in files of that name, it knows to load portfolio.php because of stuff in config etc.)

and it has a method

function display($page=0, $whichID=0, $username=0)
log_message(‘debug’, ‘~display portfolio.php ‘.$page. ‘ id ‘.$whichID.’ username ‘.$username);


so when you access

it starts with index.php, index.php does its magic and loads portfolio.php to get at class portfolio and method display

—  More on URI segments —

The URI Class and the URL Helper contain functions that make it easy to work with your URI data.
In addition, your URLs can be remapped using the URI Routing feature for more flexibility.

If your URI contains more then two segments they will be passed to your function as parameters.
Your function will be passed URI segments 3 and 4 (“sandals” and “123”):

class Products extends CI_Controller {

public function shoes($sandals, $id)
echo $sandals;
echo $id;

First check your  C:\Windows\System32\drivers\etc\hosts

It should look something like this:

# localhost name resolution is handled within DNS itself.       localhost
::1             localhost


Next run a PHPINO
<?php phpinfo() ?>

we may refer to this later

next check the index.php file in the html root (www or htdocs etc) for your CI application

review to see what error reporting and dev environment may be setup, example below

if (strpos($_SERVER[‘SERVER_NAME’], ‘localhost’) === 0) {
define(‘ENVIRONMENT’, ‘development’);
define(‘ENV_LOCAL’, ‘local’);
} else {
define(‘ENVIRONMENT’, ‘development’);
//define(‘ENVIRONMENT’, ‘production’);
define(‘ENV_LOCAL’, ‘local’);

* —————————————————————
* —————————————————————
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.

if (defined(‘ENVIRONMENT’)) {
switch (ENVIRONMENT) {
case ‘development’:

case ‘testing’:
case ‘production’:

exit(‘The application environment is not set correctly.’);


Next we are looking for the rewrite rules
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]

check to see if you have an .htacess file with something like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]

If its not in an .htacess, its probably in one of the many apache config files or files included by it


My bitnami conf that is loaded into apache has this

Alias /coverbycover/ “F:\bit5411/apps/coverbycover/htdocs/”
Alias /coverbycover “F:\bit5411/apps/coverbycover/htdocs”

<Directory “F:\bit5411/apps/coverbycover/htdocs”>
Options +MultiViews +FollowSymLinks
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
<IfVersion >= 2.3>
Require all granted
RewriteEngine On
RewriteBase /coverbycover/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /coverbycover/index.php [L]

# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
#RewriteEngine On
#RewriteRule ^/$ /coverbycover/ [PT]

next check \application\config\config.php

for something like this

locahost or 127.0.01.

$config[‘base_url’] = ‘http://&#8217; . ‘localhost/ xxxxxxxxxx’;

Its a real simple thing, but, if the base url is localhost,
make sure you access it by http://localhost/xxxxxxx/

check $config[‘uri_protocol’] = ‘AUTO’;
if auto is not working, “try one of the other delicious flavors:”

turn on logging
| Error Logging Threshold
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|    0 = Disables logging, Error logging TURNED OFF
|    1 = Error Messages (including PHP errors)
|    2 = Debug Messages
|    3 = Informational Messages
|    4 = All Messages
| For a live site you’ll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
$config[‘log_threshold’] = 4;

next lets see if we can write stuff to the logs

add the following to root index.php

echo “<HR>”;
$msg1=” test write to error_log: “.ini_get(‘error_log’);
echo $msg1.” <BR>”;
if (error_log($msg1,0)) {
echo “wrote to error_log <br>”;
} else {
echo “could not write to error_log<br>”;

log_message(‘debug’, ‘~this is a test of CI logging’);


//CI programmers use lots of array, like in the next few lines see $data,  here is how to log the array

$data[‘pagination’] = $this->pagination->create_links();

$data[‘header_title’] = ‘Covers for ‘.$username;

//use var_export to write the array to a variable

$dump = var_export($data, true);

// log the variable

log_message(‘debug’, $dump.’ ~displayPages application controllers portfolio.php’);

//or do it like this and put the dump at the end of the string

$v = var_export($result, true);

log_message(‘debug’, “~delete controlers manage covers v “.$v);

//or make it more readable

foreach ($results as $key => $value) {
log_message(‘debug’, $key.”=”.$value.’ ~preview home.php’);
$querystring .= $key.”=”.$value;


access your index.php through something like http://localhost/CIName/

find the error_log file

If that does not solve your problem you next look to see if you have
Application/config/routes.php or something similar.

$route[‘news/(:any)’] = ‘news/view/$1’;
$route[‘news’] = ‘news’;
$route[‘(:any)’] = ‘pages/view/$1’;
$route[‘default_controller’] = ‘pages/view’;

->Routing     ->Security    ->
index.php       |
<-Caching      <-View          <- Controller


Find your apache log files and review them



I use a bat file to delete the all my log and trace files, it makes it real easy to find things
1) stop servers
2) run bat

@echo on
del F:\bit5411\apache2\logs\access.log
del F:\bit5411\apache2\logs\error.log
del F:\bit5411\mysql\data\SandyBridge.err
del F:\bit5411\apps\gjapps\php_errors.log
del F:\bit5411\apps\coverbycover\htdocs\application\logs\*.php
rem need admin priveleges del F:\bit5411\php\tmp\*.*
del F:\xdebug\trace\*.xt


Are you have problems finding resources?

Do you think you have error reporting on when CI is subsequently turning if off?


Next review your database config file


do you have the right DB selected

check with PHPMYADMIN

Xdebug with codeigniter
add this to root index.php

ini_set(‘xdebug.collect_vars’, ‘on’);
ini_set(‘xdebug.collect_params’, ‘4’);
ini_set(‘xdebug.dump_globals’, ‘on’);
ini_set(‘xdebug.dump.SERVER’, ‘REQUEST_URI’);
ini_set(‘xdebug.show_local_vars’, ‘on’);
ini_set(‘xdebug.default_enable’, ‘on’);
ini_set(‘xdebug.max_nesting_level’, ’50’);
ini_set(‘xdebug.scream’, ‘on’);
;ini_set(‘xdebug.trace_options’, ‘on’);
ini_set(‘xdebug.trace_format’, ‘on’);
ini_set(‘xdebug.collect_return’, ‘on’);
ini_set(‘xdebug.collect_includes’, ‘on’);
ini_set(‘xdebug.collect_parms’, ‘4’);
ini_set(‘xdebug.var_display_max_children’, ‘128’);
ini_set(‘xdebug.var_display_max_data’, ‘-1’);
ini_set(‘xdebug.var_display_max_depth’, ‘-1’);
ini_set(‘xdebug.dump_globals’, ‘on’);

//not sure this works,but turning on xdebug_enable(); works

ini_set(‘xdebug.auto_trace’, ‘on’);

try {
if (xdebug_is_enabled()) {
echo ‘stack traces are enabled – debugging<BR>’;
echo ‘xdebug_memory_usage() ‘. xdebug_memory_usage().'<BR>’;
} else {
echo ‘not debugging<br>’;

} catch (Exception $e) {
echo ‘Caught Exception -> message: ‘, $e->getMessage(), “\n”;
// or if extended over ridden exception var_dump e->getMessage()

and set it in php.ini
auto_trace has to be on or 1 and you have to restart the apache

check for this
and where the zend_extension is

zend_extension = F:\bit5411\php\ext\php_xdebug-2.2.1-5.4-vc9.dll