Cart (0)
  • Your cart is currently empty.

NEOSERV BLOG

Tips, guides and useful information about domains, hosting, SSL certificates, email, web optimization and online security.

GitHub Actions - cPanel
Category: Websites
Published:

When developing websites, deploying changes to the server is an important part of the workflow. If you store your source code in a GitHub repository, it makes sense to ensure that updated files are also transferred to your web hosting account. Manually uploading files via FTP or the cPanel File Manager takes additional time and increases the risk of errors.

With GitHub Actions, you can automate this process. Every time a change is committed to the repository, the website is automatically updated on the server without having to manually upload any files.

In this guide, you’ll learn how to connect GitHub Actions to a web hosting account that uses the cPanel control panel via SSH and set up automatic website deployment.

Table of Contents

What Is GitHub Actions?

GitHub Actions is an automation tool built into the GitHub platform. It allows us to define which tasks should run when a specific event occurs, such as pushing new code changes, creating a pull request or manually triggering a process.

These automated processes are called workflows. Their instructions are defined in YAML files stored in the .github/workflows/ directory within the repository.

GitHub Actions is commonly used for automated code testing, building applications and deploying websites. In this guide, we’ll focus specifically on automatically deploying a website to a server.

Our deployment process will work as follows:

  1. We modify a website file on GitHub.
  2. We commit the change to the repository’s main branch (main).
  3. GitHub Actions automatically triggers the configured workflow.
  4. The workflow establishes a secure SSH connection to the server.
  5. It transfers the modified files to the appropriate directory on the web hosting account.
  6. The changes are automatically reflected on the live website.

What Do We Need for Automatic Website Deployment?

Before getting started, we’ll need:

  • A GitHub account, where we’ll create a repository for our website.
  • Web hosting with cPanel and SSH access enabled.
  • A domain or subdomain where our website will be accessible.
  • An SSH client (e.g. OpenSSH), which we’ll use to generate an SSH key pair.

Throughout this guide, we’ll use the example values shown in the table below.

Setting Value
GitHub repository github-actions-cpanel-demo
Repository branch main
Website address github-actions.yourdomain.com
Username (cPanel) user
Website directory /home/user/github-actions.yourdomain.com
SSH port 5050

The domain, username and directory path used in this article are examples only. When configuring your deployment, use the actual details of your hosting account. If your website is not hosted with NEOSERV, contact your hosting provider to find out which SSH port you should use.

1. Setting Up a Repository on GitHub

First, we’ll create a GitHub repository to store our website files.

1. Sign in to your GitHub account, click the + icon in the top-right corner and select New repository.

GitHub - New repository

2. Enter a repository name (e.g. github-actions-cpanel-demo). For this example, you can select a public repository (Public), check the Add a README file option and click Create repository.

GitHub - Create repository

3. In the newly created repository, open the Code tab, click Add file → Create new file and name the new file index.html.

GitHub - Create new file

4. Enter the following HTML code into the file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>GitHub Actions - cPanel Deployment Demo</title>
</head>
<body>
  <h1>GitHub Actions Deployment Demo</h1>
  <p>This website is deployed automatically using GitHub Actions.</p>
  <p>Hosting: NEOSERV cPanel</p>
  <p>Version: 1.0</p>
</body>
</html>

GitHub - Create index.html

5. Click Commit changes and confirm that the file should be saved to the main branch.

GitHub - Create index.html - Commit changes

The repository now contains a basic website (index.html), which we’ll automatically deploy to the server in the following steps.

2. Setting Up the Domain and Website Directory in cPanel

The next step is to prepare the directory where GitHub Actions will automatically upload our website files. For this guide, we’ll use the subdomain github-actions.yourdomain.com.

1. In the cPanel control panel, create a subdomain by following these instructions: How to Create a Subdomain?

cPanel - github-actions.yourdomain.com

2. Check the subdomain’s Document Root, which is the directory where we’ll later upload the website files. In our example, the directory path is:

/home/user/github-actions.yourdomain.com

In the directory path, replace user with your actual cPanel username. Also make sure the subdomain has its own document root and does not share it with the main domain.

3. Creating and Configuring SSH Keys

To allow GitHub Actions to securely transfer files to the server, we need SSH access. Instead of logging in with a password, we’ll use an SSH key pair.

The pair consists of:

  • A public key, which we add to the server;
  • A private key, which we store in the GitHub repository’s secrets.

Generating SSH Keys Using the Command Line

To generate an SSH key pair, we’ll use the ssh-keygen command, which is available on Windows, Linux and macOS. The process is similar on all three operating systems, with the main difference being how file paths are specified.

1. Open PowerShell (Windows) or a terminal (Linux or macOS) and run the appropriate command.

Windows (PowerShell):

ssh-keygen -t ed25519 -C "github-actions-cpanel-demo" -f "$env:USERPROFILE\.ssh\github_actions_cpanel"

Linux and macOS (Terminal):

ssh-keygen -t ed25519 -C "github-actions-cpanel-demo" -f "$HOME/.ssh/github_actions_cpanel"

The command generates a new Ed25519 key pair. Since we’ll use these keys for automatic website deployment, we’ve given the files a descriptive name: github_actions_cpanel.

Windows PowerShell - ssh-keygen

2. When prompted to enter a passphrase to protect the private key, press Enter twice without entering a passphrase. This allows GitHub Actions to use the key without requiring manual passphrase entry.

Two files will be created in the .ssh directory:

  • github_actions_cpanel – private key
  • github_actions_cpanel.pub – public key

Never publish your private SSH key in a repository or share it with anyone. Keep it in a secure location, as it provides access to the server.

Importing the Public Key into cPanel

1. Log in to cPanel and select SSH Access under the Security section.

cPanel (Jupiter) - SSH Access

2. Click Manage SSH Keys and then Import Key.

3. Display the contents of the public SSH key using the command line and copy it.

Windows (PowerShell):

Get-Content "$env:USERPROFILE\.ssh\github_actions_cpanel.pub" | Set-Clipboard

Linux and macOS (Terminal):

cat "$HOME/.ssh/github_actions_cpanel.pub"

On Linux and macOS, copy the displayed key contents to your clipboard.

4. In the cPanel form, enter github_actions_cpanel in the Choose a name for this key field and paste the public key into the Paste the public key into the following text box field. Leave the private key and Passphrase fields empty.

cPanel - SSH Access - Import SSH Key

5. Click Import to import the public key into cPanel.

cPanel - SSH Access - SSH Key Imported

6. Find the imported key in the list of public keys and click Manage.

cPanel - SSH Access - Public Keys - Manage

7. Confirm the authorization by clicking Authorize.

cPanel - SSH Access - Public Key Authorized

We’ve now authorized the public key, allowing SSH access to the server using the corresponding private key.

Checking the SSH connection

Before continuing with the GitHub configuration, let’s verify that we can successfully connect to the server using the SSH key we generated.

1. Open PowerShell (Windows) or a terminal (Linux or macOS) and run the appropriate command.

Windows (PowerShell):

ssh -i "$env:USERPROFILE\.ssh\github_actions_cpanel" -p 5050 user@server.yourdomain.com

Linux and macOS (Terminal):

ssh -i "$HOME/.ssh/github_actions_cpanel" -p 5050 user@server.yourdomain.com

Replace the following values:

  • user with your actual cPanel username,
  • server.yourdomain.com with your actual server hostname,
  • 5050 with the appropriate SSH port.

2. When connecting for the first time, you may see a security warning displaying the server’s public key fingerprint. After verifying that the fingerprint matches the one obtained from a trusted source, type yes and press Enter.

If the login is successful, you’ll see the server’s command prompt, such as [user@server ~]$. This confirms that the SSH connection is working and the server has accepted your key.

3. To close the SSH session, type exit and press Enter. You’ll then return to your local command line.

4. Adding Secrets to GitHub

We won’t store server connection details directly in the workflow file. Instead, we’ll use GitHub Actions Secrets.

1. In your GitHub repository, navigate to: Settings → Secrets and variables → Actions

GitHub - Actions secrets and variables

2. Click New repository secret to add six secrets. Their names and values are listed in the table below:

Secret Name Value
SSH_HOST Server hostname, e.g. server.yourdomain.com
SSH_PORT SSH port, e.g. 5050
SSH_USER cPanel username, e.g. user
SSH_PRIVATE_KEY The entire contents of the private SSH key
SSH_KNOWN_HOSTS The verified server’s public SSH host key in known_hosts format
DEPLOY_PATH Absolute path to the website directory

You can add the SSH_HOST, SSH_PORT, SSH_USER and DEPLOY_PATH secrets right away, as we already know their values. We’ll prepare the values for SSH_PRIVATE_KEY and SSH_KNOWN_HOSTS in the following steps.

For DEPLOY_PATH, enter the path to your website directory (e.g. /home/user/github-actions.yourdomain.com), adjusting it to match your domain and username.

How do we add a private SSH key?

1. Run the appropriate command in PowerShell (Windows) or a terminal (Linux or macOS).

Windows (PowerShell):

Get-Content "$env:USERPROFILE\.ssh\github_actions_cpanel" -Raw | Set-Clipboard

Linux and macOS (Terminal):

cat "$HOME/.ssh/github_actions_cpanel"

On Linux and macOS, copy the displayed key contents to your clipboard.

2. In GitHub, create a secret named SSH_PRIVATE_KEY and paste the entire contents of the private key into the Secret field, including the -----BEGIN OPENSSH PRIVATE KEY----- and -----END OPENSSH PRIVATE KEY----- lines.

How to Prepare the SSH_KNOWN_HOSTS Secret

The SSH_KNOWN_HOSTS secret contains the server’s public host key, which the SSH client uses to verify the server’s identity.

1. Run the following command in PowerShell (Windows) or a terminal (Linux or macOS):

ssh-keyscan -p 5050 -t ed25519 server.yourdomain.com

Replace server.yourdomain.com with your actual server hostname and 5050 with the appropriate SSH port.

2. The command returns an entry in the following format:

[server.yourdomain.com]:5050 ssh-ed25519 SERVER_PUBLIC_KEY

3. Copy the verified entry and save it in GitHub as the SSH_KNOWN_HOSTS secret.

Once we’ve added all six secrets, we have everything GitHub Actions needs to connect to the server and transfer our website files.

GitHub - Repository secrets

GitHub does not allow you to view secret values again after saving them, but you can replace them at any time. This is particularly useful when rotating SSH keys or migrating your website to another server.

5. Setting Up a GitHub Actions Workflow

Now we’ll create a workflow that automatically deploys our website to cPanel whenever changes are committed to the repository’s main branch (main).

1. In the repository, open the Actions tab and select Set up a workflow yourself (or New workflow if you’ve already created workflows before).

GitHub Actions - Set up a workflow

2. Create the file .github/workflows/deploy.yml and enter the following configuration:

name: Deploy website to cPanel

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Configure SSH
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
        run: |
          mkdir -p ~/.ssh
          chmod 700 ~/.ssh
          printf '%s\n' "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          printf '%s\n' "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
          chmod 600 ~/.ssh/known_hosts

      - name: Deploy website
        env:
          SSH_HOST: ${{ secrets.SSH_HOST }}
          SSH_PORT: ${{ secrets.SSH_PORT }}
          SSH_USER: ${{ secrets.SSH_USER }}
          DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
        run: |
          rsync -avz \
            --exclude='.git/' \
            --exclude='.github/' \
            -e "ssh -i ~/.ssh/id_ed25519 -p $SSH_PORT -o StrictHostKeyChecking=yes" \
            ./ "$SSH_USER@$SSH_HOST:$DEPLOY_PATH/"

GitHub Actions - deploy.yml

3. After entering the configuration, click Commit changes and save it directly to the main branch.

Explanation of the Workflow Configuration

Let’s take a closer look at what the individual settings in the deploy.yml file mean:

  • name defines the workflow name displayed in GitHub.
  • on: push means the workflow runs automatically whenever we commit a change to the main branch. The workflow_dispatch setting also allows us to trigger it manually.
  • runs-on: ubuntu-latest specifies the environment in which GitHub runs the workflow.
  • actions/checkout@v4 checks out the repository contents into the runner environment.
  • Configure SSH creates the required directory, writes the private key and verified server host key entry to it and sets the appropriate permissions.
  • Deploy website uses rsync to transfer files to the target directory on the server. It excludes the .git and .github directories, as they are not needed for the website to function.
  • StrictHostKeyChecking=yes prevents unknown server host keys from being accepted automatically.

We intentionally don’t use the --delete option in the rsync command, as it could remove files from the target directory that are not present in the repository. Before enabling this option, always make sure the target directory is correct and does not contain any other important files.

6. First Automatic Website Deployment

By saving the deploy.yml file, we’ve committed a new change to the main branch. Since this is the event that triggers our workflow, the deployment process starts automatically.

1. Open the Actions tab, where you can monitor the workflow’s progress.

If the workflow completes successfully, a green checkmark will appear next to the workflow run. If an error occurs, you can open the run details and review the logs for each step.

GitHub Actions - Successful workflow run

2. Now open your subdomain URL in a browser: https://github-actions.yourdomain.com/

If everything is configured correctly, you’ll see a website with the heading GitHub Actions Deployment Demo and the label Version: 1.0.

Website after the first automatic deployment

We’ve now confirmed that GitHub Actions can establish an SSH connection, transfer the files and deploy them to the correct website address.

7. Verifying Automatic Updates

The first deployment was successful, but we still need to verify the most important part of the automation: whether the website updates automatically when we make another change to the repository.

1. On GitHub, open the index.html file and click the pencil icon to edit it.

GitHub - Edit index.html

2. Find the line:

Version: 1.0

and change it to:

Version: 2.0

GitHub - Update index.html

3. Click Commit changes and enter a commit message, such as Update index.html.

Since we committed the change to the main branch, GitHub Actions automatically triggers the workflow again. This time, there’s no need to open cPanel or transfer any files manually.

GitHub Actions - Automatic workflow execution

4. When a green checkmark appears next to the workflow run (usually within a few seconds), the deployment has completed successfully. Now refresh the website. If the update was successful, you should see Version: 2.0.

Website after the second automatic deployment

We’ve now verified the entire process: after making a change on GitHub, the website on the server was automatically updated.

If you still see the old version of your website after GitHub Actions has completed successfully, try refreshing the page using Ctrl + F5. If the changes still don’t appear, check whether website-level or server-side caching is enabled.

Common Problems and Solutions

When setting up automatic website deployment for the first time, you may encounter a few common issues. Most can be resolved by checking your SSH configuration, GitHub Actions Secrets and target directory.

“Permission denied (publickey)”

This error means the server rejected authentication with the provided SSH key.

Check whether you’ve imported the correct public key into cPanel, authorized it using the Authorize option and added the corresponding private key to the SSH_PRIVATE_KEY secret. Also verify the username in SSH_USER.

“Host key verification failed”

GitHub Actions cannot verify the server’s identity.

Check the value of SSH_KNOWN_HOSTS, the server hostname and the SSH port. The entry must match the actual server, and its public host key must have been verified beforehand.

Do not resolve server identity verification errors by disabling StrictHostKeyChecking. Doing so would remove an important SSH security mechanism. Instead, verify that the SSH_KNOWN_HOSTS entry is correct.

“Connection timed out” or “Connection refused”

The most common causes are an incorrect server hostname, an incorrect SSH port or disabled SSH access.

Check the SSH_HOST and SSH_PORT secrets and confirm with your hosting provider that SSH access is enabled.

“No such file or directory”

If this error occurs during file transfer, check whether the target directory actually exists.

In cPanel, open Domains and check the Document Root value. The path stored in the DEPLOY_PATH secret must match your website directory.

GitHub Actions Succeeds, but the Website Displays a 403 or 404 Error

First, check whether the index.html file was actually transferred to the correct directory. If the file is located in a different directory, the web server won’t display it.

Also check file and directory permissions and domain settings. If the website displays outdated content, check the cache.

The Workflow Doesn’t Run After a Change

Check whether the file is saved at the correct path, .github/workflows/deploy.yml, and whether you committed the change to the main branch.

If you’re using a different branch, you’ll also need to update the branches setting in the workflow file.

Frequently Asked Questions (FAQ)

Can I Use GitHub Actions with a Private Repository?

Yes. GitHub Actions works with both public and private repositories. For private repositories, you should be aware of usage limits, which depend on your GitHub plan.

For more information, read our article: How to Connect a Private GitHub Repository with cPanel.

Do I Need a VPS to Use GitHub Actions?

No. You don’t need a VPS server to deploy your website automatically using GitHub Actions. All you need is web hosting with SSH support, which NEOSERV offers with the Green plan and above, as well as all Reseller and Turbo hosting plans.

You can enable SSH access in the My NEOSERV client portal. The process is described in our guide How to Connect to a Hosting Package via SSH.

Does My Website Update After Every Change on GitHub?

In our example, the workflow runs whenever a change is committed to the main branch. Changes in other branches won’t trigger a deployment unless we explicitly configure the workflow to do so.

Can I Also Deploy WordPress This Way?

Yes, but the process is slightly more complex than deploying a simple static website. In addition to files, WordPress also uses a database, so automatic deployment needs to account for configuration files, user-generated content and any database changes.

Is GitHub Actions Free to Use?

GitHub provides a certain amount of GitHub Actions usage at no additional cost, but usage limits and potential charges depend on the repository type, runner environment and GitHub plan.

For details, check the official GitHub Actions billing documentation.

Simplify Website Deployment

Using GitHub Actions, we’ve set up a process where updating our website is as simple as committing a change to the GitHub repository. The workflow then automatically establishes a secure SSH connection and transfers the updated files to our web hosting account. This approach eliminates the need to transfer files manually, provides better visibility into changes and makes website maintenance easier.

You don’t need your own server to automate website deployment. If you use NEOSERV Hosting with a plan that supports SSH access, you can integrate GitHub Actions into your regular cPanel workflow. You can start with a simple static website and later adapt the automation to more complex projects as needed.

COMMENTS

LEAVE A COMMENT

(required)
(required, will not be published)
(optional)
A security question to confirm you are human.