Error accessing site/index when using test config file

I set up my htaccess to redirect all requests to index-test.php

In index-test.php I specify the config file as test.php

In test.php I have my local DB connection set up

This set up works fine across the site, apart from when I try to access site/index

I get a CDbConnection error. It seems like site/index is going directly to the main.php config file, which contains my production server DB connection set up.

Here is actionIndex() in SiteController:


public function actionIndex()

{

	$this->render('index');

}

Anybody know how to resolve this?

Hey G I tried and it is ‘impossible’, mine works as expected. It is very weird as it is on our index.php file that main.php or test.php is used to create the application.

It maybe something on your .htaccess file?

Here is my htaccess file:


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index-test.php

And here is index-test.php:


// change the following paths if necessary

$yii=dirname(__FILE__).'/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/test.php';


// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


require_once($yii);

Yii::createWebApplication($config)->run();

OK I’ve pinpointed the problem, it’s due to a widget declration in my site layout file (main.php). This is the declaration:


<?php $this->widget('application.widgets.footerlinks.FooterLinks', array(

	'section'=>'cities',

)); ?>

And here is the widget:


<?php

class FooterLinks extends CWidget

{

	public $section;

	

	public function run()

	{

		$model=Page::model()->findAll('section=:section AND published=1', array(':section'=>$this->section));

		$this->render('application.widgets.footerlinks.view', array('model'=>$model));

	}

}

Is there something wrong with this? When I take out the widget declaration from the layout file it works fine.

What error message you get?

Error 500

CDbConnection failed to open the DB connection.

If I take out the $model=Page::model() query from the widget run() function I don’t get the error.

Enable debug mode then you should get a more detailed error message.

Could you retrieve the db information / connection string at that point and see what it says?

echo or fb Yii::app()->db->connectionString ??

Also, enable CWebLogRoute

It seems like it is trying to load index.php instead of index-test.php as the entry script, even though I have got this defined in the htaccess file.

I enabled all the debugging/profiling and I just get a Yii CDbConnection error message saying access denied for user.

Then rename/delete index.php it see what happens :D

OK I renamed index.php to index2.php, I now get a white page with a large text at the top saying "Index of /mysite"

Could this be an Apache config issue? I’m using Apache 2.2

BTW this issue is ONLY occurring on the root page - all other pages are working fine. And it only occurs when I try to use the index-test.php file.

It’s as if it try’s to load index.php before the htaccess!

It probably means - and take this with grains of salt as I’m no webserver expert - that it’s caching it.

I had a similar issue when I accidentally created a htaccess with a redirect to myserver.mydomain (literally).

It took ages until the server picked up the change… ;)

Looks indeed like apache issue.

Try this:




Options +FollowSymLinks -Indexes



Just tried that, it now gives error:

Forbidden

You don’t have permission to access /mysite/ on this server

Are you sure mod_rewrite is installed? Because before you renamed index.php, it was using index.php. Seems like it’s skipping the rewrite rules…

Maybe apache log helps?

mod_rewrite is enabled in httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

The problem only occurs on the root page, so it seems like it’s configured so that it always loads index.php on a root page request.

Just checking the error logs now.

Try adding a slash before index.php

I’m out of ideas. You could enable rewrite logging. in httpd.conf:




RewriteLog "C:\log.txt"

RewriteLogLevel 3



Here is the log (I’ve taken out most of the crap):

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] strip per-dir prefix: C:/Users/User Name/Documents/Web Sites/my-site/ ->

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] applying pattern ‘.’ to uri ‘’

(1) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] pass through C:/Users/User Name/Documents/Web Sites/my-site/

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] strip per-dir prefix: C:/Users/User Name/Documents/Web Sites/my-site/index.html -> index.html

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] applying pattern ‘.’ to uri ‘index.html’

(2) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] rewrite ‘index.html’ -> ‘index-test.php’

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] add per-dir prefix: index-test.php -> C:/Users/User Name/Documents/Web Sites/my-site/index-test.php

(2) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] strip document_root prefix: C:/Users/User Name/Documents/Web Sites/my-site/index-test.php -> /my-site/index-test.php

(1) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] internal redirect with /my-site/index-test.php [INTERNAL REDIRECT]

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] strip per-dir prefix: C:/Users/User Name/Documents/Web Sites/my-site/index.php -> index.php

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] applying pattern ‘.’ to uri ‘index.php’

(2) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] rewrite ‘index.php’ -> ‘index-test.php’

(3) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] add per-dir prefix: index-test.php -> C:/Users/User Name/Documents/Web Sites/my-site/index-test.php

[perdir C:/Users/User Name/Documents/Web Sites/my-site/] strip document_root prefix: C:/Users/User Name/Documents/Web Sites/my-site/index-test.php -> /my-site/index-test.php

(1) [perdir C:/Users/User Name/Documents/Web Sites/my-site/] internal redirect with /my-site/index-test.php [INTERNAL REDIRECT]

BTW I have this in my Apache config file:


<IfModule dir_module>

    DirectoryIndex index.html index.php

</IfModule>

This is pretty much default I think. If I remove index.php from the above it makes no difference. However if I change it to index-test.php, then it actually works… (but that isn’t really a proper fix!)

Also localhost/mysite/index-test.php works

But localhost/mysite does not work (this seems to be looking for index.php)