Skip to main content

Is Git Repo Above Document Root OK?

Comments

16 comments

  • cPanelMichael
    Hello, The issue you may run into is that future versions of cPanel could lead to new files/directories in the account's home directory. Thus, you'd then need to manually edit the .gitignore file again to account for that. Generally, the better approach would be to setup the primary domain name to be something such as "dev.domain.tld" and then add "domain.tld" as an addon domain name. With this approach, you can easily adjust the document root of the addon domain name directly via the cPanel UI. Thank you.
    0
  • bgarrant
    Hello, The issue you may run into is that future versions of cPanel could lead to new files/directories in the account's home directory. Thus, you'd then need to manually edit the .gitignore file again to account for that. Generally, the better approach would be to setup the primary domain name to be something such as "dev.domain.tld" and then add "domain.tld" as an addon domain name. With this approach, you can easily adjust the document root of the addon domain name directly via the cPanel UI. Thank you.

    Can we remove the public_html folder and use a symbolic link like many have done with Laravel? Will that break anything? All I see in it is a .well-known folder rm -rf public_html ln -s laravel/public/ public_html
    See: joshmountain.com/blog/installing-laravel-and-composer-on-a-cpanel-server
    0
  • cPanelMichael
    Hello, It's unsupported, but it is a common method used in relation to application development since there's no native method of changing the primary document root. Thus, it should work, but it's possible for issues to arise. For instance, there's an internal case (CPANEL-17484) that's fixed in cPanel version 72 where systems using custom ACL settings in "WHM >> Tweak Settings" in combination with accounts using public_html symlinks can result in the "File Protect" feature not applying the custom ACL settings for files inside the symlinked document root. Thank you.
    0
  • bgarrant
    @cPanelMichael With your first suggestion, can I make a folder outside of public_html to be used for a addon domain doc root? For example, if I create a folder call `project` and it has a `public` folder within it, can I make the `public` folder the doc root so nothing out side of it is accessible? Like this: project |--local |--public |--|-- assets |--|-- index.php |--|-- .htaccess |--site |--statamic |--please |--.gitignore public_html (original doc root) I do not want the site, statamic, please, local files to be accessible
    0
  • cPanelMichael
    Hello, Yes, that's possible as long as the following option is disabled under the "Domains" tab in "WHM >> Tweak Settings": Restrict document roots to public_html Thank you.
    0
  • bgarrant
    @cPanelMichael Is there any plans to ever allowing changing of the doc root for primary domains? With all the platforms and CMS systems out there it just seems like it is necessary.
    0
  • cPanelMichael
    @cPanelMichael Is there any plans to ever allowing changing of the doc root for primary domains? With all the platforms and CMS systems out there it just seems like it is necessary.

    Hello, We do have an existing feature request to include a supported method of changing the document root associated with the domain name utilized during account creation. I encourage you to vote and add feedback to this feature request at: Allow users to change the DocumentRoot Thank you.
    0
  • bgarrant
    Hello, We do have an existing feature request to include a supported method of changing the document root associated with the domain name utilized during account creation. I encourage you to vote and add feedback to this feature request at:
    0
  • Haym
    The options for this right now are:
    • Change the primary domain and use an addon domain.
    • Symlink the public_html directory to the desired location (works fine).
    It's an increasingly common issue and one which is important for cPanel to resolve if they don't want (inexperienced) cPanel users to think the product isn't suitable for modern applications, I'll add my vote to the feature request.
    0
  • bgarrant
    The options for this right now are:
    • Change the primary domain and use an addon domain.
    • Symlink the public_html directory to the desired location (works fine).
    It's an increasingly common issue and one which is important for cPanel to resolve if they don't want (inexperienced) cPanel users to think the product isn't suitable for modern applications, I'll add my vote to the feature request.

    Thanks @Haym What is the best way to make the Symlink? What about the .well-known folder in it? Does it matter?
    0
  • bgarrant
    The options for this right now are:
    • Change the primary domain and use an addon domain.
    • Symlink the public_html directory to the desired location (works fine).
    It's an increasingly common issue and one which is important for cPanel to resolve if they don't want (inexperienced) cPanel users to think the product isn't suitable for modern applications, I'll add my vote to the feature request.

    I deleted the public_html folder, and created a symlink with this: ln -s www_domain/public_html public_html
    Is this all I need to do? Will cPanel try to recreate the original public_html folder?
    0
  • cPanelMichael
    Hello, The symbolic link won't be removed with cPanel updates, but note it's an unsupported modification so it's not something we test against. Generally, the addon domain name workaround is the best approach if you want to ensure it works in a supported environment. Thank you.
    0
  • bgarrant
    Hello, The issue you may run into is that future versions of cPanel could lead to new files/directories in the account's home directory. Thus, you'd then need to manually edit the .gitignore file again to account for that. Generally, the better approach would be to setup the primary domain name to be something such as "dev.domain.tld" and then add "domain.tld" as an addon domain name. With this approach, you can easily adjust the document root of the addon domain name directly via the cPanel UI. Thank you.

    What about using a reverse .gitignore file to only "include" the file and folders I want? Would that be a better approach? # Ignore Everything * # Except these files and folders !.git !.gitignore !/local/cache/ !/local/storage/ !/local/temp/ !/public_html/** !/site/** !/statamic/** !LocalValetDriver.php !mix-manifest.json !package-lock.json !package.json !phpunit.xml !please !webpack.min.js
    0
  • bgarrant
    No. Only the things checked into the git repository would come down when you perform a git-pull from another machine. well yes. So it's mildly complicated but basically you'll want to list any paths you don't want git to care about in the .gitignore so that changes in those areas aren't reported as unstaged. I'm not sure what Statamatic's recommendations are for a .gitignore but it's pretty typical for tools like Statamatic to publish a good starting example .gitignore. If Statamatic is rendering content into the $PROJECT_ROOT/public folder, then I bet it would need to be listed in your .gitignore...but, again, you're more of a Statamatic expert than I.

    @cPanelAdamF @cPanelMichael So I took your advice and installed a git repo above webroot in the ~/
    . See: # Ignore Everything * # Except these files and folders !.git !.gitignore !/local/cache/ !/local/storage/ !/local/temp/ !/public_html/** !/site/** !/statamic/** !LocalValetDriver.php !mix-manifest.json !package-lock.json !package.json !phpunit.xml !please !webpack.min.js
    This shortens it up a lot and makes it so that it is independent on cPanel files/folders. What do you think of this approach? Is there a better way I am not thinking of?
    0
  • bgarrant
    @cPanelAdamF @cPanelMichael Is there a better way to do this? I know you are working on some things for future cPanel upgrades. Biggest issue really is the .gitignore file. If you need your files above webfoot it get's huge with all the folders/files you need to ignore from cPanel. It would be great to have a better way to use Git, and have files above the webfoot. I can't really use domain add-on method as it would mess up our WHMCS billing system that creates an account for each primary domain.
    0
  • cPanelMichael
    This shortens it up a lot and makes it so that it is independent on cPanel files/folders. What do you think of this approach? Is there a better way I am not thinking of?

    I don't see any obvious problem with this approach. I recommend testing it out on a non-production account first to verify it works as expected. Thank you.
    0

Please sign in to leave a comment.