Advanced template: what's the right folder structure?

Actually I’ve done this

Version A


-- advanced

   -- backend

   -- frontend

   -- common

   -- ...

-- tests

-- vendor

I noticed there is a composer.json into htdocs and a composer.json into advanced

I notiiced also there is a vendor folder under htdocs and under advanced

Was my structure wrong?

Was these more correct ?

Version B


-- backend

-- frontend

-- common

-- tests

-- vendor

I’m asking this because of a problem with a specific extensione and because of duplication of vendor folder

What’s the right? Version A or Version B?

B is like default structure except you put all code directly in web root folder (you do not have parent folder like ‘myApp’). Why the hell are you doing that ? :o

Anyway, whatever works for you is the best.

Both are wrong. Server webroot should have only entry scripts and publicly accessible files such as assets.

I’m doing this

  1. Enter into htdocs

  2. Install composer

  3. Install yii. After this i’ve composer.json, composer.phar and the vendor folder under htdocs

  4. I create project advanced. So i’ve add htdocs/advanced now

What was NOT clear to me is that I can ( I MUST) delete root composer.* and root/vendor folder

I just tried and all is working well (and the yii2-admin extension now works… )

So i’ve now only a ‘flat’ index.html into the htdocs root and i’ve created the virtual hosts pointing to ‘advanced/frontend/web’ and to ‘advanced/backend/web’.

Please, consider this is my development environment and I’ve not yet read about deploying an advanced app.

Also, my production server has 100+ folders into server root, but of course we’ll point the ‘webroot’ of single domains to the right dir

Is this right?

Sounds OK. You could actually run Yii with almost any structure you create. The issue with placing code and configs into webroot is possible security breach.

Yes, I understand, thank you a lot.

This is my development environment, in production I’ve a shared host (sigh… :( ) so server security actually it’s not a my problem. Client forced me to use THIS production server…

You still can try to do it right as I’ve described at

Yes, I’ll do exactly what you have written, because my shared host bring me the problem of cannot have ‘frontend’ and ‘backend’ divided into 2 subdomains (like I’ve done in other situations)

I’ve a problem now.

My shared host give me only an empty root directory.

It expect I’ve my index.php or index.html file here.

So renaming ‘frontend’ as www and moving backend as frontend/admin cannot work.

What can I do?

Can’t you go one level above it?

There is absolutely no control panel for this situation.

I explain. I’m on

The main domain has full access to every kind of config

If you create a subdomain, like, will create a /public/yii2 folder, and there is no way, I think, to force to point to /pubic/yii2/<something>

Sigh :(

I’ll definitively ask for a new host

Well, if there’s support for .htaccess you may try putting index.php into root directory while putting everything else into “protected” that will be denied for web access.

Ehm… yes, .htaccess is admitted and fully supported (they said me)

Can you please write me what must I put into it? I’ve no experience about it

It’s better to learn about it a bit. It can go very bad otherwise.