@@ -3,7 +3,7 @@ name: Deploy Laravel to cPanel via SSH
33on :
44 push :
55 branches :
6- - production # Or your deployment branch
6+ - production
77
88jobs :
99 deploy :
@@ -31,17 +31,15 @@ jobs:
3131 fi
3232 npm run build || echo "Skipping frontend build (optional)"
3333
34- - name : 📄 Write .env file from Secret
35- run : echo "${{ secrets.LARABRIX_ENV }}" > .env
36-
37- - name : 🗜️ ZIP Application
34+ - name : 🗜️ ZIP Application (excluding .env)
3835 run : |
3936 zip -r deploy.zip . \
4037 -x "node_modules/*" \
38+ "vendor/*" \
4139 ".git/*" \
4240 "tests/*" \
4341 "storage/logs/*" \
44- "vendor/composer/* "
42+ ".env "
4543
4644 - name : 🔐 Add SSH Key
4745 uses : webfactory/ssh-agent@v0.7.0
@@ -55,31 +53,40 @@ jobs:
5553 deploy.zip \
5654 ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/deploy.zip
5755
58- - name : 🔐 SSH into server and deploy
56+ - name : 📤 Upload .env File
57+ run : |
58+ echo "${{ secrets.LARABRIX_ENV }}" > .env
59+ scp -P ${{ secrets.SSH_PORT }} \
60+ -o StrictHostKeyChecking=no \
61+ .env \
62+ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/larabrix.rhtech.dev/.env
63+
64+ - name : 🚀 SSH into Server and Deploy
5965 run : |
60- ssh -p "${{ secrets.SSH_PORT }}" ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} <<EOF
61- echo "Current directory: \$(pwd)"
62- echo "Listing home directory contents:"
63- ls -la ~/
66+ ssh -p "${{ secrets.SSH_PORT }}" ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} <<'EOF'
6467 echo "Checking if target directory exists:"
65- if [ -d "~ /larabrix.rhtech.dev" ]; then
68+ if [ -d "$HOME /larabrix.rhtech.dev" ]; then
6669 echo "Target directory exists"
6770 else
68- echo "Target directory does not exist. Creating it ..."
69- mkdir -p ~ /larabrix.rhtech.dev
71+ echo "Creating target directory ..."
72+ mkdir -p "$HOME /larabrix.rhtech.dev"
7073 fi
7174
7275 echo "Unzipping into ~/larabrix.rhtech.dev"
7376 unzip -o ~/deploy.zip -d ~/larabrix.rhtech.dev
7477 rm ~/deploy.zip
7578
76- cd ~/larabrix.rhtech.dev
79+ cd ~/larabrix.rhtech.dev || exit 1
7780
81+ echo "Running Laravel setup..."
7882 php artisan migrate --force
7983 php artisan config:clear
8084 php artisan config:cache
8185 php artisan route:cache
8286 php artisan view:cache
87+ php artisan storage:link
88+
89+ echo "Fixing permissions..."
8390 chmod -R 755 storage
8491 chmod -R 755 bootstrap/cache
8592 EOF
0 commit comments