fix: proper shared hosting PHP deployment with vendor + frontend assets
API CI/CD / Validate (composer + pint) (push) Failing after 2s
API CI/CD / Test (PHPUnit) (push) Failing after 2s
API CI/CD / Build frontend assets (push) Failing after 39s
API CI/CD / Security audit (push) Failing after 1s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Failing after 2s
API CI/CD / Test (PHPUnit) (push) Failing after 2s
API CI/CD / Build frontend assets (push) Failing after 39s
API CI/CD / Security audit (push) Failing after 1s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
- Remove --exclude=vendor and pre-install with --no-dev - Download frontend build artifacts before deploy - Add post-deploy artisan commands (migrate, cache, optimize) - Add alpine container for consistent package management
This commit is contained in:
+3
-1
@@ -15,9 +15,11 @@ After pushing, the pipeline will run automatically. The following steps are requ
|
||||
| Variable Name | Default | Description |
|
||||
|---|---|---|
|
||||
| `SSH_PORT` | `22` | SSH port for the deployment server |
|
||||
| `SSH_TARGET_DIR` | — | Absolute path on the server where the project is deployed |
|
||||
| `SSH_TARGET_DIR` | — | Absolute path on the server where the Laravel app root goes |
|
||||
| `PRODUCTION_URL` | — | Public URL of the production site |
|
||||
|
||||
> **Note:** The deploy job runs `php artisan migrate`, `config:cache`, `route:cache`, `view:cache`, and `optimize` via SSH after uploading. The PHP CLI binary must be available on the shared hosting server.
|
||||
|
||||
## 3. Allow Gitea Actions
|
||||
|
||||
- Go to **Settings → Actions** in your Gitea repository
|
||||
|
||||
@@ -245,11 +245,13 @@ jobs:
|
||||
fi
|
||||
|
||||
# ──────────────────────────────────────────────
|
||||
# DEPLOY (manual): to production via SSH
|
||||
# DEPLOY (manual): to shared hosting via SSH
|
||||
# ──────────────────────────────────────────────
|
||||
deploy:
|
||||
name: Deploy to production
|
||||
name: Deploy to shared hosting (PHP)
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: php:8.3-cli
|
||||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
||||
needs: [test, build, security]
|
||||
environment:
|
||||
@@ -259,21 +261,58 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install SSH client
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends openssh-client sshpass rsync
|
||||
apt-get install -y --no-install-recommends \
|
||||
git unzip curl libzip-dev libpng-dev libonig-dev libxml2-dev \
|
||||
openssh-client sshpass rsync
|
||||
docker-php-ext-install mbstring zip gd pdo_mysql
|
||||
|
||||
- name: Deploy via rsync
|
||||
- name: Install Composer
|
||||
run: |
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||
rm composer-setup.php
|
||||
|
||||
- name: Install production PHP dependencies
|
||||
run: |
|
||||
composer install --no-dev --optimize-autoloader --no-interaction --no-progress
|
||||
|
||||
- name: Download frontend build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: frontend-assets
|
||||
path: ./
|
||||
|
||||
- name: Deploy Laravel app to shared hosting
|
||||
run: |
|
||||
sshpass -p "${{ secrets.SSH_PASSWORD }}" rsync -avz --delete \
|
||||
-e "ssh -p ${{ vars.SSH_PORT || 22 }} -o StrictHostKeyChecking=no" \
|
||||
--exclude='.env' \
|
||||
--exclude='.git' \
|
||||
--exclude='.gitea' \
|
||||
--exclude='tests' \
|
||||
--exclude='storage/logs/*' \
|
||||
--exclude='database/sqlite' \
|
||||
--exclude='database/database.sqlite' \
|
||||
--exclude='node_modules' \
|
||||
--exclude='vendor' \
|
||||
--exclude='.npm' \
|
||||
--exclude='reports' \
|
||||
--exclude='.phpunit.result.cache' \
|
||||
--exclude='package-lock.json' \
|
||||
--exclude='.composer-cache' \
|
||||
./ \
|
||||
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ vars.SSH_TARGET_DIR }}/
|
||||
|
||||
- name: Post-deploy artisan commands
|
||||
run: |
|
||||
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh \
|
||||
-o StrictHostKeyChecking=no \
|
||||
-p ${{ vars.SSH_PORT || 22 }} \
|
||||
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \
|
||||
"cd ${{ vars.SSH_TARGET_DIR }} && \
|
||||
php artisan migrate --force && \
|
||||
php artisan config:cache && \
|
||||
php artisan route:cache && \
|
||||
php artisan view:cache && \
|
||||
php artisan optimize"
|
||||
|
||||
Reference in New Issue
Block a user