Wie man Grav CMS mit Nginx auf Ubuntu 20.04 installiert

Grav ist ein kostenloses, quelloffenes und flaches CMS, das keine Datenbank benötigt. Es basiert auf PHP und bietet verschiedene Funktionen, die anderen CMS wie WordPress, Joomla, etc. nicht zur Verfügung stehen. Es ist einfach, leicht zu bedienen und kommt mit einigen der Schlüsseltechnologien wie Twig Templating, Markdown, YAML, Parsedown, Doctrine Cache, Gregwar Image Library und Symfony Console.

In diesem Tutorial werde ich dir zeigen, wie du Grav CMS mit Nginx und Let’s Encrypt SSL auf einem Ubuntu 20.04 Server installierst.

Voraussetzungen

  • Ein Server, auf dem Ubuntu 20.04 läuft.
  • Ein gültiger Domainname, der auf die IP deines Servers zeigt.
  • Ein Root-Passwort ist auf dem Server konfiguriert.

Erste Schritte

Aktualisiere zunächst die Systempakete auf die aktuelle Version, indem du den folgenden Befehl ausführst:

apt-get update -y

Sobald alle Pakete aktualisiert sind, kannst du mit dem nächsten Schritt fortfahren.

Nginx und PHP installieren

Zuerst musst du den Nginx Webserver, PHP und andere PHP-Erweiterungen auf deinem System installieren. Du kannst sie alle mit dem folgenden Befehl installieren:

apt-get install nginx php php-cli php-fpm php-common php-curl php-gd php-json php-mbstring php-xml php-zip php-opcache php-apcu unzip -y

Sobald alle Pakete installiert sind, überprüfe die PHP-Version mit dem folgenden Befehl:

php --version

Du solltest die folgende Ausgabe erhalten:

PHP 7.4.3 (cli) (built: Jul  5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Als nächstes bearbeite die php.ini Datei und nimm einige Änderungen vor:

nano /etc/php/7.4/fpm/php.ini

Ändere die folgenden Zeilen:

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = America/Chicago

Speichere und schließe die Datei und starte den PHP-FPM Dienst neu, um die Änderungen zu übernehmen:

systemctl restart php7.4-fpm

Sobald du damit fertig bist, kannst du mit dem nächsten Schritt fortfahren.

Grav CMS installieren

Als nächstes musst du das Grav CMS in das Nginx Web Root Verzeichnis herunterladen. Du kannst es von der Grav Download Seite mit folgendem Befehl herunterladen:

cd /var/www/html
wget https://getgrav.org/download/core/grav-admin/1.7.17

Sobald der Download abgeschlossen ist, entpacke die heruntergeladene Datei mit dem folgenden Befehl:

unzip 1.7.17

Als nächstes benennst du das entpackte Verzeichnis mit dem folgenden Befehl in grav um:

mv grav-admin grav

Setze als Nächstes die richtigen Eigentumsrechte für das grav-Verzeichnis:

chown -R www-data:www-data /var/www/html/grav

Sobald du damit fertig bist, kannst du mit dem nächsten Schritt fortfahren.

Nginx für Grav CMS konfigurieren

Als nächstes musst du eine Nginx-Konfigurationsdatei für den virtuellen Host erstellen, um Grav CMS zu hosten. Du kannst sie mit dem folgenden Befehl erstellen:

nano /etc/nginx/conf.d/grav.conf

Füge die folgenden Zeilen hinzu:

server {

listen 80;

server_name grav.example.com;
root /var/www/html/grav;

index index.html index.php;

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

   location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
   location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
   location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }

location ~ \.php$ {
   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 }

}

Speichere und schließe die Datei, wenn du fertig bist und überprüfe Nginx auf Syntaxfehler:

nginx -t

Du solltest die folgende Ausgabe erhalten:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Starte abschließend den Nginx-Dienst neu, um die Änderungen zu übernehmen:

systemctl restart nginx

Du kannst den Status des Nginx auch mit dem folgenden Befehl überprüfen:

systemctl status nginx

Du solltest die folgende Ausgabe sehen:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-09 06:45:28 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 33099 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 33110 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 33111 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.6M
     CGroup: /system.slice/nginx.service
             ??33111 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??33112 nginx: worker process

Jul 09 06:45:28 node1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 09 06:45:28 node1 systemd[1]: Started A high performance web server and a reverse proxy server.

Wenn alles in Ordnung ist, kannst du mit dem nächsten Schritt fortfahren.

Zugriff auf Grav CMS

Du kannst nun auf die Grav CMS Web UI über die URL http://grav.example.com zugreifen. Du solltest den folgenden Bildschirm sehen:

GRAV CMS

Gib deinen Admin-Benutzernamen und dein Passwort ein und klicke auf den Button Create User. Du wirst nun zum Grav CMS Dashboard weitergeleitet:

Grav CMS Dashboard

Konfigurationsseite

System Konfiguration

Accounts Seite

Benutzer Konten

Plugins Seite

Grav Plugins

Tools Seite

Backup Funktion

Grav CMS mit Let’s Encrypt SSL sichern

Als nächstes musst du das Certbot Client-Paket installieren, um Let’s Encrypt SSL zu installieren und zu verwalten.

Als erstes installierst du Certbot mit dem folgenden Befehl:

apt-get install python3-certbot-nginx -y

Sobald die Installation abgeschlossen ist, führe den folgenden Befehl aus, um das Let’s Encrypt SSL auf deiner Website zu installieren:

certbot --nginx -d grav.example.com

Du wirst aufgefordert, eine gültige E-Mail-Adresse anzugeben und die Nutzungsbedingungen zu akzeptieren, wie unten gezeigt:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): hitjethva@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for grav.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/grav.conf

Als nächstes wählst du aus, ob der HTTP-Verkehr auf HTTPS umgeleitet werden soll oder nicht, wie unten gezeigt:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Gib 2 ein und drücke Enter, um die Installation abzuschließen. Du solltest die folgende Ausgabe sehen:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/grav.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://grav.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=grav.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/grav.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/grav.example.com/privkey.pem
   Your cert will expire on 2021-12-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Du kannst nun sicher auf das Grav CMS zugreifen, indem du das HTTPS-Protokoll verwendest.

Fazit

Herzlichen Glückwunsch! Du hast Grav CMS mit Nginx und Let’s Encrypt SSL erfolgreich auf dem Ubuntu 20.04 Server installiert. Du kannst nun ganz einfach deine Website mit dem Grav CMS erstellen.

Das könnte dich auch interessieren …