Archive / Vps

How to Set Up a CI/CD Pipeline on Your VPS

To deploy CI/CD on a VPS, you set up a server-side automation runner—like GitHub Actions' self-hosted runner—directly on your virtual server, which then executes your pipeline scripts to test, build, and deploy code from your repository to the same machine or a staging environment.

Why Run CI/CD on a VPS vs. a Cloud Service?

Cloud-based CI/CD services (like GitHub-hosted runners) are simple but bill per minute and can't directly access your VPS's databases or file system. Running the runner on your own VPS consolidates costs, gives you full control over the execution environment, and allows direct file operations. This is ideal for deploying to the same server. You trade this for managing the runner's uptime and security yourself.

Core Setup Steps for a Self-Hosted Runner

A common approach is using GitHub Actions' self-hosted runner. The process is similar for GitLab CI or Jenkins.

  1. Provision a Compatible VPS: You need a Linux VPS (Ubuntu 22.04 LTS is standard) with root access. The runner is a background service, so a plan with a single vCPU and 1-2 GB of RAM can handle light to medium workloads.
  2. Install the Runner Software: On your VPS, download and configure the runner agent from your Git provider. For GitHub, you run a script from your repository's settings page. Run it as a dedicated system user.
  3. Define Your Workflow: In your project repo, create a .github/workflows/deploy.yml file. Configure the job to use your self-hosted runner by setting runs-on: self-hosted or a matching label.

Note

For a stable foundation, consider a KVM VPS with SSD storage. KVM virtualization ensures isolated resources, which leads to more consistent runner performance than oversold OpenVZ containers.

A Sample Pipeline Workflow for a VPS

This basic GitHub Actions workflow runs on a self-hosted VPS runner to test and deploy a Node.js API.

name: Deploy to VPS
on:
  push:
    branches: [ main ]

jobs:
  test-and-deploy:
    runs-on: self-hosted
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
      - name: Install dependencies
        run: npm ci
      - name: Run tests
        run: npm test
      - name: Deploy application
        run: |
          pm2 stop my-api || true
          pm2 start server.js --name my-api

This pipeline triggers on a push to main. The runner checks out the code, installs Node.js and dependencies, runs the test suite, and if tests pass, uses PM2 to restart the application. All steps execute directly on your VPS.

Security and Maintenance Tips

Running a CI/CD service on your server introduces new considerations.

Setting up CI/CD on your VPS turns it into an automated deployment hub. The initial setup requires command-line work, but the payoff is a fast, private, and cost-controlled pipeline. For projects that have outgrown shared hosting, a Hostinger VPS provides a straightforward platform to host both your application and its automation engine.

Frequently asked questions

Can I run CI/CD on a cheap VPS?

Yes, you can run a CI/CD runner on an entry-level VPS. The runner itself is lightweight. Performance limits come from your pipeline's tasks (e.g., running complex test suites or building large applications). For simple web apps or scripts, a plan with 1 vCPU and 1GB RAM is often sufficient.

What's the difference between a self-hosted runner and a cloud runner?

A cloud runner is a temporary, managed virtual machine provided by a service like GitHub. A self-hosted runner is software you install on your own server (like a VPS). The self-hosted runner gives you a persistent environment, direct server access, and no per-minute fees, but you are responsible for its maintenance and security.

How do I deploy a WordPress site using CI/CD on a VPS?

For WordPress, your CI/CD pipeline on a VPS can use WP-CLI commands. A typical workflow would: 1) Check out your theme/plugin code, 2) Run PHP CodeSniffer tests, 3) Use SCP or rsync over SSH to copy files to your VPS's web directory, and 4) Execute WP-CLI commands to update the database. You'd store your SSH credentials and database details as secrets in your CI platform.

Is it safe to run CI/CD on my production VPS?

It's common but adds risk. The runner has access to your production environment. For better safety, use a separate staging VPS for the runner and deployments, then sync to production after verification. At a minimum, strictly limit the runner user's file permissions and never expose secrets in logs.

Affiliate disclosure: If you buy through our links, we may earn a commission at no extra cost to you.

Ready to get started? Check out Hostinger's plans.

Related reads