🐧 CrumbForest Debian/Ubuntu Setup (Nginx Edition)

Komplettes LEMP-Setup (Linux, Nginx, MySQL, PHP) für Debian 11/12 und Ubuntu 20.04/22.04 LTS Server.

📋 Übersicht

Status: ✨ Experimental / Alternative
- Debian 11 (Bullseye) / Debian 12 (Bookworm)
- Ubuntu 20.04 LTS / 22.04 LTS
- Native LEMP Stack (Nginx, MariaDB, PHP-FPM)


🔧 Server-Anforderungen

Mindestanforderungen

  • OS: Debian 11+ oder Ubuntu 20.04+
  • RAM: 512 MB (1 GB empfohlen)
  • Disk: 2 GB frei
  • CPU: 1 Core (2+ empfohlen)
  • Network: Internet-Zugang für apt

Software

  • Nginx: 1.18+
  • MariaDB: 10.5+
  • PHP: 8.1+ (8.2/8.3 empfohlen) via FPM
  • Composer: 2.x

📦 Installation

1. System Update

sudo apt update
sudo apt upgrade -y

2. Nginx installieren

# Nginx installieren
sudo apt install nginx -y

# Service starten
sudo systemctl start nginx
sudo systemctl enable nginx

# Status prüfen
sudo systemctl status nginx

Test: curl http://localhost sollte Nginx "Welcome" Page zeigen.

3. MariaDB installieren

# MariaDB installieren
sudo apt install mariadb-server mariadb-client -y

# Service starten
sudo systemctl start mariadb
sudo systemctl enable mariadb

# Sicherheits-Setup
sudo mysql_secure_installation

mysql_secure_installation Antworten:

Enter current password: [ENTER]
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database? [Y/n] Y
Reload privilege tables? [Y/n] Y

4. PHP 8.2+ (FPM) installieren

Anders als bei Apache benötigen wir hier php-fpm.

Option A: Debian/Ubuntu Default (PHP 8.1 FPM)

sudo apt install php-fpm php-mysql php-cli php-curl php-json php-mbstring php-xml php-zip php-bcmath -y

Option B: Neuere PHP Version (empfohlen für 8.2+)

# Sury PPA für neuere PHP Versionen
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https -y

# PPA hinzufügen
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/sury-php.list'
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

# Update & Install PHP 8.3 FPM
sudo apt update
sudo apt install php8.3-fpm php8.3-mysql php8.3-cli php8.3-curl php8.3-mbstring php8.3-xml php8.3-zip php8.3-bcmath -y

PHP-FPM prüfen:

# Status checken
sudo systemctl status php8.3-fpm
# (Ersetze 8.3 durch deine installierte Version)

5. Composer installieren

# Composer herunterladen
curl -sS https://getcomposer.org/installer | php

# Global verfügbar machen
sudo mv composer.phar /usr/local/bin/composer

# Verifizieren
composer --version

🗄️ Datenbank Setup

Datenbank & User erstellen

# Als root einloggen
sudo mysql

# In MySQL Shell:
CREATE DATABASE crumbforest CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE crumbforest_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE USER 'crumbforest_user'@'localhost' IDENTIFIED BY 'SICHERES_PASSWORT_HIER';

GRANT ALL PRIVILEGES ON crumbforest.* TO 'crumbforest_user'@'localhost';
GRANT ALL PRIVILEGES ON crumbforest_test.* TO 'crumbforest_user'@'localhost';

FLUSH PRIVILEGES;
EXIT;

Schema importieren

# Als crumbforest_user
mysql -u crumbforest_user -p crumbforest < crumbforest_sql/schema.sql

# Verifizieren
mysql -u crumbforest_user -p crumbforest -e "SHOW TABLES;"

📁 Projekt Setup

1. Projekt-Verzeichnis anlegen

# Als root oder mit sudo
sudo mkdir -p /var/www/crumbforest
cd /var/www/crumbforest

# Projekt clonen oder hochladen
sudo git clone YOUR_REPO_URL .
# ODER via SCP/SFTP hochladen

2. Dependencies installieren

cd /var/www/crumbforest
sudo composer install --no-dev --optimize-autoloader

3. .env konfigurieren

sudo cp .env .env.backup  # falls schon vorhanden
sudo nano .env

Wichtige Anpassungen:

# Base URL
BASE_URL=http://your-domain.com

# Database
DB_HOST=localhost
DB_NAME=crumbforest
DB_USER=crumbforest_user
DB_PASS=DEIN_SICHERES_PASSWORT

# JWT Secret (KRITISCH!)
JWT_SECRET=$(openssl rand -base64 32)

# Paths
UPLOAD_DIR=/var/www/crumbforest/web_root/uploads
LOG_FILE=/var/www/crumbforest/logs/crumbforest.log

4. Permissions setzen

Nginx läuft standardmäßig (wie Apache) unter dem User www-data.

# Owner auf www-data setzen
sudo chown -R www-data:www-data /var/www/crumbforest

# Base permissions
sudo chmod -R 755 /var/www/crumbforest

# Writable directories
sudo chmod -R 775 /var/www/crumbforest/logs
sudo chmod -R 775 /var/www/crumbforest/web_root/uploads

# .env schützen
sudo chmod 600 /var/www/crumbforest/.env

# Logs erstellen
sudo mkdir -p /var/www/crumbforest/logs
sudo touch /var/www/crumbforest/logs/crumbforest.log
sudo chown www-data:www-data /var/www/crumbforest/logs/crumbforest.log

🌐 Nginx Server Block (VirtualHost)

1. Config erstellen

sudo nano /etc/nginx/sites-available/crumbforest

Inhalt:

server {
   listen 80;
   server_name your-domain.com www.your-domain.com;

   root /var/www/crumbforest/web_root;
   index index.php index.html;

   # Logs
   access_log /var/log/nginx/crumbforest_access.log;
   error_log /var/log/nginx/crumbforest_error.log;

   # Gzip Compression
   gzip on;
   gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

   # Security Headers
   add_header X-Frame-Options "SAMEORIGIN";
   add_header X-XSS-Protection "1; mode=block";
   add_header X-Content-Type-Options "nosniff";

   # Haupt-Location / API Router
   location / {
       try_files $uri $uri/ /index.php?$query_string;
   }

   # .env und andere sensible Dateien schützen
   location ~ \.(env|git|htaccess|htpasswd) {
       deny all;
   }

   # PHP-Verarbeitung
   location ~ \.php$ {
       include snippets/fastcgi-php.conf;

       # WICHTIG: Pfad zur richtigen PHP version prüfen!
       # z.B. php8.3-fpm.sock oder php8.1-fpm.sock
       fastcgi_pass unix:/run/php/php8.3-fpm.sock;

       # PHP Settings überschreiben (Äquivalent zu php_value in Apache)
       fastcgi_param PHP_VALUE "upload_max_filesize=10M \n post_max_size=12M \n memory_limit=256M";

       include fastcgi_params;
   }

   # Uploads (Static Files) caching
   location /uploads {
       expires 30d;
       add_header Cache-Control "public, no-transform";
   }
}

WICHTIG: Prüfe den fastcgi_pass Pfad:

ls /run/php/

Passe die Version in der Config entsprechend an (z.B. php8.1-fpm.sock).

2. Site aktivieren

# Symlink erstellen
sudo ln -s /etc/nginx/sites-available/crumbforest /etc/nginx/sites-enabled/

# Default entfernen (optional)
sudo rm /etc/nginx/sites-enabled/default

# Config testen
sudo nginx -t

# Nginx neu starten
sudo systemctl reload nginx

🔒 SSL/HTTPS Setup (Let's Encrypt)

Certbot für Nginx installieren

# Certbot installieren
sudo apt install certbot python3-certbot-nginx -y

# Automatisches SSL Setup
sudo certbot --nginx -d your-domain.com -d www.your-domain.com

🐛 Troubleshooting Nginx

502 Bad Gateway

Meistens ein Problem mit PHP-FPM.
1. Läuft PHP-FPM? sudo systemctl status php8.3-fpm
2. Stimmt der Socket Pfad in der Config? (/run/php/...)
3. tail -f /var/log/nginx/crumbforest_error.log

403 Forbidden

Permissions prüfen:
sudo chown -R www-data:www-data /var/www/crumbforest

404 Not Found bei API Calls

Prüfen ob try_files $uri $uri/ /index.php?$query_string; korrekt gesetzt ist.


Generated by Antigravity - based on SETUP_DEBIAN.md