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