Question about Yii's directory structure

Hello guys! I read the wiki article about the directory structure of yii. I found it very amazing but I have some confusion about it that i wanted to get clarified.

My questions are the following:

  1. In the entry script index.php, from what config files do you include?.. the ones on the frontend? Or the ones on the common folder?

  2. Do you have to use path aliases all the time when including classes (like including classes from common to the frontend) or you should import them first in the config files?

  3. Is it necessary that you change properties such as basePath, runtimePath, extensionPath, controllerPath, and etc. to make the directory structure work?

  4. On what folders you should modify .htaccess to "deny from all"?

  1. The entry script should use the config file for the corresponding app. That is, the frontend index.php should use frontend’s config, and so on.

  2. You can import several path aliases in config, such as site.common.models., site.common.components.

  3. You only need to configure ‘basePath’ so that it points to frontend for the frontend app.

  4. You set webroot to be frontend/www. As a result, you don’t need “deny from all” in .htaccess because non-www files are not exposed to end users.

First of all, thank you so much qiang!! ;D

  1. I don’t quite understand it a bit. You mean the index.php found on frontend/www? How about in the common folder? Does it also have an index.php file? Or in frontend config, you import the files found on common?

How about the index.php on the top-level folder?

  1. So how is it going to look like in the address bar? http://localhost/frontend/www/index.php? How to set webroot to be frontend/www? Is it through .htaccess?

My questions seems to be somehow non-sense. I apologize for that. It’s just that I somehow don’t understand quite a few things pertaining to this. :)

Hi qiang,

If you set webroot to frontend/www, what url do you use to access backend/www?

I have another question. What should be in the application bootstrap index.php?.. how should it differ from the index.php found on the backend and frontend?

Each index.php will require different configuration files, which sets different paths as basePath.

You should configure the virtual host of your webserver for give access to frontend and backend.

For example www.mysite.con should be virtual-hosted in frontend, while backend.mysite.con should be virtual-hosted in backend.

how to access the front-end?.. for example, http://localhost/frontend/www/index.php ??.. like the one on the yii site


if you look at the wiki article you will see in the hierarchy an index.php file found in the "www" folder in "frontend".

I’m confused if whether that’s the application entry script or not (qiang said the the www is the webroot for that application).

If it is the entry script, we access it using http://localhost/appName/frontend/www/index.php right?.. (assuming it is located in localhost) …

How should it be done so that it would just be http://localhost/appName/index.php ??

If you want this solution, use the gii generated architecture.

This article is meant for different situation: you shuld configure Apache to use different forlder for different virtual host.

In a local machine you should edit the host configuration in order to create some faked test domani, like

local.application.com => virtual host in frontend/www

backend-local.application.com => virtual host in backend/www

Is not a question of Yii configuration, is a question of apache.

Setting up Apache VHost was the answer indeed. Don’t forget to modify the Windows host file (if working working on a Win machine) - usually located at: C:\Windows\system32\drivers\etc\hosts.

Can now access http://backend.localhost/.

Cheers