|
| 1 | +# Coolify Deployment Guide voor Speedtest Tracker |
| 2 | + |
| 3 | +## Waarom crasht de container? 🔍 |
| 4 | + |
| 5 | +De container crasht omdat **Laravel een APP_KEY vereist** om te kunnen starten. Wanneer je `php artisan serve` uitvoert zonder APP_KEY, crasht de applicatie onmiddellijk. |
| 6 | + |
| 7 | +### Container Startup Process |
| 8 | +1. Container start → `start-container` script |
| 9 | +2. Supervisord start → voert `php artisan serve --host=0.0.0.0 --port=80` uit |
| 10 | +3. Laravel bootstrap → **FAALT als APP_KEY ontbreekt** |
| 11 | +4. Container crasht → restart loop (10x restarts) |
| 12 | + |
| 13 | +## Oplossing: Verplichte Environment Variables 🔧 |
| 14 | + |
| 15 | +### Stap 1: Genereer APP_KEY |
| 16 | + |
| 17 | +Je hebt **3 opties** om een APP_KEY te genereren: |
| 18 | + |
| 19 | +#### Optie A: Met composer (lokaal) |
| 20 | +```bash |
| 21 | +# In de repository directory |
| 22 | +composer install --no-dev --optimize-autoloader |
| 23 | +php artisan key:generate --show |
| 24 | +``` |
| 25 | + |
| 26 | +#### Optie B: Met Docker (zonder lokale PHP) |
| 27 | +```bash |
| 28 | +docker run --rm -v $(pwd):/app -w /app composer:latest composer install --no-dev --optimize-autoloader |
| 29 | +docker run --rm -v $(pwd):/app -w /app php:8.4-cli php artisan key:generate --show |
| 30 | +``` |
| 31 | + |
| 32 | +#### Optie C: Handmatig genereren |
| 33 | +```bash |
| 34 | +# Genereer random base64 string (32 bytes) |
| 35 | +echo "base64:$(openssl rand -base64 32)" |
| 36 | +``` |
| 37 | + |
| 38 | +De output ziet er zo uit: `base64:AbCdEf1234567890...` |
| 39 | + |
| 40 | +### Stap 2: Configureer Environment Variables in Coolify |
| 41 | + |
| 42 | +Ga naar je applicatie in Coolify en voeg deze environment variables toe: |
| 43 | + |
| 44 | +#### ⚠️ VERPLICHT (zonder deze crasht de app): |
| 45 | +```bash |
| 46 | +APP_KEY=base64:JouwGegenereerdeKeyHier== |
| 47 | +APP_ENV=production |
| 48 | +APP_DEBUG=false |
| 49 | +APP_URL=https://network.makkerlab.nl |
| 50 | +DB_CONNECTION=sqlite |
| 51 | +``` |
| 52 | + |
| 53 | +#### 📝 Aanbevolen (voor productie): |
| 54 | +```bash |
| 55 | +# Logging |
| 56 | +LOG_LEVEL=warning |
| 57 | +LOG_CHANNEL=stack |
| 58 | + |
| 59 | +# Session |
| 60 | +SESSION_DRIVER=cookie |
| 61 | +SESSION_LIFETIME=10080 |
| 62 | + |
| 63 | +# Cache |
| 64 | +CACHE_STORE=database |
| 65 | + |
| 66 | +# Queue |
| 67 | +QUEUE_CONNECTION=database |
| 68 | + |
| 69 | +# Mail (optioneel - voor notificaties) |
| 70 | +MAIL_MAILER=smtp |
| 71 | +MAIL_HOST=your-smtp-host.com |
| 72 | +MAIL_PORT=587 |
| 73 | + |
| 74 | +MAIL_PASSWORD=your-password |
| 75 | +MAIL_ENCRYPTION=tls |
| 76 | + |
| 77 | +MAIL_FROM_NAME="Speedtest Tracker" |
| 78 | +``` |
| 79 | + |
| 80 | +### Stap 3: Nixpacks Build Configuratie |
| 81 | + |
| 82 | +Nixpacks detecteert automatisch Laravel, maar je kunt het optimaliseren met een `nixpacks.toml`: |
| 83 | + |
| 84 | +```toml |
| 85 | +[phases.setup] |
| 86 | +nixPkgs = ["nodejs_22", "php84", "php84Packages.composer"] |
| 87 | + |
| 88 | +[phases.install] |
| 89 | +cmds = [ |
| 90 | + "composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist", |
| 91 | + "npm ci --only=production" |
| 92 | +] |
| 93 | + |
| 94 | +[phases.build] |
| 95 | +cmds = [ |
| 96 | + "npm run build", |
| 97 | + "php artisan config:cache", |
| 98 | + "php artisan route:cache", |
| 99 | + "php artisan view:cache" |
| 100 | +] |
| 101 | + |
| 102 | +[start] |
| 103 | +cmd = "php artisan serve --host=0.0.0.0 --port=3000" |
| 104 | +``` |
| 105 | + |
| 106 | +**Let op**: Als je `nixpacks.toml` toevoegt, commit en push naar je repository! |
| 107 | + |
| 108 | +### Stap 4: Database Migraties |
| 109 | + |
| 110 | +Na de eerste succesvolle deployment moet je de database initialiseren: |
| 111 | + |
| 112 | +1. **Via Coolify Terminal** (in de container): |
| 113 | +```bash |
| 114 | +php artisan migrate --force |
| 115 | +php artisan db:seed --force # Optioneel, voor demo data |
| 116 | +``` |
| 117 | + |
| 118 | +2. **Of voeg toe aan build commands** in Coolify: |
| 119 | +``` |
| 120 | +php artisan migrate --force |
| 121 | +``` |
| 122 | + |
| 123 | +### Stap 5: Storage Permissies |
| 124 | + |
| 125 | +Zorg dat storage directories schrijfbaar zijn. Voeg toe aan build commands: |
| 126 | +```bash |
| 127 | +chmod -R 775 storage bootstrap/cache |
| 128 | +``` |
| 129 | + |
| 130 | +## Deployment Checklist ✅ |
| 131 | + |
| 132 | +- [ ] APP_KEY gegenereerd en toegevoegd aan environment variables |
| 133 | +- [ ] Alle verplichte environment variables ingesteld |
| 134 | +- [ ] APP_URL ingesteld op juiste domein |
| 135 | +- [ ] DB_CONNECTION ingesteld (sqlite voor standaard) |
| 136 | +- [ ] Container gedeployed zonder crashes |
| 137 | +- [ ] Database migraties uitgevoerd |
| 138 | +- [ ] Applicatie bereikbaar via browser |
| 139 | +- [ ] Inloggen werkt (standaard credentials controleren) |
| 140 | + |
| 141 | +## Troubleshooting 🔍 |
| 142 | + |
| 143 | +### Container blijft crashen? |
| 144 | + |
| 145 | +1. **Check logs in Coolify**: |
| 146 | + - Ga naar "Logs" tab |
| 147 | + - Kijk naar de runtime logs (niet build logs) |
| 148 | + - Zoek naar error messages van Laravel |
| 149 | + |
| 150 | +2. **Veelvoorkomende errors**: |
| 151 | + |
| 152 | +``` |
| 153 | +RuntimeException: No application encryption key has been specified. |
| 154 | +→ Oplossing: APP_KEY ontbreekt of is incorrect |
| 155 | +
|
| 156 | +SQLSTATE[HY000]: General error: 1 no such table |
| 157 | +→ Oplossing: Migraties zijn niet uitgevoerd (run: php artisan migrate --force) |
| 158 | +
|
| 159 | +file_put_contents(/var/www/html/storage/framework/sessions/...): Failed to open stream |
| 160 | +→ Oplossing: Storage directories niet schrijfbaar (run: chmod -R 775 storage) |
| 161 | +``` |
| 162 | + |
| 163 | +3. **Open een terminal in de container** (in Coolify): |
| 164 | +```bash |
| 165 | +# Check of APP_KEY is ingesteld |
| 166 | +php artisan tinker --execute="echo config('app.key');" |
| 167 | + |
| 168 | +# Check database connectie |
| 169 | +php artisan migrate:status |
| 170 | + |
| 171 | +# Check storage permissies |
| 172 | +ls -la storage/ |
| 173 | +``` |
| 174 | + |
| 175 | +### Applicatie draait maar geeft errors? |
| 176 | + |
| 177 | +1. **Check de logs**: |
| 178 | +```bash |
| 179 | +tail -f storage/logs/laravel.log |
| 180 | +``` |
| 181 | + |
| 182 | +2. **Clear cache** (na environment wijzigingen): |
| 183 | +```bash |
| 184 | +php artisan config:clear |
| 185 | +php artisan cache:clear |
| 186 | +php artisan view:clear |
| 187 | +``` |
| 188 | + |
| 189 | +## Verificatie 🎯 |
| 190 | + |
| 191 | +Na succesvolle deployment: |
| 192 | + |
| 193 | +1. **Container status** = Running (geen restarts) |
| 194 | +2. **Browser toegang** → https://network.makkerlab.nl werkt |
| 195 | +3. **Geen errors** in logs |
| 196 | +4. **Login pagina** wordt getoond |
| 197 | + |
| 198 | +## Standaard Login Credentials 🔑 |
| 199 | + |
| 200 | +Check de documentatie of database seeders voor standaard credentials: |
| 201 | +```bash |
| 202 | +# In container terminal |
| 203 | +php artisan tinker --execute="App\Models\User::first();" |
| 204 | +``` |
| 205 | + |
| 206 | +## Support & Documentatie 📚 |
| 207 | + |
| 208 | +- Officiële docs: https://docs.speedtest-tracker.dev |
| 209 | +- Environment variables: https://docs.speedtest-tracker.dev/getting-started/environment-variables |
| 210 | +- Installation guide: https://docs.speedtest-tracker.dev/getting-started/installation |
| 211 | +- GitHub: https://github.com/alexjustesen/speedtest-tracker |
| 212 | + |
| 213 | +--- |
| 214 | + |
| 215 | +**Nog steeds problemen?** Share de **runtime logs** (niet build logs) uit Coolify! |
0 commit comments