Configure Nginx PHP-FPM on VPS for WordPress

Configure Nginx + PHP-FPM on VPS for Maximum WordPress Speed

If your WordPress site is running on a VPS with Apache + mod_php, this guide will transform your server performance. Switching to Nginx + PHP-FPM is the single highest-impact optimization you can make — getting 3-5x more concurrent requests with the same hardware is entirely realistic.

Table of Contents

  1. What is Nginx + PHP-FPM?
  2. Why It Outperforms Apache + mod_php
  3. System Requirements
  4. Install Nginx and PHP-FPM
  5. Configure PHP-FPM Pool
  6. Nginx Configuration for WordPress
  7. Enable OPcache
  8. Performance Comparison Table
  9. Common Troubleshooting
  10. FAQ
  11. Summary

What is Nginx + PHP-FPM?

Nginx (pronounced "Engine-X") is a web server and reverse proxy designed for handling massive concurrent connections with minimal resources. Unlike Apache's process-per-connection model, Nginx uses an event-driven architecture that serves thousands of connections per CPU core.

PHP-FPM (PHP FastCGI Process Manager) separates PHP execution from the web server, maintaining a pool of PHP worker processes that communicate with Nginx via Unix sockets. This separation enables precise resource management and independent scaling of PHP workers.

Why WordPress specifically benefits from Nginx + PHP-FPM:
WordPress generates many sub-requests per pageview (PHP processing, CSS, JS, images). Nginx serves static files dramatically faster than Apache while PHP-FPM keeps PHP workers pre-forked and ready — the result is lower CPU, lower RAM, and much higher throughput.

Why It Outperforms Apache + mod_php

The difference comes down to architecture:

System Requirements

ComponentMinimumRecommended
OSUbuntu 20.04 LTSUbuntu 22.04 LTS or newer
RAM1 GB2 GB+
CPU1 vCore2 vCore+
Disk20 GB SSD40 GB SSD+
PHPPHP 8.0PHP 8.2 or 8.3
DatabaseMySQL 8.0MariaDB 10.11+

Tip AsiaGB VPS plans include SSD storage and full root access — perfect for this configuration, starting at 500 THB/month.

Install Nginx and PHP-FPM

# Update packages
sudo apt update && sudo apt upgrade -y

# Install Nginx
sudo apt install -y nginx

# Add PHP PPA for latest PHP versions
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

# Install PHP 8.3-FPM with WordPress-required extensions
sudo apt install -y php8.3-fpm php8.3-mysql php8.3-curl \
  php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip \
  php8.3-imagick php8.3-intl php8.3-bcmath
# Verify services are running
sudo systemctl status nginx
sudo systemctl status php8.3-fpm

# Enable on boot
sudo systemctl enable nginx php8.3-fpm
Note: If Apache is currently running, stop it first: sudo systemctl disable --now apache2 — Nginx and Apache both listen on ports 80/443.

Configure PHP-FPM Pool

The PHP-FPM pool config lives at /etc/php/8.3/fpm/pool.d/www.conf. Key values to tune:

[www]
user = www-data
group = www-data

; Unix socket is faster than TCP for local communication
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data

; Dynamic mode adapts to traffic patterns
pm = dynamic

; RAM 1 GB → max_children = 25, RAM 2 GB → max_children = 50
pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500

Calculate safe pm.max_children:

# Check available RAM (MB)
free -m | awk '/Mem:/{print $7}'

# Each PHP-FPM process uses ~30-40 MB
# Example: 800 MB free ÷ 35 = ~22 max_children

Nginx Configuration for WordPress

Create /etc/nginx/sites-available/wordpress:

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

    # WordPress permalink support
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # PHP via FastCGI
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Browser cache for static assets
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|webp|svg|woff2?)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
        try_files $uri =404;
    }

    # Security hardening
    location ~ /\.(ht|git) { deny all; }
    location ~* wp-config\.php { deny all; }
}
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Enable OPcache

Edit /etc/php/8.3/fpm/conf.d/10-opcache.ini:

opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.interned_strings_buffer=16
sudo systemctl restart php8.3-fpm

Performance Comparison Table

Benchmark results on a 1 GB RAM VPS running WordPress with 20 plugins:

StackReq/secondAvg ResponseRAM Used
Apache + mod_php 7.4~45~650 ms~750 MB
Apache + PHP-FPM 8.1~80~400 ms~600 MB
Nginx + PHP-FPM 8.3~180~200 ms~350 MB
Nginx + PHP-FPM 8.3 + OPcache~320~110 ms~280 MB

Common Troubleshooting

502 Bad Gateway

# Check PHP-FPM socket exists
ls -la /run/php/php8.3-fpm.sock

# Check logs
sudo tail -50 /var/log/php8.3-fpm.log
sudo tail -50 /var/log/nginx/wordpress_error.log

Permission Denied on File Writes

sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

Large File Upload Fails

# In /etc/php/8.3/fpm/php.ini
upload_max_filesize = 64M
post_max_size = 64M

# In /etc/nginx/nginx.conf inside http {}
client_max_body_size 64M;

FAQ

What is PHP-FPM and how does it differ from mod_php?

mod_php runs PHP inside each Apache process, loading the full PHP module per request which consumes more RAM. PHP-FPM runs PHP as a separate pool of worker processes communicating via FastCGI, enabling precise resource control and significantly lower RAM usage.

How much faster is Nginx + PHP-FPM compared to Apache + mod_php?

Generally handles 3-5x more concurrent requests with the same RAM. Nginx's event-driven architecture avoids the thread-per-request overhead. Actual response time depends primarily on your PHP code and database queries.

What VPS specs do I need for WordPress with Nginx + PHP-FPM?

For small-to-medium WordPress sites (under 10,000 pageviews/day), 1-2 GB RAM and 1-2 vCores is sufficient. AsiaGB VPS starts at 500 THB/month and supports this configuration out of the box.

How do I calculate pm.max_children for PHP-FPM?

Each PHP-FPM worker uses approximately 30-40 MB RAM. Divide your free RAM in MB by 35 to get a safe value. With 800 MB free: 800 ÷ 35 ≈ 22 max_children.

How much does OPcache improve WordPress performance?

OPcache caches compiled PHP bytecode, eliminating recompilation per request. For WordPress with many plugins, OPcache typically reduces PHP execution time by 50-70% — one of the highest-impact optimizations available.

What Nginx config is required for WordPress specifically?

WordPress requires try_files for pretty permalink support plus a PHP FastCGI location block. Add cache headers for static assets and deny access to wp-config.php and .htaccess files.

Summary

Switching to Nginx + PHP-FPM on your VPS is one of the best performance investments for WordPress. The key steps are:

With AsiaGB VPS featuring SSD storage and 99% Uptime, you have a solid foundation to run production-grade WordPress at scale.

Ready to Supercharge Your WordPress?

AsiaGB VPS with SSD storage — deploy Nginx + PHP-FPM immediately. Starting at 500 THB/month.

View VPS Plans