简体   繁体   English

设置 .cpanel.yml 文件以上传所有内容

[英]set up .cpanel.yml file to upload everything

Just starting to learn how to set up git repository on my server with cPanel.刚开始学习如何使用 cPanel 在我的服务器上设置 git 存储库。 It says that i have to have a file called .cpanel.yml in the root folder for it to work.它说我必须在根文件夹中有一个名为 .cpanel.yml 的文件才能工作。

It gave me this file example:它给了我这个文件示例:

    ---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/public_html/
    - /bin/cp index.html $DEPLOYPATH
    - /bin/cp style.css $DEPLOYPATH

What is neccesary for me to write here instead of line 5-6 to upload everything?我需要在这里写什么而不是第 5-6 行来上传所有内容? I guess line 4 is correct if it should upload to home/user/public_html folder.如果应该上传到 home/user/public_html 文件夹,我想第 4 行是正确的。

Thanks for all the help.感谢所有的帮助。

Because I found it a challenge and there's no good documentation, I'm posting what I used.因为我发现这是一个挑战并且没有好的文档,所以我发布了我使用的内容。 Replace USER and PROJECT with your own folders.USERPROJECT替换为您自己的文件夹。

---
deployment:
  tasks:
    # NOTE: public_html on cPanel must not be removed or renamed.
    # This folder has owner USER:nobody, and the USER user does not have
    # access to change owner. So this folder must stay as-is to keep the nobody
    # group, which is critical to the site working. A new folder won't work.
    - export DEPLOYPATH=/home/USER/public_html
    - export REPOPATH=/home/USER/repositories/PROJECT
    # Remove previous old files, if any.
    - /bin/rm -Rf ${DEPLOYPATH}_old
    # Copy old site files to another directory.
    - /bin/cp -R ${DEPLOYPATH} ${DEPLOYPATH}_old
    # Sync repository files to the deploy target path, excluding .git folder.
    # --delete-after will remove deleted files and folders after syncing.
    - /bin/rsync -aP --exclude '.git' --exclude '.well-known' ${REPOPATH}/ ${DEPLOYPATH} --delete-after
    # Set correct permissions.
    - /bin/chmod 755 ${DEPLOYPATH}
    - /bin/find ${DEPLOYPATH} -type d -exec /bin/chmod 755 '{}' \;
    - /bin/find ${DEPLOYPATH} -type f -exec /bin/chmod 644 '{}' \;

It's possible to use cp , but it's a pain, because you don't want to copy the .git folder, and you can't exclude folders easily.可以使用cp ,但是很麻烦,因为您不想复制.git文件夹,并且无法轻松排除文件夹。 I used rsync .我使用了rsync

Setting the permissions is necessary if your git repo doesn't have the correct file/folder permissions.如果您的 git repo 没有正确的文件/文件夹权限,则需要设置权限。 This happens often if you check in code from Windows.如果您从 Windows 签入代码,这种情况经常发生。

You may need to change the deploy process for your own uses.您可能需要更改部署过程以供您自己使用。 See this guide for file permissions: https://www.a2hosting.com/kb/cpanel/cpanel-file-features/cpanel-file-manager/file-permissions有关文件权限,请参阅本指南: https : //www.a2hosting.com/kb/cpanel/cpanel-file-features/cpanel-file-manager/file-permissions

The codes代码

-export DEPLOYPATH=/home/user/public_html/
- cp index.html $DEPLOYPATH
- cp style.css $DEPLOYPATH 

Are linux codes是linux代码吗

The cp command by default takes two positional arguments, source, and destination.默认情况下,cp 命令采用两个位置参数,源和目标。 By default, it will only copy files, not directories.默认情况下,它只会复制文件,而不是目录。 But cp can be passed various options and arguments to change this behavior.但是 cp 可以通过各种选项和参数来改变这种行为。

To copy all files, including subdirectories, the command you want to use is probably要复制所有文件,包括子目录,您要使用的命令可能是

/bin/cp -R * $DEPLOYPATH.

That should recursively copy all files and directories from the repository directory to the deploy path.这应该递归地将所有文件和目录从存储库目录复制到部署路径。

You only need this part of the .cpanel.yml:你只需要 .cpanel.yml 的这部分:

    ---
deployment:
  tasks:

The parts listed after "tasks:" are option Linux Bash Commands. “tasks:”后面列出的部分是选项 Linux Bash 命令。

For recursive file you can use:对于递归文件,您可以使用:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/folderpath
    - /bin/cp -R . $DEPLOYPATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM