Automate Website Deployment on VPS with n8n | Auto Update After Git Push 🚀

Automate Your App Deployment with N8N

Have you ever wished you could automatically update your app on your server every time you push new code? This guide will show you how to do just that using n8n, a powerful workflow automation tool. By setting this up, you'll save time and avoid manual updates.

1

Set Up the GitHub Trigger

First, we need to tell n8n to listen for new code on your GitHub account.

  1. Add a Trigger: In your n8n workflow, click to add your first step. Search for "GitHub" and select the On Push trigger. This action will start your workflow whenever you push new changes to your chosen code repository.
  2. Connect GitHub: To link your GitHub account, you'll create a new credential. The easiest way is with OAuth2.
  3. Create an App on GitHub: Go to your GitHub profile settings and find the OAuth Apps section under Developer settings. Click to create a new OAuth app. Give it a simple name like "n8n" and fill in the homepage and callback URLs that n8n gives you.
  4. Finish the Connection: GitHub will give you a Client ID and a Client Secret. Copy these codes and paste them into n8n to complete the connection.
  5. Configure the Node: Now, select your GitHub username and the specific repository you want to automate. You can test this step to make sure it's working correctly.
2

Connect to Your Server with SSH

Next, we will add a step that connects to your server and runs the deployment commands.

  1. Add the SSH Node: Add a new step to your workflow and search for "SSH." Choose the Execute a Command action.
  2. Create a Secure Connection: It's best to use a private key for a secure connection. Before you do this, make sure you've set up passwordless SSH login on your server. This means your computer can connect to the server without needing a password.
  3. Add Your Key: Copy the content of your private key file from your local computer and paste it into the n8n credentials.
  4. Enter Server Details: Fill in your server's IP address, the port (which is usually 22), and your username.
3

Write the Deployment Commands

Now for the most important part: the commands that will actually deploy your app.

  1. Write Your Script: In the Command field of the SSH node, write the sequence of commands you would normally run to update your app. These usually include:
cd /var/www/my-app git pull npm install npm run build pm2 restart all

Set the Working Directory: Make sure to set the Working Directory to the main folder of your project on the server.

4

Launch Your Automation!

Finally, turn your workflow on.

Activate the Workflow: At the top of your n8n workflow, there is a toggle switch. Flip this switch to activate your workflow.

Congratulations! Your Automation is Ready

That's it! Now, every time you push new code to your GitHub repository, this workflow will automatically run, update your app on the server, and restart it for you. This makes deploying your projects much faster and easier.

💡 Pro Tips for Better Automation
  • Test your workflow with a simple change first
  • Add error notifications to know if something goes wrong
  • Consider adding a backup step before deployment
  • Use environment variables for sensitive information

© 2025 ThapaTechnical - DevOps Automation Guide. Built with ❤️ for developers.

Subscribe - Thapa Technical