Please ensure that php and composer is installed and configured properly on the server. You can test it by running php -v and composer -v.
In this example we will use the following variables
| Variables | Value |
|---|---|
| Username | admin |
| Password | 12345 |
| IP Address | 123.45.67.89 |
# If logged as different user, switch to admin first
su - admin
# Create ~/.ssh folder if not yet created
mkdir -p ~/.ssh
# Generate SSH key pair
# Set the file name to /home/admin/.ssh/admin and leave the passphrase empty for simplicity.
ssh-keygen -t rsa -b 4096 -C "admin@interseptx"
chmod 700 ~/.ssh
# Add the public key to the authorized_keys file on the VPS
cat ~/.ssh/admin.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# Download the private key to your local machine (Windows)
# Use the credential you use to login to the SSH server
scp admin@123.45.67.89:/home/admin/.ssh/admin "C:\Users\Admin\.ssh"
# Add the private key to the ssh-agent
ssh-add "C:\Users\Admin\.ssh\admin"
# Test the connection (Windows)
# If you can connect without possword then it is a success
ssh -i "C:\Users\Admin\.ssh\admin" -o ServerAliveInterval=60 -A -p 22 admin@123.45.67.89Go to project's repository Settings, select Secrets and variables, then Actions and add the following secrets:
| Secret | Value |
|---|---|
| LIVE_SSH_HOST | 123.45.67.89 |
| LIVE_SSH_USERNAME | admin |
| LIVE_SSH_PRIVATE_KEY | [ENCRYPTION_KEY] |
| LIVE_SSH_PORT | 22 |
Add a new file .github/workflows/live-deploy.yml to your project:
name: Deploy to Servers
on:
push:
branches: [ live ]
jobs:
production:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy Live
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.LIVE_SSH_HOST }}
username: ${{ secrets.LIVE_SSH_USERNAME }}
key: ${{ secrets.LIVE_SSH_PRIVATE_KEY }}
port: ${{ secrets.LIVE_SSH_PORT || 22 }}
script: |
set -e
# Navigate to Live directory
cd ~/public_html
# Switch to Live branch
echo "Switching to Live branch..."
git checkout live
# Pull latest changes
echo "Pulling latest changes..."
git pull
# Run server-up command
echo "Running build"
/usr/local/bin/composer install
/usr/local/bin/php vendor/bin/phinx migrate
# Ensure
chmod -R 0755 ~/public_html
echo "Live deployment completed successfully!"