Shared stuff behind public_html, a good idea?

I just played around with my hosting (based on Cpanel). I discovered that I can place a subdomain outside the public_html folder. I could then also access it from a domain. I have more than one domain (in public_html) on that server. It means that I could have shared files on that hidden subdomain. Would that be a good idea? Pros, cons?

For example, I can put plugins there that I use on more than one domain. Then when I update the plugin, I do that for two domains (or more) at ones. That’s because both my domains point on the same plugin folder in the hidden subdomain.

I read in the docs that I can put the content folder outside the root, to protect the files. In this case I’m interested in the shared files perspective. I hope you will share some thoughts around this topic.

Where have you read that?

Here: https://getkirby.com/docs/developer-guide/configuration/folders#changing-the-site-folder

Now I see that it was about moving the whole site below the public_html.

Do you have any experience/thoughts on my topic?

The content folder cannot be moved outside the webroot in K2, because it contains files (images etc) that must be publicly accessible.

I don’t know your server settings, of course you can usually point a domain to another folder then public_html, thus making this a separate web root. So the same applies as to any web root. I guess the reason you want to make this folder accessible via URL is to serve assets like plugin JS and CSS files? Otherwise, you wouldn’t need a domain. However, if you do use a different domain, you might run into CORS issues when serving those resources.

In what way your domain would be hidden, I don’t understand.

This is the type of things I LOVED to do but then I realized that some optimizations are not really worth it.
Because you end up tying multiple things together and if something goes wrong (and we’re talking code so something WILL go wrong), fixing things becomes a pain.

As for your main question, I don’t have much experience with “exotic” server configurations but I don’t really see why it would make things easier. It sure would make things faster if you split all the assets in different folders and use those as subdomain to load js, css, fonts and so on.

I think if it was me, I would just make a folder on the server, put all my plugins or shared stuff in there, and use symlinks rather than a custom kirby setup or domain setup. Far simpler. But I do agree with @manuelmoreale - sometimes going to all that trouble is more trouble later on then its worth.

1 Like

I’d also rather keep projects together then do all this sharing stuff, I don’t really see an advantage, especially if you manage plugins via composer in the long run.

2 Likes

@texnixe
Yes, I don’t need to create a sub domain, I figured it out. I just needed to create a new FTP account with a shorter path to get full access to the folders outside the root.

@texnixe @manuelmoreale
No, my reasons was not to use it as a CDN kind of thing, but good to have that input as well.

@jimbobrjames I’ve not worked with symlinks. I’ll probably stay out of it for now.

I’ll try to explain more around my thoughts. It’s not about spreading out JS/CSS resources. Let’s say I build a script or a function. That function will be updated from time to time and will be used on 3 sites. So instead of updating all 3 sites, I’ll update only one, the hidden folder. Or maybe I have 10 scripts/functions like that.

@texnixe Composer is probably another way. I’ve tried it a few times, but I’m no expert in it yet.

include __DIR__ . '/../../my-hidden-folder/functions.php';

Well with symlinks you can make individual files or entire folders appear as if they belong inside your domain, but the files can be anywhere on the server. When you FTP into that site, it looks and feels like its in that project. You don’t need to get clever with the paths to things either - as far as the server is concerned, those files are in your domain, not elsewhere. It’s just a simple terminal command to make a symlink, nothing scary. You can use it for shared plugins and your common functions.

1 Like

Still, the question is if it is worth it. If you move a project to another server, you have to think about moving those dependencies as well. Guess it all depends how you handle your projects. But if your plugins/shared functions are under version control and you either add them as submodules or via composer, then this stuff all updates itself within your usual update routine.

1 Like

So now we have 3 ways to do it:

  1. Put a folder outside the root. Debate if it’s worth it. The benefit would be that it’s instantly updates everywhere.
  2. Use symlinks. I found a good resource for how to do it with Cpanel: https://www.namecheap.com/support/knowledgebase/article.aspx/9561/29/how-to-create-a-symbolic-link-in-cpanel
  3. Use updates with Git/Submodules/Composer.