3.6 KiB
3.6 KiB
PHP Projekt Setup für Netcup
Projektstruktur
Das Deployment erwartet diese Struktur in deinem Hauptprojekt:
dein-projekt/ # Hauptordner
├── ansible/ # Hier sind wir jetzt
│ └── netcup-simple-deploy/
├── docker/ # Docker-Konfiguration
│ ├── Dockerfile # (optional, wird sonst automatisch erstellt)
│ └── docker-compose.yml # (optional)
├── src/ # PHP Framework/Library Dateien
│ ├── classes/
│ ├── includes/
│ └── ...
├── public/ # Web-Root (öffentlich zugänglich)
│ ├── index.php # Haupteinstiegspunkt
│ ├── css/
│ ├── js/
│ ├── images/
│ └── ...
├── storage/ # (optional) Logs, Cache, etc.
├── cache/ # (optional) Cache-Dateien
├── logs/ # (optional) Log-Dateien
└── .env # (optional) Umgebungsvariablen
Quick Setup
1. Konfiguration
cd ansible/netcup-simple-deploy
vim inventory/hosts.yml
Ändere diese Werte:
ansible_host: DEINE-NETCUP-IP
domain: "deine-domain.com"
ssl_email: "deine@email.com"
local_app_path: "../.." # Zeigt auf dein Hauptprojekt
php_version: "8.2" # PHP Version
2. Deployment
make deploy
Das war's! Deine PHP-App läuft unter https://deine-domain.com
Was passiert beim Deployment?
- Dateien übertragen:
public/,src/,docker/→ Server - Dockerfile erstellen: Falls keins in
docker/vorhanden - Docker Container bauen: PHP + Apache + deine App
- Nginx Proxy: SSL-Termination und Weiterleitung
- SSL-Zertifikat: Automatisch mit Let's Encrypt
Für verschiedene PHP-Setups
Eigenes Dockerfile verwenden
Lege dein Dockerfile in docker/Dockerfile:
FROM php:8.2-apache
# Deine spezifischen PHP Extensions
RUN docker-php-ext-install pdo pdo_mysql
# Custom Apache Config
COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf
# App Dateien
COPY public/ /var/www/html/
COPY src/ /var/www/src/
EXPOSE 80
Mit Composer Dependencies
FROM php:8.2-apache
# Composer installieren
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Dependencies installieren
COPY composer.json composer.lock /var/www/
WORKDIR /var/www
RUN composer install --no-dev --optimize-autoloader
# App kopieren
COPY public/ /var/www/html/
COPY src/ /var/www/src/
Mit Database
Erweitere inventory/hosts.yml:
app_env:
APP_ENV: "production"
DATABASE_HOST: "your-db-host"
DATABASE_NAME: "your-db-name"
DATABASE_USER: "your-db-user"
DATABASE_PASS: "your-db-password"
Nützliche Befehle
# Logs anschauen
make logs
make error-logs
# Cache löschen
make clear-cache
# Permissions reparieren
make fix-permissions
# Composer auf Server ausführen
make composer-install
# Live logs verfolgen
make tail-logs
# SSH auf Server
make ssh
Troubleshooting
App lädt nicht?
# Apache Fehler-Logs prüfen
make error-logs
# Allgemeine Logs
make logs
# Container Status
make status
Permissions-Probleme?
# Permissions reparieren
make fix-permissions
Nach Code-Änderungen?
# Einfach neu deployen
make deploy
Database-Verbindung?
# Umgebungsvariablen prüfen
ansible all -m shell -a "docker exec \$(docker ps -q | head -1) env | grep DATABASE"
Das Setup ist optimiert für deine bestehende Projektstruktur - keine Änderungen an deinem Code nötig! 🎉