About Kirby folder structure

I know about setting custom folder paths in Kirby:

http://getkirby.com/docs/advanced/customized-folder-setup

Folder structure question

The question is why Kirby folder structure don’t look like this by default (files are not shown here)?

kirby
custom

That will totally separate your code from Kirby core files.

Unfolded directory

Just to show you that the panel some other stuff still exists I show you this…

kirby
    panel
custom
    assets
    content
    kirby
    site
    thumbs

Why have more than two folders in the root? Often we don’t want to hack the core files anyway.

Is the second occurrence of kirby really right?

It might be useful to form three top level directories:

kirby
    panel
custom
    assets
    site
files
    accounts
    avatars
    cache
    content
    thumbs

Only the subdirectories of the new directory files need write access for the webserver, e.g. if you use the panel or the kirby cache.

This structure can also be useful for data backup, if the directories in custom rarely receive changes.

Feel free to rename the directory files.

Hint:
The subdirectories in files have been moved from your directory custom or its subdirectories.

1 Like

I like that the content folder is separate, because it contains everything the users create and modify. Easy to backup and version when we update sites.

2 Likes

@Malvese I agree, I also like to have the content folder separately for Git versioning. It might also make sense to move templates and stuff out of the web root as suggested elsewhere. As for the rest, maybe there are as many preferences as there are developers. For my part, I don’t really care if the stuff is in 2, 3 or 4 different folders, in fact, if I have content and the rest in 2 repos, I end up with only 2 folders in my web root anyway:)

@anon77445132 I agree that it’s great to separate the “generated” content from the rest.

@Malvese @texnixe Agree! With this structure it still is, just that it’s in a sub folder.

For me this structure makes the most sense to me…

  • Kirby - Separate Kirby core files from the rest. The panel goes in here as well.
  • custom - Everyting else that we do, template, content and other custom stuff.

Sub folders

  • site - The assets folder are now at the same level as templates and snippets.
  • files - Separate “files” (which are generated content) from the template stuff

Structure

kirby
    panel
    other core folders
custom
    site
        assets
        controllers
        plugins
        snippets
        templates
    files
        accounts
        avatars
        cache
        content
        thumbs

It always feels weird to me to add a folder to the gitignore list, then version it in another repository. Perhaps it’s clean and I’m too cautious :smile:

Btw, has anyone tried using a git submodule for the content folder?

I hadn’t thought about it but one thing I’d like to move is the accounts folder, because users with admin rights can create users and I don’t want to risk losing or overwriting them when I update the site.
Unfortunately there is no way to move that folder in Kirby core. I guess I could try to use a symlink instead.

Curious how you set up your folder structure, could you share it?
Do you keep content inside the web root, and change the path in /site.php or with symlinks?

Pretty basic, in fact; as I mentioned above, with just a content folder and a “theRest” folder in the web root or even within a project folder and changing the path in site.php. Haven’t really experimented with putting stuff outside the web root yet.

Thank you. I actually have a little trouble setting it that way.

So your Kirby install is in a subfolder of your web root. How would I make mydomain.com point that subfolder instead of the web root? Another .htaccess file with a redirect on the web root?

Also, how do I go up one level in site.php? Not sure relative paths work, like: $kirby->roots->content = $kirby->roots()->index() . DS . '../content';

I think it depends on your client’s hosting provider. If you use shared hosting with the domain name included, you sometimes cannot point the main domain to anything else than the web root. Then in such a case, you have to live with that and certainly not move anything outside the web root anyway or persuade your client to move to another provider, or keep domains and hosting provider separate (that’s actually what I do with my personal domains, they live separately from where I host my stuff, so I can point them to whatever server I want).

They do, for sure. :slight_smile:

You can: Simply set $kirby->roots->accounts to your desired destination.
Right now, this doesn’t work for every directory, but it might work very soon.

2 Likes

Oh good, I didn’t know accounts could have a custom path (it’s not in the docs). Thank you @texnixe and @lukasbestle, you help me a lot :smile:

Yeah, that feature has been added by another PR by @fanningert in April.
I have created an issue about the missing docs in the getkirby.com repo.