Files
xamxam/nginx/docs/TEST_DATABASE_SETUP.md
2026-04-15 14:24:44 +02:00

2.8 KiB

Test Database Setup - Post-ERG

Guide for deploying the test database to production server.


🎯 Quick Deploy

just deploy-db

This automatically:

  1. Checks remote DB doesn't exist (safety check)
  2. Uploads storage/test.db to the server
  3. Sets correct permissions (660, www-data:posterg)

🔧 Prerequisites (One-Time Setup)

1. Install PHP SQLite Extension

ssh posterg
sudo apt update
sudo apt install php8.4-sqlite3
sudo systemctl restart php8.4-fpm

2. Verify Installation

ssh posterg
php -m | grep sqlite3
# Should output: pdo_sqlite, sqlite3

🧪 Complete Testing Workflow

1. Create Test Data Locally

# Create empty test database from schema
just init-db

# Or create with sample fixtures
just fixtures

2. Deploy Test Database

just deploy-db

3. Test the Site

Visit: https://posterg.erg.be/

4. Check What Database is Being Used

ssh posterg
php -r "require_once '/var/www/posterg/src/Database.php'; echo 'Using: ' . Database::getInstance()->getDatabasePath() . PHP_EOL;"

5. Switch Back to Production

ssh posterg
rm /var/www/posterg/storage/test.db

🔒 Permissions Explained

/var/www/posterg/storage/
drwxrwxr-x  www-data posterg  # 775 - group writable

/var/www/posterg/storage/test.db
-rw-rw----  www-data posterg  # 660 - owner/group read/write

🐛 Troubleshooting

"could not find driver"

ssh posterg
sudo apt install php8.4-sqlite3
sudo systemctl restart php8.4-fpm

"unable to open database file"

ssh posterg
chown www-data:posterg /var/www/posterg/storage/test.db
chmod 660 /var/www/posterg/storage/test.db
chmod 775 /var/www/posterg/storage/

"attempt to write a readonly database"

ssh posterg
chmod 775 /var/www/posterg/storage/
rm -f /var/www/posterg/storage/test.db-*

⚠️ Important Notes

Production Safety

just deploy excludes all .db files by default. Only just deploy-db uploads the test database.

Backup Production Database

ssh posterg
cp /var/www/posterg/storage/posterg.db /var/www/posterg/storage/posterg.db.backup.$(date +%Y%m%d)

Command Description
just init-db Create empty test database
just fixtures Create test database with sample data
just deploy-db Deploy test database to server

Deployment Checklist

After running just deploy-db, verify:

  • Database file exists: ssh posterg "ls -la /var/www/posterg/storage/test.db"
  • Correct permissions: -rw-rw---- www-data posterg
  • Site loads: Visit https://posterg.erg.be/
  • No errors in logs: ssh posterg "tail /var/log/nginx/posterg_error.log"