Optimizing WordPress on a VPS
Optimizing WordPress on a VPS – Pixzo technical guide
This article describes how to maximize WordPress performance on a Pixzo VPS, intended for administrators who configure the server themselves.
Requirements
- Server: Pixzo VPS with at least 2 GB RAM and 2 CPU cores - WP version: WordPress 6.5 or higher (check with `wp core version`) - PHP: 8.1 or 8.2 (check with `php -v`) - SSH access with root or sudo privileges - Web server: Nginx (recommended) or LiteSpeed - Optional: `wp-cli` (install with `curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar`)
Steps
1. Optimize the web server and PHP stack
Use Nginx for better static file performance than Apache. Enable OPcache for PHP 8.2.
Open `/etc/php/8.2/fpm/php.ini` and modify these lines:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000Restart PHP-FPM:
sudo systemctl restart php8.2-fpm
2. Configure PHP-FPM workers
Adjust the number of workers to your VPS resources. For 2 GB RAM and 2 cores: max 8 workers.
Edit `/etc/php/8.2/fpm/pool.d/www.conf`:
pm = dynamic
pm.max_children = 8
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 4Restart PHP-FPM:
sudo systemctl restart php8.2-fpm
3. Enable HTTP/2 in Nginx
Open `/etc/nginx/nginx.conf` and add to the `http` block:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
}Check configuration and restart:
sudo nginx -t && sudo systemctl restart nginx
4. Install page caching
For Nginx: use WP Rocket (plugin) and configure cache settings.
Install WP Rocket via WP-admin and set in Settings > WP Rocket > Cache: - Enable caching: on - Cache lifespan: 3600 seconds (1 hour)
Or use nginx-helper for a server-side cache:
sudo apt install nginx-common
Add to `/etc/nginx/sites-available/your-site`:
set $cache_uri $request_uri;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
add_header Cache-Control "public, immutable";
}Test and restart:
sudo nginx -t && sudo systemctl reload nginx
5. Configure browser caching
Add the above cache headers to Nginx for static files.
In the same file, under `location ~* \.(jpg|jpeg|png|gif|ico|css|js)$`, also add:
add_header Cache-Control "public, immutable";
Reload Nginx.
6. Optimize images
Use `optipng` and `jpegoptim` for bulk reduction:
sudo apt install optipng jpegoptim
find /var/www/html/wp-content/uploads -name "*.jpg" -exec jpegoptim --strip-all --max=85 {} \;
find /var/www/html/wp-content/uploads -name "*.png" -exec optipng -o7 {} \;Enable WebP support via WP Rocket (settings under Media).
7. Clean up the database
Use WP-Optimize:
wp plugin install wp-optimize --activate
wp db optimizeDelete expired transients and spammers:
wp transient delete --all
wp comment delete $(wp comment list --status=spam --format=ids) --force8. Limit autoloaded options
Check autoload size:
wp option list --autoload=yes --format=total_size
If > 1 MB, find and delete unused options:
wp option list --autoload=yes --format=json | grep -E '"option_name":"(.*)"' | head -20
wp option delete unused_option_nameVerification
Check page speed with a tool:
curl -o /dev/null -s -w "Time total: %{time_total}\n" https://yoursite.nl
Normal load time < 500ms.
Check PHP-opcache status:
php -r "print_r(opcache_get_status());"
See `opcache_enabled` = true.
Frequently asked problems
Problem: Page cache does not work with Nginx and WP Rocket. Solution: Check whether the Nginx-helper plugin is activated and configure the cache location block correctly.
Problem: PHP-FPM crashes after worker config. Solution: Reduce `pm.max_children` to 4 and check RAM: `free -h`.
Problem: Images are not served in WebP. Solution: Install the Imagick PHP extension: `sudo apt install php8.2-imagick` and restart PHP-FPM.
With this configuration, WordPress runs on your Pixzo VPS without unnecessary database queries or unneeded PHP processes. What is your biggest performance bottleneck?