Complete Guide: Automatic Laravel + Vue.js Deployment to cPanel using GitHub Actions

Deploy your Laravel + Vue (Vite) project automatically to a cPanel server whenever you push code to GitHub.

Introduction

Manually uploading files via FTP or File Manager after every code change is time-consuming and error-prone.

In this guide, we'll set up a CI/CD pipeline so that every time we push code to GitHub:

VS Code
     │
git push
     │
GitHub Repository
     │
GitHub Actions
     │
SSH into Server
     │
git pull
composer install
npm install
npm run build
php artisan optimize
     │
Website Updated 🚀

Technologies Used

  • Laravel
  • Vue.js
  • Vite
  • GitHub
  • GitHub Actions
  • SSH
  • cPanel
  • Linux Server

Step 1 – Create a GitHub Repository

Create a new repository.

Example:

Project-Staging

Clone it locally:

git clone https://github.com/USERNAME/REPOSITORY.git

or if the project already exists:

git init
git remote add origin git@github.com:USERNAME/REPOSITORY.git

git add .
git commit -m "Initial Commit"
git push -u origin main

Step 2 – Clone Repository on Server

Login via SSH

ssh username@server

Go to your project directory.

Example

cd /home/username/public_html/foldername

Clone directly inside the folder

git clone git@github.com:USERNAME/REPOSITORY.git .

Notice the dot (.)

Without the dot Git creates

foldername/
    RepositoryName/

With the dot

foldername/
    app/
    bootstrap/
    public/
    routes/

which is what Laravel requires.


Step 3 – Setup SSH Authentication

GitHub no longer supports password authentication.

Generate SSH key

ssh-keygen -t ed25519 -C "github-deploy"

If another key already exists

id_ed25519

Create a new one

github_actions

Example

ssh-keygen -t ed25519 -C "github-actions"

Save as

/home/username/.ssh/github_actions

Step 4 – Allow GitHub Actions to Login

Display public key

cat ~/.ssh/github_actions.pub

Append it

cat ~/.ssh/github_actions.pub >> ~/.ssh/authorized_keys

Fix permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 5 – Test SSH

Run

ssh -T git@github.com

Expected

Hi username!
You've successfully authenticated.

Step 6 – GitHub Repository Secrets

Open

Repository
    Settings
        Secrets and Variables
            Actions

Create

SecretValue
SERVER_HOSTYour Server IP/Hostname
SERVER_PORT22
SERVER_USERcPanel Username
SERVER_SSH_KEYPrivate Key (github_actions)

Step 7 – Create GitHub Workflow

Create

.github/workflows/deploy.yml
name: Deploy Laravel Foldername Project
on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Deploy to Server uses: appleboy/ssh-action@v1.2.2 with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} key: ${{ secrets.SERVER_SSH_KEY }} port: ${{ secrets.SERVER_PORT }} script: | set -e cd /home/username/public_html/foldername
echo "Pulling latest code..." git pull origin main echo "Installing Composer dependencies..." composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader echo "Installing Node modules..." npm ci echo "Building assets..." npm run build echo "Optimizing Laravel..." php artisan optimize:clear php artisan config:cache php artisan view:cache echo "Deployment Completed Successfully."

Step 8 – Push Code

git add .

git commit -m "Deployment Setup"

git push origin main

GitHub Actions will start automatically.


Step 9 – Monitor Deployment

Open

GitHub
    Actions

You'll see

Deploy Laravel Foldername Project

Click it to watch the deployment.


Problems We Faced & Solutions

1. Git Clone Asked for Username & Password

Error

Password authentication is not supported

Solution

Use SSH instead of HTTPS.

Wrong

git clone https://github.com/...

Correct

git clone git@github.com:USERNAME/PROJECT.git

2. Repository Created an Extra Folder

Problem

foldername/
      ProjectName/

Solution

Clone into current directory

git clone git@github.com:USERNAME/PROJECT.git .

Notice the dot.


3. Composer Failed During Deployment

Reason

Laravel couldn't boot because

.env

was missing.

Solution

Create

.env

Configure

  • APP_KEY
  • Database
  • Mail
  • Redis
  • Queue

Generate key

php artisan key:generate

4. Migration Failed

Error

Duplicate column

Reason

Database already contained the column.

Solution

Remove automatic migration

php artisan migrate --force

and manage production schema manually.


5. Route Cache Failed

Error

Another route has already been assigned name

Reason

Duplicate route names.

Example

user.account-settings

defined twice.

Solution

Rename one route.


6. @routes Printed on Screen

Reason

Laravel cache issue.

Solution

Run

php artisan optimize:clear

7. route() is not defined

Reason

Application cache or frontend assets were outdated.

Solution

npm run build

php artisan optimize:clear

Production Recommendations

✔ Never commit

.env

✔ Never commit

vendor/

✔ Never commit

node_modules/

✔ Always use

.gitignore

✔ Backup database before deployment.

✔ Review migrations before applying them in production.

✔ Keep Composer dependencies optimized.


Useful Commands

Clone

git clone git@github.com:USERNAME/PROJECT.git .

Pull

git pull origin main

Composer

composer install --no-dev

Node

npm ci

Build

npm run build

Clear Cache

php artisan optimize:clear

Config Cache

php artisan config:cache

View Cache

php artisan view:cache

Final Workflow

VS Code
      │
git push
      │
GitHub Repository
      │
GitHub Actions
      │
SSH Login
      │
git pull
      │
composer install
      │
npm ci
      │
npm run build
      │
php artisan optimize
      │
Laravel Website Updated

Conclusion

Using GitHub Actions with SSH and cPanel provides a reliable, repeatable deployment process for Laravel + Vue.js applications. Once configured, every push to the main branch automatically updates your server, eliminating manual uploads and reducing deployment errors. As your application grows, you can extend this pipeline with automated tests, code quality checks, and zero-downtime deployment strategies.

This setup not only saves time but also makes deployments consistent and easier to maintain for both solo developers and teams.

0 Comment's

Add Comment

Register to Reply

About Author

Looking for a reliable and skilled web developer? I'm Bhawesh Bhaskar, a Senior Full Stack Software Developer with proven expertise in both front-end and back-end development. I provide professional website design, custom web application development, and robust PHP solutions using Laravel, CodeIgniter, and Core PHP. I help businesses create modern, responsive, and high-performance websites that drive results. Whether you're starting from scratch or need to upgrade your existing site, I deliver solutions tailored to your goals.
💼 Let’s build something great together — contact me today for a free consultation!