Zum Hauptinhalt springen
Zurück zur Kategorie

WordPress Installation und Optimierung: VPS Anleitung

Anleitung zur Installation und Optimierung von WordPress auf einem VPS. LEMP Stack Setup, wp-config.php Einstellungen, Dateiberechtigungen, SSL, OPcache Performance-Optimierung und Sicherheitshärtung.

Lesezeit: 20 min Web Hosting / Anwendungen
wordpressvpslempnginxphp-fpmmysqlsslopcachesicherheit

Inhaltsverzeichnis

WordPress Installation und Optimierung: VPS Anleitung

WordPress ist das weltweit am häufigsten verwendete Content-Management-System. WordPress auf einem VPS statt auf Shared Hosting zu betreiben bietet mehr Kontrolle, bessere Performance und Anpassungsmöglichkeiten. Diese Anleitung behandelt WordPress-Installation, Konfiguration und Optimierung auf einem LEMP Stack.

Voraussetzungen: LEMP Stack

hljs bash
# Systemaktualisierung
sudo apt update && sudo apt upgrade -y

# Nginx installieren
sudo apt install nginx -y
sudo systemctl enable nginx

# MariaDB installieren
sudo apt install mariadb-server -y
sudo systemctl enable mariadb
sudo mysql_secure_installation

# PHP 8.2 und erforderliche Erweiterungen für WordPress
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-xml php8.2-curl \
  php8.2-mbstring php8.2-zip php8.2-gd php8.2-imagick php8.2-intl \
  php8.2-bcmath php8.2-soap -y
sudo systemctl enable php8.2-fpm

WordPress-Datenbank erstellen

hljs sql
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'starkes-passwort';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

WordPress herunterladen und installieren

hljs bash
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/mysite.com

# Dateiberechtigungen setzen
sudo chown -R www-data:www-data /var/www/mysite.com
sudo find /var/www/mysite.com -type d -exec chmod 755 {} \;
sudo find /var/www/mysite.com -type f -exec chmod 644 {} \;

wp-config.php Konfiguration

hljs php
// Datenbankeinstellungen
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'starkes-passwort' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );

// Dateibearbeitung deaktivieren (Sicherheit)
define('DISALLOW_FILE_EDIT', true);

// SSL erzwingen
define('FORCE_SSL_ADMIN', true);

// Speicherlimit
define('WP_MEMORY_LIMIT', '256M');

Nginx Konfiguration (für WordPress)

hljs nginx
server {
    listen 80;
    server_name mysite.com www.mysite.com;
    root /var/www/mysite.com;
    index index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location = /xmlrpc.php { deny all; }
    location = /wp-config.php { deny all; }
    location ~ /\. { deny all; }

    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|svg)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    client_max_body_size 64M;
}
hljs bash
sudo ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

SSL-Zertifikat

hljs bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d mysite.com -d www.mysite.com

PHP-Optimierung (OPcache)

hljs ini
opcache.enable = 1
opcache.memory_consumption = 256
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 2
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_vars = 3000

Sicherheitshärtung

hljs bash
# wp-config.php absichern
sudo chmod 600 /var/www/mysite.com/wp-config.php

Setzen Sie die Berechtigungen von wp-config.php auf 600. Diese Datei enthält Ihr Datenbankpasswort.

Auf REXE-Servern werden für WordPress mindestens 2 GB RAM empfohlen. Für stark frequentierte Websites bevorzugen Sie 4 GB+ RAM und SSD-Speicher.

Fazit

Ihre WordPress-Website läuft jetzt auf einem LEMP Stack auf einem VPS, ist mit SSL gesichert und mit OPcache optimiert. Halten Sie Ihre Website mit regelmäßigen Backups, Sicherheitsupdates und Performance-Monitoring gesund.