繁体   English   中英

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

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

刚开始学习如何使用 cPanel 在我的服务器上设置 git 存储库。 它说我必须在根文件夹中有一个名为 .cpanel.yml 的文件才能工作。

它给了我这个文件示例:

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

我需要在这里写什么而不是第 5-6 行来上传所有内容? 如果应该上传到 home/user/public_html 文件夹,我想第 4 行是正确的。

感谢所有的帮助。

因为我发现这是一个挑战并且没有好的文档,所以我发布了我使用的内容。 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 '{}' \;

可以使用cp ,但是很麻烦,因为您不想复制.git文件夹,并且无法轻松排除文件夹。 我使用了rsync

如果您的 git repo 没有正确的文件/文件夹权限,则需要设置权限。 如果您从 Windows 签入代码,这种情况经常发生。

您可能需要更改部署过程以供您自己使用。 有关文件权限,请参阅本指南: https : //www.a2hosting.com/kb/cpanel/cpanel-file-features/cpanel-file-manager/file-permissions

代码

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

是linux代码吗

默认情况下,cp 命令采用两个位置参数,源和目标。 默认情况下,它只会复制文件,而不是目录。 但是 cp 可以通过各种选项和参数来改变这种行为。

要复制所有文件,包括子目录,您要使用的命令可能是

/bin/cp -R * $DEPLOYPATH.

这应该递归地将所有文件和目录从存储库目录复制到部署路径。

你只需要 .cpanel.yml 的这部分:

    ---
deployment:
  tasks:

“tasks:”后面列出的部分是选项 Linux Bash 命令。

对于递归文件,您可以使用:

---
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