Setup existing yii project to work on localhost

Hi all,

I’m completely new to yii so please pardon my lack of knowledge and information.

I’m practicing web development and I got access to a friend’s website. I wanted to play with it on my localhost (using XAMPP on Windows) and found out that it uses yii. When I try to run index.php, I’m getting a page that just says:

CDbException

CDbConnection failed to open the DB connection.

I think that (obviously) I have to set up the existing database of the website. I’ve done a bit of searching but I’m confused and struggling with where to start. Is there any guide that I can follow to fix the issue? I just want to get it running first.

Thanks everyone.

Hi @mikepham, welcome to the forum.

I have some questions before I start. Would you please answer them?

  1. Do you have full access to the source code of the site of your friend?
  2. Do you want to learn Yii 2.0 or Yii 1.1?

'CDbConnection` is a component of Yii framework 1.1. So the site of your friend is running on Yii 1.1. If you are new to Yii and want to learn it, I would rather recommend you start learning Yii 2.0 from scratch following the definitive guide. https://www.yiiframework.com/doc/guide/2.0/en

As for the current problem, you could check the source code. See config\main.php file for the configuration of db component. It should be something like:

    'components' => array(
        ...
        'db' => array(
            'connectionString' => 'mysql:host=localhost;dbname=xxxx',
            'emulatePrepare' => true,
            'username' => 'xxxx',
            'password' => 'xxxx',
            'charset' => 'utf8',
            'schemaCachingDuration' => 60 * 60 * 24 * 30,
        ),

You have to create a db connection according to the information provided there.

Hi softark,

Thank you for your response.
As for the questions,

  1. Yes I do
  2. I’m actually helping my friend developing something for his website, but it’s really not imperative that I have to do it. I’m a student and I just want to get started and develop my skills with a ‘real world’ project, so for now, I would be more interested in Yii 1.1. I might learn Yii 2 afterwards and might learn how to upgrade the website from Yii 1.1 to Yii 2.

Also, as for your answer, I just want to make sure that I have to create the database, grant access to the username and password beforehand right?

Thank you.

Yes, that’s right. If I were you, I would ask your friend for a backup of the relevant db tables, or at least a setup script that would create the necessary tables for the site.

P.S.
I have moved this thread to Yii 1.1 - Installation and Setup

Hello @softark and @mikepham

i am completely new to yii as well. i have a complete source code with yii2 framework (version - 2.0.13.1). i have configured the db array with necessary details ( ‘dsn’ => ‘mysql:host=localhost;dbname = yidb’). and tried to launch it using xampp on windows. but when i try to login the application does not seem to work.

all i did was copy the source code into htdocs and tried to access it through chrome via xampp.
i am not sure where i went wrong. your insight would be really helpful.

i am getting several errors like

  1. 404 notfound.
  2. from origin ‘http://localhost:8000’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http,
  3. CORS error while trying to login

Thank you