Grav CMS te installeren met Nginx op Ubuntu 20.04

Grav is een gratis, open-source en flat-file CMS dat geen database nodig heeft. Het is gebaseerd op PHP en biedt verschillende mogelijkheden die andere CMS’en als WordPress, Joomla, enz. niet hebben. Het is eenvoudig, gemakkelijk te gebruiken, en wordt geleverd met enkele van de belangrijkste technologieën, waaronder Twig Templating, Markdown, YAML, Parsedown, Doctrine Cache, Gregwar Image Library, en Symfony Console.

In deze handleiding laat ik je zien hoe je Grav CMS installeert met Nginx en Let’s Encrypt SSL op Ubuntu 20.04 server.

Voorwaarden

  • Een server waarop Ubuntu 20.04 draait.
  • Een geldige domeinnaam gekoppeld aan het IP van je server.
  • Een root wachtwoord is geconfigureerd op de server.

Aan de slag

Werk eerst de systeempakketten bij naar de bijgewerkte versie door het volgende commando uit te voeren:

apt-get update -y

Als alle pakketten zijn bijgewerkt, kun je doorgaan met de volgende stap.

Installeer Nginx en PHP

Eerst moet je de Nginx webserver, PHP en andere PHP extensies op je systeem installeren. Je kunt ze allemaal installeren met het volgende commando:

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

Zodra alle pakketten zijn geïnstalleerd, controleer je de PHP-versie met het volgende commando:

php --version

Je zou de volgende uitvoer moeten krijgen:

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

Bewerk vervolgens het php.ini bestand en breng enkele wijzigingen aan:

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

Wijzig de volgende regels:

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

Sla het bestand op en sluit het en herstart dan de PHP-FPM service om de wijzigingen toe te passen:

systemctl restart php7.4-fpm

Als je klaar bent, kun je doorgaan naar de volgende stap.

Grav CMS installeren

Vervolgens moet je het Grav CMS downloaden naar de Nginx web root directory. Je kunt het downloaden van de Grav downloadpagina met het volgende commando:

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

Zodra de download is voltooid, pak je het gedownloade bestand uit met het volgende commando:

unzip 1.7.17

Hernoem vervolgens de uitgepakte map naar grav met het volgende commando:

mv grav-admin grav

Stel vervolgens het juiste eigendom in op de grav map:

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

Als je klaar bent, kun je doorgaan met de volgende stap.

Nginx configureren voor Grav CMS

Vervolgens moet je een Nginx virtueel host configuratiebestand maken om Grav CMS te hosten. Je kunt het aanmaken met het volgende commando:

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

Voeg de volgende regels toe:

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;
 }

}

Sla het bestand op en sluit het als je klaar bent en controleer dan de Nginx op eventuele syntaxfouten:

nginx -t

Je zou de volgende uitvoer moeten krijgen:

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

Start tot slot de Nginx-service opnieuw op om de wijzigingen toe te passen:

systemctl restart nginx

Je kunt de status van de Nginx ook controleren met het volgende commando:

systemctl status nginx

Je zou de volgende uitvoer moeten zien:

? 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.

Als alles in orde is, kun je doorgaan met de volgende stap.

Toegang tot Grav CMS

Je hebt nu toegang tot de Grav CMS web UI met behulp van de URL http://grav.example.com. Je zou het volgende scherm moeten zien:

GRAV CMS

Stel je admin gebruikersnaam, wachtwoord in en klik op de knop Gebruiker aanmaken. Je wordt doorgestuurd naar het Grav CMS dashboard:

Grav CMS dashboard

Configuratie Pagina

Systeemconfiguratie

Accounts Pagina

Gebruikersaccounts

Plugins Pagina

Grav Plugins

Pagina Hulpmiddelen

Back-up functie

Grav CMS beveiligen met Let’s Encrypt SSL

Vervolgens moet je het Certbot-clientpakket installeren om de Let’s Encrypt SSL te installeren en te beheren.

Installeer eerst de Certbot met het volgende commando:

apt-get install python3-certbot-nginx -y

Zodra de installatie klaar is, voer je het volgende commando uit om de Let’s Encrypt SSL op je website te installeren:

certbot --nginx -d grav.example.com

Je wordt gevraagd een geldig e-mailadres op te geven en de servicevoorwaarden te accepteren zoals hieronder weergegeven:

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): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Kies vervolgens of je HTTP-verkeer wel of niet wilt omleiden naar HTTPS, zoals hieronder te zien is:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Typ 2 en druk op Enter om de installatie te voltooien. Je zou de volgende uitvoer moeten zien:

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.

Je hebt nu veilig toegang tot het Grav CMS via het HTTPS-protocol.

Conclusie

Gefeliciteerd! Je hebt Grav CMS met succes geïnstalleerd met Nginx en Let’s Encrypt SSL op Ubuntu 20.04 server. Je kunt nu gemakkelijk je website maken met het Grav CMS.