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!

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:
    68
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    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:
    39
    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:
    68
    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:
    68
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    What about using a reverse .gitignore file to only "include" the file and folders I want? Would that be a better approach?
    Code:
    
    # 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
    
     
  15. bgarrant

    bgarrant Well-Known Member

    Joined:
    Jun 27, 2012
    Messages:
    68
    Likes Received:
    9
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    @cPanelAdamF
    @cPanelMichael

    So I took your advice and installed a git repo above webroot in the
    Code:
    ~/
    . See: Installing and running above webroot - The Knowledge Base - Statamic 2 Docs

    If I login to my account, my home directory
    Code:
    ~/
    looks like this:

    Code:
    .cpanel
    .cphorde
    .git - GIT WORKING REPO (not a bare repo)
    .htpasswds
    .ssh
    .trash
    access-logs
    etc
    local - STATAMIC FOLDER
    logs
    mail
    perl5
    public_ftp
    public_html - includes the forward facing files needed
    sass - DEVELOPMENT FILES
    site - STATAMIC FOLDER
    ssl
    statamic - STATAMIC FOLDER
    tmp
    www
    .bash_history
    .bash_logout
    .bash_profile
    .bashrc
    .contactemail
    .env - STATAMIC FILE
    .gitconfig
    .gitignore
    .zshrc
    LocalValetDriver.php - DEVELOPMENT FILE
    mix-manifest.json - DEVELOPMENT FILE
    package-lock.json - DEVELOPMENT FILE
    package.json - DEVELOPMENT FILE
    phpunit.xml - DEVELOPMENT FILE
    please - DEVELOPMENT FILE
    webpack.min.js - DEVELOPMENT FILE
    
    The only concern I have is with my .gitignore. If I do not want all the cPanel folders included in the repo, which I do not, what is best approach?

    Here is the default Statamic .gitignore

    Code:
    .DS_Store
    .env
    node_modules/
    bower_components/
    local/cache/*
    local/storage/*
    local/temp/*
    installer.php
    
    Since we are using the
    Code:
    ~/
    location for our .git repo, we then have to contend with all the cPanel folders/files if we ever need to make a
    Code:
    git add --all
    and
    Code:
    git commit
    on the server. Here is what the .gitignore looks like:

    Code:
    # Statamic and OS #
    #################
    .DS_Store
    .env
    node_modules/
    bower_components/
    local/cache/*
    local/storage/*
    local/temp/*
    installer.php
    /.idea
    
    # cPanel #
    #################
    /.cpanel/
    /.cphorde/
    /.htpasswds/
    /.ssh/
    /.trash/
    access-logs
    /etc/
    /logs/
    /mail/
    /perl5/
    /public_ftp/
    /public_html/error_log
    /public_html/.well-known
    /ssl/
    /tmp/
    www
    /.bash_history
    /.bash_logout
    /.bash_profile
    /.bashrc
    /.contactemail
    /.gitconfig
    /.lastlogin
    /.viminfo
    /.zshrc
    
    As you see that is very long, and if you happen to add a new feature to cPanel it would probably require modifying this on every site. What do you think of using a reverse .gitignore to just "include" the files/folders I need in the repo?

    Code:
    # 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?
     
  16. bgarrant

    bgarrant Well-Known Member

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

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,442
    Likes Received:
    1,961
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice