IDE:Drupal

Aus ahrensburg.city
Version vom 8. Oktober 2025, 15:10 Uhr von Thorsten (Diskussion | Beiträge) (// via Wikitext Extension for VSCode)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

nginx auf Ubuntu installieren

Voraussetzungen

  • Ubuntu Server (18.04 LTS oder neuer)
  • Root- oder sudo-Berechtigungen

Installation

Paketlisten aktualisieren

sudo apt update

nginx installieren

sudo apt install nginx
sudo rm /etc/nginx/sites-enabled/default

Status prüfen

sudo systemctl status nginx

Firewall konfigurieren

sudo ufw allow 'Nginx Full'
sudo ufw status

Grundlegende Befehle

# nginx starten
sudo systemctl start nginx

# nginx stoppen
sudo systemctl stop nginx

# nginx neustarten
sudo systemctl restart nginx

# Konfiguration neu laden
sudo systemctl reload nginx

# Autostart aktivieren
sudo systemctl enable nginx

Wichtige Verzeichnisse

  • Konfiguration: /etc/nginx/
  • Webroot: /var/www/html/
  • Logs: /var/log/nginx/

Drupal mit PostgreSQL

Datenbank anlegen

sudo -u postgres -i
createdb -E UTF8 -O thorsten drupal
exit # Ausloggen

PHP Installieren

sudo apt install php-fpm php-pgsql php-xml php-curl php-gd php-mbstring php-xmlrpc php-zip php-intl php-json php-cli php-common php-apcu php-bcmath php-soap php-ldap php-imagick php-zip php-gmp -y

Composer Installieren


php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Drupal Installieren

cd /var/www
sudo composer create-project drupal/recommended-project drupal

Nginx Konfigurationsdatei erstellen

Erstelle eine neue Konfigurationsdatei mit folgendem Befehl:

sudo nano /etc/nginx/conf.d/drupal.conf

Füge zum Beispiel folgende Grundkonfiguration ein:

server {
    listen 80;
    server_name localhost;
    root /var/www/drupal/web;

    index index.php index.html index.htm;



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

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

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { allow all; log_not_found off; access_log off; }

    location ~ \..*/.*\.php$ { return 403; }
    location ~ ^/sites/.*/private/ { return 403; }
    location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; }
    location ~ (^|/)\. { return 403; }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    location ~ '\.php$|^/update.php' {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTP_PROXY "";
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_intercept_errors on;
    }

    location ~ ^/sites/.*/files/styles/ {
        try_files $uri @rewrite;
    }

    location ~ ^(/[a-z\-]+)?/system/files/ {
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }
}

Speichere die Datei und lade die Nginx-Konfiguration neu:

sudo systemctl reload nginx