Dreaming about a setup where you just push your changes, and they will be immateriality live?
It’s possible! I use Hugo and NPM to build my static websites and deploy them automatically from GitHub/GitLab to my Plesk webspace.
So how is this possible? The secret is the Plesk Git extension, which can pull any git repository as soon as a webhook is called (this extension has to be installed by your provider, but with most providers, it is available). For that, we have to push our built artifact to another branch (similar to how github-pages works), which is then deployed to the webspace.
Step 1: Modify your CI
Here it depends on what CI you use. I will provide examples of how it’s done with GitHub Actions and GitLab CI. Generally, the steps are:
- Create an ssh key (deploy key) and put it into a CI variable to grant the CI push access to the repo
- Use an image with git or install git and set up the key
- Create a new branch, e.g.,
- Clone the deploy branch and delete everything besides the
- Move the built artifact from the previous build step to the cloned (and now empty) folder
- add, commit, push
First, generate an ssh key. With GitHub you can then create a deploy key under
Settings->Deploy keys by inserting the public key. Then make a repository secret named
Settings->Secrets and insert the private key.
Your Action definition then might look like this (don’t forget to change the repository URL):
First, generate an ssh key. With GitLab you can then create a deploy key under
Settings-> Repository->Deploy keys by inserting the public key. Then make a protected variable named
Settings->CI/CD->Variables and insert the private key.
.gitlab-ci.yml CI definition then might look like this (don’t forget to change the repository URL):
Step 2: Create website in Plesk
Next, create the website in Plesk and add a Git repository. If the repository is private, you have to add the public key given by Plesk to GitHub/GitLab as the deploy key for the SSH connection. Don’t forget to select the deploy branch and correct folder on your webspace! Instruction can be found here.
Plesk always clones the main branch for the first time before you switched to the other branch. When switching, the old files won’t get deleted, so you might have to clean up once and remove some of the old files from the webspace folder.
Step 3: Configure the webhook
Plesk will give you a webhook-URL under the repository settings of the git extension in Plesk. Then configure GitHub/GitLab to call that webhook URL every time a push happens.
With GitHub and GitLab, this can be done under
Settings->Webhooks . Select push events and test it.
Step 4: Profit
That’s it! This should basically work with every CI that has access to your repository and the git Plesk extension.