Is Git Repo Above Document Root OK?
I have Statamic CMS driven site that stores some files above the doc root like so:
~/ folder structure
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:
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?
.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:
.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?
-
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 -
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 folderrm -rf public_html ln -s laravel/public/ public_html
See: joshmountain.com/blog/installing-laravel-and-composer-on-a-cpanel-server0 -
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 -
@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 -
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 -
@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 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 -
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).
0 -
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).
Thanks @Haym What is the best way to make the Symlink? What about the .well-known folder in it? Does it matter?0 -
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).
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 -
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 -
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 -
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 -
@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 -
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.
Comments
16 comments