Skip to content

Latest commit

 

History

History
236 lines (169 loc) · 5.42 KB

File metadata and controls

236 lines (169 loc) · 5.42 KB

🚨 START HERE - Fix Backend on Render

Your Situation

✅ Backend works locally with MySQL
❌ Backend doesn't work on Render.com

The Fix (Choose ONE option below)


🎯 OPTION 1: SQLite (Fastest & Easiest)

Why Choose This:

  • No separate database needed
  • Works on Render's free tier
  • Setup in 5 minutes
  • Perfect for this application

Steps:

1. Set Environment Variables on Render

Go to: https://dashboard.render.com → Your backend service → Environment

Click "Add Environment Variable" and add these:

Key Value
APP_NAME Validation Engine
APP_ENV production
APP_KEY See below
APP_DEBUG false
APP_URL https://validation-engine-backend.onrender.com
DB_CONNECTION sqlite
DB_DATABASE /opt/render/project/src/database/database.sqlite
LOG_CHANNEL stack
LOG_LEVEL error

Generate APP_KEY locally:

cd E:\work\Angular\validation-engine-backend
php artisan key:generate --show

Copy the entire output (including base64:) and paste as APP_KEY value.

2. Update Render Build/Start Commands

Still in Render dashboard → Your service → Settings:

  • Build Command: bash build.sh
  • Start Command: php -S 0.0.0.0:$PORT -t public

Click "Save Changes"

3. Push Your Code

cd E:\work\Angular\validation-engine-backend
git add .
git commit -m "Configure for Render with SQLite"
git push origin main

4. Wait & Test (2-3 minutes)

Render will auto-deploy. Check logs for:

  • ✅ "Migration table created successfully"
  • ✅ "Build complete!"

Then test: https://validation-engine-backend.onrender.com/api/validation_rules
Should return: []

DONE! Your backend is working!


🎯 OPTION 2: PostgreSQL (Production-Ready)

Why Choose This:

  • Better for production
  • Free on Render
  • More scalable

Steps:

1. Create PostgreSQL Database

  • Go to: https://dashboard.render.com
  • Click "New +""PostgreSQL"
  • Name: validation-engine-db
  • Database: validation_engine
  • Region: Same as your web service
  • Plan: Free
  • Click "Create Database"

2. Get Database Credentials

After creation, go to database → Info tab

Note these values:

  • Hostname
  • Port (usually 5432)
  • Database
  • Username
  • Password

3. Set Environment Variables on Render

Go to your web serviceEnvironment:

Key Value
APP_NAME Validation Engine
APP_ENV production
APP_KEY Generate with php artisan key:generate --show
APP_DEBUG false
APP_URL https://validation-engine-backend.onrender.com
DB_CONNECTION pgsql
DB_HOST From database info
DB_PORT 5432
DB_DATABASE From database info
DB_USERNAME From database info
DB_PASSWORD From database info
LOG_CHANNEL stack
LOG_LEVEL error

4. Update Build/Start Commands

In Render dashboard → Your service → Settings:

  • Build Command: bash build.sh
  • Start Command: php -S 0.0.0.0:$PORT -t public

Click "Save Changes"

5. Push Your Code

cd E:\work\Angular\validation-engine-backend
git add .
git commit -m "Configure for Render with PostgreSQL"
git push origin main

6. Wait & Test

Check logs, then test: https://validation-engine-backend.onrender.com/api/validation_rules

DONE!


🧪 Testing After Setup

Test All Endpoints:

1. Root (should work):

https://validation-engine-backend.onrender.com/

Expected: {"message":"Validation Engine API"...}

2. API Test (should work):

https://validation-engine-backend.onrender.com/api/test

Expected: {"message":"API is working!"...}

3. Validation Rules (should work):

https://validation-engine-backend.onrender.com/api/validation_rules

Expected: []

4. Frontend (should work):

https://validation-engine-frontend.netlify.app
  • Admin page should load
  • No CORS errors
  • Can create validation rules

🐛 If Something Goes Wrong

Check Render Logs

Dashboard → Your Service → Logs

Look for errors like:

  • SQLSTATE[HY000] → Database connection problem
  • No APP_KEY → Need to set APP_KEY
  • Migration failed → Check database credentials

Common Fixes:

Problem: "No application encryption key"

php artisan key:generate --show

Copy output and set as APP_KEY on Render.

Problem: "Connection refused" or "Database error"

  • Check DB_* environment variables
  • Verify database is running (PostgreSQL option)
  • Verify DB_DATABASE path (SQLite option)

Problem: "404 Not Found" for all routes

  • Check Start Command: php -S 0.0.0.0:$PORT -t public
  • Redeploy: Dashboard → "Manual Deploy" → "Clear build cache & deploy"

Problem: Still seeing CORS errors

  • Make sure backend is actually working (test the endpoints above)
  • Check that requests are reaching the backend (look at Render logs)
  • Verify CORS middleware is applied (check bootstrap/app.php)

⏱️ Time Estimate

  • Option 1 (SQLite): 5-10 minutes
  • Option 2 (PostgreSQL): 10-15 minutes

📞 Need Help?

  1. Check Render logs for specific error messages
  2. Test each endpoint individually
  3. Verify all environment variables are set correctly
  4. Try "Clear build cache & deploy" in Render dashboard

Let's get your backend working! Choose an option above and follow the steps. 🚀