Automatically Deploy Your App to a VPS with GitHub Actions
If your deploy process is "SSH into the server, cd to the app, git pull , restart something, hope" — this post replaces it with git push . What you'll have by the end: every push to your main branch updates the app on your server automatically. You can also trigger a deploy by hand from the GitHub UI. This is the simple version — it has a few seconds of downtime during the restart and it builds…
GitHub Actions automates the process of deploying your application to a Virtual Private Server (VPS) with a simple GitHub push. This eliminates the need for manual SSH connections, command executions, and restarts. To set this up, you'll need an app in a GitHub repository, a VPS you can SSH into, a dedicated Linux user for deploys, and a few prerequisites.
First, generate an SSH key exclusively for deployment on your local machine. Add the public key to your server and test the connection. Then, grant the deploy user permission to restart your application without requiring a password. Store the SSH private key as a secret in your GitHub repository.
Create a GitHub Actions workflow file, `.github/workflows/deploy.yml`, that runs automatically on every push to the main branch. The workflow uses the `appleboy/ssh-action` to connect to your VPS, fetches the latest code from the main branch, resets to that commit, installs dependencies, builds the application, applies migrations, and finally restarts the app.
Common issues include permission errors, SSH username problems, missing dependencies, and memory constraints during build. Ensure your server setup matches the workflow's assumptions and adjust accordingly.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.