wordpress optimaliseren op een vps
Wordpress Optimaliseren Op Een Vps
WordPress optimaliseren op een VPS
Dit artikel beschrijft hoe je WordPress op een VPS optimaliseert voor maximale snelheid, bedoeld voor developers en systeembeheerders.
Vereisten
Een VPS met root-toegang, Ubuntu 22.04 of Debian 12, WordPress 6.7, Nginx, PHP 8.2 met PHP-FPM, een SSL-certificaat.
Stappen
1. Configureer OPcache
Open `/etc/php/8.2/cli/conf.d/10-opcache.ini` en voeg toe: ```bash opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=10000 ``` Herstart PHP-FPM: ```bash sudo systemctl restart php8.2-fpm ```
2. Stel PHP-FPM max_children in
Open `/etc/php/8.2/fpm/pool.d/www.conf`. Bereken: (RAM in MB - 512) / 80. Stel `pm.max_children` in op de uitkomst. Herstart PHP-FPM.
3. Schakel HTTP/2 in op Nginx
Voeg in het serverblok van je site (bijv. `/etc/nginx/sites-available/example.com`) toe: ```nginx listen 443 ssl http2; listen [::]:443 ssl http2; ``` Test de configuratie en herlaad Nginx: ```bash sudo nginx -t && sudo systemctl reload nginx ```
4. Activeer FastCGI Cache
Voeg bovenaan je Nginx-configuratie toe: ```nginx fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m; ``` In het serverblok: ```nginx set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } location ~ \.php$ { fastcgi_cache WORDPRESS; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_valid 200 60m; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; } ``` Maak de cachemap aan en herstart Nginx.
5. Configureer browsercache
Voeg in het serverblok toe: ```nginx location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ { expires 365d; add_header Cache-Control "public, immutable"; } ``` Herlaad Nginx.
6. Schakel GZIP-compressie in
Voeg in `/etc/nginx/nginx.conf` toe: ```nginx gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; gzip_vary on; gzip_proxied any; gzip_comp_level 6; ``` Herstart Nginx.
7. Converteer afbeeldingen naar WebP
Installeer de plugin WebP Express via WordPress-admin. Of gebruik CLI met cwebp: ```bash sudo apt install webp cwebp -q 80 input.jpg -o input.webp ```
8. Activeer lazy loading
WordPress 5.5+ heeft native lazy loading. Voeg toe aan `wp-config.php`: ```php define('WP_CACHE', true); add_theme_support('post-thumbnails'); ```
Verificatie
Test de optimalisaties met: ```bash curl -I https://jouwsite.nl | grep -E "HTTP/|cf-cache-status|X-Cache" ``` Gebruik GTmetrix of WebPageTest voor een volledige performance-analyse.
Veelgestelde problemen
1. PHP 8.2 is niet beschikbaar Voeg het Ondrej PPA toe: `sudo add-apt-repository ppa:ondrej/php && sudo apt update`
2. FastCGI cache werkt niet Controleer de cachemap: `sudo ls -la /etc/nginx/cache` en zorg dat Nginx eigenaar is: `sudo chown -R www-data:www-data /etc/nginx/cache`
3. GZIP wordt niet verzonden Controleer Accept-Encoding header: `curl -H "Accept-Encoding: gzip" -I https://jouwsite.nl | grep Content-Encoding`
Cloudflare APO vereist een actief Pro-abonnement. Overweeg of de investering opweegt tegen de winst.