Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is Git Repo Above Document Root OK?

Discussion in 'General Discussion' started by bgarrant, Jan 22, 2018.

Tags:
  1. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    I have Statamic CMS driven site that stores some files above the doc root like so:

    ~/ folder structure
    Code:
    .cpanel
    .cphorde
    .git -- repo created with `git init`
    .htpasswds
    .pki
    .ssh
    .trash
    access-logs
    etc
    local --Statamic Files
    logs
    mail
    perl5
    public_ftp
    public_html
    |-- assets - Statamic files
    |-- index.php - Statamic files
    |-- .htaccess - Statamic files
    site --Statamic Files
    ssl
    statamic -- Statamic Files
    tmp
    www
    .bash_history
    .bash_logout
    .bash_profile
    .bashrc
    .contactemail
    .env
    .gitignore -- Statamic Files
    .lastlogin
    .viminfo
    .zshrc
    please
    
    Is it OK to run the `git init` in the ~/ location (above doc root) like this? It works well since I have other files in the public_html folder and it keeps my core Statamic folders/files above doc root as recommended here: Installing and running above webroot - Knowledge Base - Statamic 2 Docs.

    My .gitignore is a bit long as I exclude all the cPanel stuff:

    Code:
    .DS_Store
    .env
    node_modules/
    bower_components/
    local/cache/*
    local/storage/*
    local/temp/*
    installer.php
    # cPanel
    /.cpanel/
    /.cphorde/
    /.htpasswds/
    /.ssh/
    /.trash/
    access-logs
    /etc/
    /logs/
    /mail/
    /perl5/
    /public_ftp/
    /public_html/error_log
    /ssl/
    /tmp/
    www
    /.bash_history
    /.bash_logout
    /.bash_profile
    /.bashrc
    /.contactemail
    /.gitconfig
    /.lastlogin
    /.viminfo
    /.zshrc
    
    SO, since I want to control the site with Git and I also want to keep the core Statamic folder above the doc root is this a good way to do it? It seems to work fine. I tried to install git to a subfolder instead of ~/ and I was unable to get my Statamic folders/files in /public_html to link up correctly.

    I have many other sites I want to use git for with core files for the CMS above the doc root. Is this the best way of is there some other method I should use? I know I could change the document root location, but isn't that NOT RECOMMENDED for a primary domain?

    What do you recommend for best practices when using git and cPanel this way?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  3. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    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

    Code:
    rm -rf public_html
    ln -s laravel/public/ public_html
    
    See: joshmountain.com/blog/installing-laravel-and-composer-on-a-cpanel-server
     
    #3 bgarrant, Jan 22, 2018
    Last edited by a moderator: Jan 22, 2018
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  5. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    @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
     
    #5 bgarrant, Jan 22, 2018
    Last edited: Jan 22, 2018
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  7. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    @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.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  9. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    @cPanelMichael I added my vote and opinion. What are the odds of this happening really with just a few votes? In meantime, what would you do if you really needed to modify it? The add-on domain way seems like a hack. I have a Laravel site I would like to change the doc root on as we speak. I really do not want to intermix all those Laravel folders with all the cPanel folders/files in the user ~/ directory. I really want to just create a directory called `~/Laravel` and then have a new `public` folder within it? What should I do? We need a better way...
     
  10. Haym

    Haym Active Member

    Joined:
    May 12, 2017
    Messages:
    36
    Likes Received:
    5
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    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.
     
  11. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Thanks @Haym What is the best way to make the Symlink? What about the .well-known folder in it? Does it matter?
     
  12. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    52
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    I deleted the public_html folder, and created a symlink with this:
    Code:
    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?
     
  13. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page