Expose a directory as public but hide another same-level directory

Emmanuel Figuerola asked:

I have a web application that has the following directory structure:


This web application is installed for every new user in our VPS. They provide a subdomain name, and then a subdomain is generated, with the corresponding directory in the VPS where the web app will be stored. Every web app consists of two directories, app and public.

What I need is, for public to be, well, public, so that when the user types http://subdomain_name.ourdomain.com, the contents of public are shown to the user. At the same time, the app directory, which is on the same level as public, MUST NOT BE ACCESSIBLE to any user.

How would I go about this?

Keep in mind that the solution must be capable of being automated (every step done programmatically). I’m not asking for the automatization how-to, but the solution should be able to be executed programmatically for each web app installation, not just manually.

Additional info: Using Apache and cPanel.

EDIT for clarification: I’d like to be able to pull off a structure like the following:

/the hosting home directory
        [here goes ourdomain.com's index and such]

So, for example, user types http://webapp_charles.ourdomain.com into the browser and /[our hosting home]/webapp_charles/public is loaded. However, no visitor must be able to access /[our hosting home]/webapp_charles/app.

My answer:

As the instructions for the web framework told you, you make the DocumentRoot the public directory.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.