简体   繁体   中英

set up .cpanel.yml file to upload everything

Just starting to learn how to set up git repository on my server with cPanel. It says that i have to have a file called .cpanel.yml in the root folder for it to work.

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? I guess line 4 is correct if it should upload to home/user/public_html folder.

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.

---
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. I used rsync .

Setting the permissions is necessary if your git repo doesn't have the correct file/folder permissions. This happens often if you check in code from 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

The codes

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

Are linux codes

The cp command by default takes two positional arguments, source, and destination. By default, it will only copy files, not directories. But cp can be passed various options and arguments to change this behavior.

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:

    ---
deployment:
  tasks:

The parts listed after "tasks:" are option Linux Bash Commands.

For recursive file you can use:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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