Skip to content

Instantly share code, notes, and snippets.

@khuppenbauer
Created January 16, 2026 10:52
Show Gist options
  • Select an option

  • Save khuppenbauer/9ef1529e5dfbae468d553f80e3aa4eba to your computer and use it in GitHub Desktop.

Select an option

Save khuppenbauer/9ef1529e5dfbae468d553f80e3aa4eba to your computer and use it in GitHub Desktop.
devenv
{ pkgs, lib, config, ... }:
{
packages = with pkgs; [
postgresql
mariadb
apacheHttpd
openssl
];
# PHP 8.4 mit allen wichtigen Extensions
languages.php = {
enable = true;
version = "8.4";
extensions = [
"pdo"
"pdo_mysql"
"pdo_pgsql"
"mysqli"
"mbstring"
"curl"
"gd"
"intl"
"zip"
"xml"
"simplexml"
"opcache"
];
ini = ''
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
display_errors = On
error_reporting = E_ALL
date.timezone = Europe/Berlin
'';
};
# PostgreSQL mit PostGIS
services.postgres = {
enable = true;
package = pkgs.postgresql_16;
extensions = extensions: [
extensions.postgis
];
initialDatabases = [
{ name = "devdb"; }
];
initialScript = ''
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
'';
listen_addresses = "127.0.0.1";
port = 5432;
settings = {
logging_collector = "on";
log_directory = "pg_log";
log_filename = "postgresql-%Y-%m-%d.log";
log_connections = "on";
log_disconnections = "on";
};
};
# MariaDB
services.mysql = {
enable = true;
package = pkgs.mariadb;
initialDatabases = [
{ name = "devdb"; }
];
ensureUsers = [
{
name = "devuser";
password = "devpass";
ensurePermissions = {
"devdb.*" = "ALL PRIVILEGES";
};
}
];
settings = {
mysqld = {
log_error = ".devenv/state/mysql/error.log";
general_log = 1;
general_log_file = ".devenv/state/mysql/general.log";
bind-address = "127.0.0.1";
port = 3306;
};
};
};
# Apache Webserver mit SSL
services.httpd = {
enable = true;
package = pkgs.apacheHttpd;
settings = {
Listen = "443";
ServerName = "localhost";
LoadModule = [
"mpm_prefork_module modules/mod_mpm_prefork.so"
"authz_core_module modules/mod_authz_core.so"
"dir_module modules/mod_dir.so"
"mime_module modules/mod_mime.so"
"log_config_module modules/mod_log_config.so"
"rewrite_module modules/mod_rewrite.so"
"ssl_module modules/mod_ssl.so"
"socache_shmcb_module modules/mod_socache_shmcb.so"
"proxy_module modules/mod_proxy.so"
"proxy_fcgi_module modules/mod_proxy_fcgi.so"
];
};
virtualHosts = {
"localhost" = {
listen = [
{ ip = "127.0.0.1"; port = 443; ssl = true; }
{ ip = "127.0.0.1"; port = 80; }
];
documentRoot = "./public";
extraConfig = ''
# SSL Konfiguration
SSLEngine on
SSLCertificateFile ${config.env.DEVENV_STATE}/apache/localhost.crt
SSLCertificateKeyFile ${config.env.DEVENV_STATE}/apache/localhost.key
# PHP-FPM
<FilesMatch \.php$>
SetHandler "proxy:unix:${config.env.DEVENV_STATE}/php-fpm.sock|fcgi://localhost"
</FilesMatch>
# .htaccess Support
<Directory "${config.env.DEVENV_ROOT}/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Logging
ErrorLog ${config.env.DEVENV_STATE}/apache/error.log
CustomLog ${config.env.DEVENV_STATE}/apache/access.log combined
'';
};
"app.local" = {
listen = [
{ ip = "127.0.0.1"; port = 443; ssl = true; }
];
documentRoot = "./apps/app1";
extraConfig = ''
SSLEngine on
SSLCertificateFile ${config.env.DEVENV_STATE}/apache/localhost.crt
SSLCertificateKeyFile ${config.env.DEVENV_STATE}/apache/localhost.key
<FilesMatch \.php$>
SetHandler "proxy:unix:${config.env.DEVENV_STATE}/php-fpm.sock|fcgi://localhost"
</FilesMatch>
<Directory "${config.env.DEVENV_ROOT}/apps/app1">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
'';
};
};
};
# PHP-FPM für Apache
services.php-fpm = {
enable = true;
pools.web = {
listen = "${config.env.DEVENV_STATE}/php-fpm.sock";
settings = {
"pm" = "dynamic";
"pm.max_children" = 10;
"pm.start_servers" = 2;
"pm.min_spare_servers" = 1;
"pm.max_spare_servers" = 5;
};
};
};
# Erstelle SSL-Zertifikate und Verzeichnisse beim Start
enterShell = ''
# Erstelle notwendige Verzeichnisse
mkdir -p public apps/app1 .devenv/state/apache
# Generiere selbstsigniertes SSL-Zertifikat falls nicht vorhanden
if [ ! -f .devenv/state/apache/localhost.key ]; then
echo "📜 Erstelle SSL-Zertifikat..."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout .devenv/state/apache/localhost.key \
-out .devenv/state/apache/localhost.crt \
-subj "/C=DE/ST=BW/L=Schorndorf/O=Dev/CN=localhost"
echo "✓ SSL-Zertifikat erstellt"
fi
# Erstelle beispiel index.php falls nicht vorhanden
if [ ! -f public/index.php ]; then
cat > public/index.php << 'EOF'
<?php
phpinfo();
EOF
echo "✓ Beispiel index.php erstellt in public/"
fi
# Erstelle beispiel .htaccess
if [ ! -f public/.htaccess ]; then
cat > public/.htaccess << 'EOF'
# Beispiel .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
EOF
echo "✓ Beispiel .htaccess erstellt in public/"
fi
echo ""
echo "🌐 =========================================="
echo " Development Environment Ready!"
echo "=========================================="
echo ""
echo "🌍 Apache Webserver:"
echo " HTTPS: https://localhost (Standard)"
echo " HTTP: http://localhost"
echo " VHost: https://app.local (füge zu /etc/hosts hinzu)"
echo " Document Root: ./public"
echo ""
echo "🐘 PostgreSQL (PostGIS):"
echo " Host: 127.0.0.1"
echo " Port: 5432"
echo " Database: devdb"
echo " User: \$USER"
echo " Connect: psql devdb"
echo ""
echo "🐬 MariaDB:"
echo " Host: 127.0.0.1"
echo " Port: 3306"
echo " Database: devdb"
echo " User: devuser"
echo " Password: devpass"
echo " Connect: mysql -u devuser -pdevpass devdb"
echo ""
echo "🔧 PHP:"
echo " Version: $(php -v | head -n1)"
echo " Extensions: pdo_mysql, pdo_pgsql, gd, intl, ..."
echo ""
echo "📝 Logs:"
echo " Apache Error: .devenv/state/apache/error.log"
echo " Apache Access: .devenv/state/apache/access.log"
echo " MariaDB: .devenv/state/mysql/error.log"
echo " PostgreSQL: .devenv/state/postgres/pg_log/"
echo ""
echo "💡 Tipps:"
echo " - .htaccess wird in allen Verzeichnissen unterstützt"
echo " - Füge '127.0.0.1 app.local' zu /etc/hosts für VHost hinzu"
echo " - Logs live: tail -f .devenv/state/apache/error.log"
echo ""
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment