So hosten Sie eine Website auf Ihrem VPS (Nginx/Apache + PHP + SSL)

Geschätzte Lektüre: 3 Minuten

Diese Anleitung zeigt Ihnen, wie Sie eine Website auf Ihrem VeerHost-VPS von Grund auf hosten – inklusive Installation eines Webservers (Nginx oder Apache), PHP, Erstellung eines Virtual Hosts, Hochladen Ihrer Dateien und Absicherung mit einem kostenlosen Let’s-Encrypt-SSL-Zertifikat. Funktioniert auf Ubuntu 22.04, Ubuntu 24.04 und Debian.

Option A: Nginx (für die meisten Websites empfohlen)

1. Nginx und PHP installieren

apt update
apt install -y nginx php-fpm php-mysql php-cli php-curl php-zip php-mbstring php-xml php-gd

PHP-Version prüfen:

php -v

2. Das Website-Verzeichnis erstellen

mkdir -p /var/www/yourdomain.com/html
chown -R www-data:www-data /var/www/yourdomain.com
chmod -R 755 /var/www/yourdomain.com

3. Einen Nginx-Virtual-Host erstellen

nano /etc/nginx/sites-available/yourdomain.com

Fügen Sie diese Konfiguration ein (ersetzen Sie yourdomain.com durch Ihre echte Domain und passen Sie bei Bedarf die PHP-Version an):

server {
    listen 80;
    listen [::]:80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
    }

    location ~ /.ht {
        deny all;
    }
}

Hinweis: Prüfen Sie Ihren PHP-FPM-Socket mit ls /var/run/php/ und verwenden Sie den korrekten Dateinamen (z. B. php8.1-fpm.sock oder php8.3-fpm.sock).

Aktivieren Sie die Site und testen Sie sie:

ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx

Option B: Apache

1. Apache und PHP installieren

apt update
apt install -y apache2 php libapache2-mod-php php-mysql php-curl php-zip php-mbstring php-xml php-gd

2. Das Website-Verzeichnis erstellen

mkdir -p /var/www/yourdomain.com/html
chown -R www-data:www-data /var/www/yourdomain.com

3. Einen Apache-Virtual-Host erstellen

nano /etc/apache2/sites-available/yourdomain.com.conf
<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/html

    <Directory /var/www/yourdomain.com/html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/yourdomain_error.log
    CustomLog ${APACHE_LOG_DIR}/yourdomain_access.log combined
</VirtualHost>
a2ensite yourdomain.com.conf
a2enmod rewrite
apache2ctl configtest
systemctl reload apache2

MySQL installieren (falls nötig)

apt install -y mysql-server
mysql_secure_installation

Erstellen Sie eine Datenbank und einen Benutzer für Ihre Website:

mysql -u root -p

CREATE DATABASE mywebsite;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON mywebsite.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Website-Dateien hochladen

Von Ihrem lokalen Rechner aus können Sie Dateien per SCP hochladen:

scp -r /path/to/local/files root@YOUR_VPS_IP:/var/www/yourdomain.com/html/

Oder verwenden Sie einen FTP-Client wie FileZilla mit SFTP (Port 22) und Ihren SSH-Zugangsdaten.

Kostenloses SSL-Zertifikat installieren (Let’s Encrypt)

Stellen Sie sicher, dass Ihr Domain-DNS bereits auf Ihre VPS-IP zeigt, bevor Sie diesen Schritt ausführen. Installieren Sie Certbot:

apt install -y certbot python3-certbot-nginx
# oder für Apache:
apt install -y certbot python3-certbot-apache

Holen und installieren Sie das Zertifikat:

# Nginx:
certbot --nginx -d yourdomain.com -d www.yourdomain.com

# Apache:
certbot --apache -d yourdomain.com -d www.yourdomain.com

Certbot richtet HTTPS automatisch ein und konfiguriert die Verlängerung. Testen Sie die Erneuerung:

certbot renew --dry-run

Überprüfen, ob alles funktioniert

Erstellen Sie eine Test-PHP-Datei, um zu bestätigen, dass alles funktioniert:

echo '<?php phpinfo(); ?>' > /var/www/yourdomain.com/html/info.php

Rufen Sie http://yourdomain.com/info.php in Ihrem Browser auf. Sie sollten die PHP-Infoseite sehen. Löschen Sie die Datei danach wieder:

rm /var/www/yourdomain.com/html/info.php

Sobald Ihre Website live ist, sollten Sie Ihren VPS absichern und regelmäßige Backups einrichten.

  • Limited-Time Offer

WordPress Hosting — Just $1/month for 12 months

Only 13 spots left

Get WordPress-ready hosting with free SSL, fast NVMe storage, malware protection, and 24/7 expert support—everything you need to launch and keep your website running smoothly.

12-month term • New customers only • Limited availability

Launchpad