Continuously deploy your WordPress website using GitHub Actions

Apr 22, 2025

-sidebar-toc>        -language-notice>

The prerequisites

Before you can start a continuous deployment on your WordPress site to  begin, you'll need a couple of items you must have:

  1. A basic understanding of Git including pushing code or using an .gitignore file.

Locally storing your site and setting up GitHub

As a user you will find the easiest method to gain access to your WordPress site's local files is by using Dev. In just a couple of steps, you are able to pull your website from its server to Dev, allowing you to work on the site on your own.

How to do it:

  1. Open Dev and click Add site.
  2. Choose the Import from option. This will save everything on your website so that you are able to use it locally to develop.

The next step is to create the GitHub repository, and then upload the site's content onto GitHub.

Setting up GitHub secrets to

In order to automate the process of deploying from GitHub to  the server you'll need certain SSH details like your username or password, port as well as your IP address. As these are private storage options, you should save them as GitHub secret files.

In order to add secrets on GitHub:

  1. Visit your repository on GitHub.
  2. Select Settings > Variables and secrets >> Actions and options New repository secret.
  3. Add the following secret:
  •        _SERVER_IP      
  •        _USERNAME      
  •        password      
  •        HTTP0_PORT      
SFTP/SSH info details in My
SFTP/SSH info details in My.

Once you have this set-up completed You can now set up an automatic deployment of your WordPress site.

Configuring your server

Before automating the deployment process using GitHub Actions, you must configure your servers to sign in with GitHub and deploy the latest code.

1. Create an SSH key to your server

SSH into your server via your the command "SSH" accessible within your My dashboard.

SSH terminal command My.
The command for SSH on the terminal My.

Then, generate a new SSH keys (skip this step if you already own one):

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Press Enter to save the key to the default location and leave the passphrase empty when you are asked.

Generate SSH key on your  server
Generator of SSH key for your server.

2. Include the SSH password to GitHub

To access the content of the public key file (e.g., ~/.ssh/id_rsa.pub) execute this command:

cat ~/.ssh/id_rsa.pub

The key will be displayed. Go to GitHub settings Settings > SSH or GPG keys and keys Then, create a new SSH key Give it a title (e.g., " Server Key") then paste the key public. Be sure to select "Authentication Key" is selected because this key will enable the server to pull and push the code.

3. Configure Git to make use of SSH on the server.

Navigate to your site's live directory via the server, by executing the following command:

cd /www/your-site/public

It is possible to find this route within the Environment details section on the My site dashboard, like the following:

WordPress site path My
WordPress website path My.

Then, you need to set the directory up as an Git repository and set the remote URL to utilize SSH:

git init git remote add origin [email protected]:your-username/your-repo.git

Replace your-username and your-repo with your GitHub username and repository's name and repository name, respectively.

Verify that the SSH configuration works through running:

ssh -T [email protected]

There should be a message like: "Hi your-username! Your account has been authenticated successfully, however GitHub isn't able to offer shell access."

After this configuration your server will be prepared to accept and distribute updates from GitHub directly through GitHub Actions.

The creation of the GitHub Actions workflow for automatic deployment

Now that you have your WordPress website is running on your local machine, it's been pushed to GitHub, and you have installed the GitHub secrets now is the time to create a GitHub actions workflow. The workflow will deploy changes instantly whenever you push changes to the branch that is the main branch.

For the purpose of automating deployment to make it easier, you'll need to create an the YAML file that defines the way that deployments will take place. This is how you can set it up:

  1. Create a directory titled .github/workflows in your GitHub repository.
  2. In this directory, make a new file called deploy.yml.
  3. Incorporate the following contents into the deploy.yml file:
name: Deploy to on: push: branches: - main # Trigger the workflow only when changes are pushed to the main branch jobs: deploy: runs-on: ubuntu-latest steps: # Setup Node.js (only if needed for build tasks) - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20.x' # Checkout the latest code from the GitHub repository - name: Checkout code uses: actions/[email protected] # Deploy to via SSH - name: Deploy via SSH uses: appleboy/[email protected] with: host: $ secrets._SERVER_IP  username: $ secrets._USERNAME  password: $ secrets.PASSWORD  port: $ secrets.PORT  # Optional, default is 22 script: | # Navigate to the live site directory cd /www/your-site/public # Pull the latest changes from the GitHub repository git fetch origin main git reset --hard origin/main # Ensure the live site matches the latest main branch

A closer look at this workflow

Here's a summary of the procedure:

  1. Trigger: The workflow is triggered every time code is transferred to the main part of your GitHub repository.
  2. Jobs: The workflow contains only one job known as deploy that operates in the Ubuntu virtual machine ( ubuntu-latest).
  3. Code for checking out  The step makes use of the actions/ [email protected[email protected] action to download the latest code directly from the GitHub repository.
  4.      Deploy via SSH     :
  • Appleboy's appleboy/ssh action plugin establishes an SSH connection to your server utilizing the passwords you've stored in the GitHub repository (host user, password, username and, if you wish, your port).
  •        Deployment Commands       : This step navigates to the live directory on your server. makes use of        Git fetch       and        git reset --hard       to pull and reset the code so that it matches the latest        principal        branch:
  • cd /www/your-site/public: Navigates to the live directory where WordPress is hosted.
  • Git fetch principal The fetcher retrieves the most current changes to your principal branch in your GitHub repository.
  • git reset Hard main/source The live site to the most current version of the code that is from the branch that is used for main.

Test the workflow

Once you've established the workflow, test it with a minor alteration into your GitHub repository's main branch. Each time you push the change, GitHub actions automates deployment by pulling the most recent version of your code before the deployment to your live web page at .

You can check the progress of your workflow through the Actions tab in your GitHub repository. If the workflow encounters errors You'll be able to view the logs in detail to help to fix and resolve the issue.

Summary

By setting up continuous deployment of your WordPress site with GitHub Actions, you automate your process of development, and ensure that each change submitted through GitHub will be automatically pushed to the live website to .

Additionally, it allows you to incorporate additional workflows in the pipeline, such as testing and formatting using scripts from the @wordpress/scripts program.

    What do you think of the process? Is there something else you'd like us explain or did you experience some errors when following this procedure? Please share your questions or feedback in the comment section down below!

Joel Olawanle

Joel is an Frontend Developer working as a Technical Editor. Joel is an enthusiastic teacher and enthusiast for open source. He has published over 300 technical articles majorly around JavaScript as well as its frameworks.