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

时间:2018-12-07 21:08:18

标签: git server gitlab cpanel

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

它给了我这个文件示例:

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

我需要在这里写而不是在5-6行中上传所有内容吗? 我猜第4行是否应该上传到home / user / public_html文件夹是正确的。

感谢所有帮助。

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您只需要.cpanel.yml的这一部分:

    ---
deployment:
  tasks:

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

答案 2 :(得分:0)

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

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

答案 3 :(得分:-1)

代码

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

是Linux代码

默认情况下,cp命令采用两个位置参数,即源和目标。默认情况下,它将仅复制文件,而不复制目录。但是cp可以传递各种选项和参数来更改此行为。

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

/bin/cp -R * $DEPLOYPATH.

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

相关问题