📑 Table of Contents
🚀 WordPress Site Optimization Process
This comprehensive guide walks you through optimizing your WordPress site by configuring post revisions, memory limits, cron jobs, OpCache, and implementing FastCGI caching. These optimizations will significantly improve your site's performance and resource efficiency.
📝 Step 1: Configure Post Revisions Policy
WordPress stores multiple revisions of your posts by default, which can bloat your database. We'll disable this feature to conserve database space and improve performance.
Navigate to Document Root
cd /var/www/example.com/public_htmlEdit wp-config.php
sudo nano wp-config.phpScroll down to the section that allows custom directives, typically located below the define('WP_AUTO_UPDATE_CORE', 'false'); line.
Add Post Revisions Directive
/** DISABLE POST REVISIONS */
define('WP_POST_REVISIONS', 'false');💾 Step 2: Configure WordPress Memory Limit
Increasing the WordPress memory limit allows your site to handle more complex operations and plugins without running into memory errors.
Add Memory Limit Directive to wp-config.php
/** MEMORY LIMIT */
define('WP_MEMORY_LIMIT', '256M');Update PHP-FPM Pool Configuration
cd /etc/php/8.3/fpm/pool.d/sudo nano example.com.confLocate the php_admin_value[memory_limit] directive (press CTRL+W to search). Uncomment the line and change the value from 32M to 256M:
php_admin_value[memory_limit] = 256Msudo systemctl reload php8.3-fpm⏰ Step 3: Configure WordPress Cron
By default, WordPress cron runs on every page load, which can slow down your site. We'll disable the built-in cron and set up a real server-side cron job for better performance.
Disable Built-in WordPress Cron
Add this directive to wp-config.php (in the same section as previous directives):
/** DISABLE WP-CRON */
define('DISABLE_WP_CRON', true);Save and close the file (CTRL+X, then Y, then Enter).
Create Server-Side Cron Job
crontab -eAdd the following line to run WordPress cron every 15 minutes:
*/15 * * * * wget -q -O - https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
WordPress Cron Workflow
(Disabled)
Every 15 minutes
Executed reliably
⚡ Step 4: Configure OpCache
OpCache stores precompiled PHP scripts in memory, dramatically improving PHP execution speed. We'll configure OpCache with optimal settings for WordPress.
Edit PHP Pool Configuration
sudo nano /etc/php/8.3/fpm/pool.d/example.com.confScroll to the end of the file (CTRL+END) and add the following directives:
Development Server Configuration (Recommended for Testing)
; OPCACHE CONFIGURATION - DEVELOPMENT SERVER - Jul 2025
; Directive php_admin_flag[opcache.enabled] leave commented - enabled by default
; php_admin_flag[opcache.enabled] = 1
php_admin_value[opcache.memory_consumption] = 256
php_admin_value[opcache.interned_strings_buffer] = 32
php_admin_value[opcache.max_accelerated_files] = 20000
php_admin_flag[opcache.validate_timestamps] = 1
php_admin_value[opcache.revalidate_freq] = 2
php_admin_flag[opcache.validate_permission] = 1Production Server Configuration (For Live Sites)
; OPCACHE CONFIGURATION - PRODUCTION SERVER - Jul 2025
; Directive php_admin_flag[opcache.enabled] leave commented - enabled by default
;php_admin_flag[opcache.enabled] = 1
;php_admin_value[opcache.memory_consumption] = 256
;php_admin_value[opcache.interned_strings_buffer] = 32
;php_admin_value[opcache.max_accelerated_files] = 20000
;php_admin_flag[opcache.validate_timestamps] = 0
;php_admin_flag[opcache.validate_permission] = 1Reload PHP-FPM
sudo systemctl reload php8.3-fpm| OpCache Directive | Value | Purpose |
|---|---|---|
| opcache.memory_consumption | 256 MB | Memory allocated for OpCache |
| opcache.interned_strings_buffer | 32 MB | Memory for storing interned strings |
| opcache.max_accelerated_files | 20000 | Maximum number of cached files |
| opcache.validate_timestamps | 1 (Dev) / 0 (Prod) | Check for file changes |
| opcache.revalidate_freq | 2 seconds | File check frequency (Dev only) |
🚄 Step 5: Configure FastCGI Caching
FastCGI caching stores rendered HTML pages in memory, serving them instantly without executing PHP or querying the database. This is one of the most effective performance optimizations available.
Configure Nginx Main Configuration
cd /etc/nginxsudo nano nginx.confScroll down to the FastCGI caching section and add a new cache path for your site:
### FASTCGI CACHING
# fastcgi_cache_path directive - PATH & NAME must be unique for each site
fastcgi_cache_path /var/run/SITENAME levels=1:2 keys_zone=SITENAME:100m inactive=60m;
fastcgi_cache_path /var/run/SITE2NAME levels=1:2 keys_zone=SITE2NAME:100m inactive=60m;
# Applied to all sites
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;Create Cache Excludes File
cd /etc/nginx/includes/If the fastcgi_cache_excludes.conf file doesn't exist, create it with appropriate exclusion rules for WordPress admin areas, logged-in users, and dynamic content.
Configure Site-Specific Server Block
sudo nano /etc/nginx/sites-available/example.com.confAdd FastCGI Caching to PHP Location Block
Locate the PHP processing location block and add the following directives:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_HOST $host;
fastcgi_pass unix:/run/php/php8.3-fpm-example.com.sock;
include /etc/nginx/includes/fastcgi_optimize.conf;
# FastCGI caching directives
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache SITENAME;
fastcgi_cache_valid 60m;
}Add Cache Excludes and Headers
Above the PHP location block, add:
include /etc/nginx/includes/fastcgi_cache_excludes.conf;
add_header X-FastCGI-Cache $upstream_cache_status;Add Cache Purge Location
Add this location block to allow manual cache purging:
location ~ /purge(/.*) {
fastcgi_cache_purge SITENAME "$scheme$request_method$host$1";
}Test and Reload Nginx
sudo nginx -tsudo systemctl reload nginxVerify FastCGI Caching
Test if caching is working properly:
curl -I https://example.comOn first request, you should see X-FastCGI-Cache: MISS
curl -I https://example.comOn subsequent requests, you should see X-FastCGI-Cache: HIT
FastCGI Cache Flow
First visit
Generate HTML
Save to memory
Serve from cache
☁️ Step 6: Cloudflare Integration
Cloudflare provides CDN, DDoS protection, and additional caching layers. Proper configuration ensures secure communication between Cloudflare and your server.
Server-Side Configuration
Verify Cloudflare IP List File
readlink -f /etc/nginx/includes/cloudflare_ip_list.confCopy the full path displayed by this command.
Update Nginx Server Block
cd /etc/nginx/sites-available/sudo nano example.com.confAdd the include directive for Cloudflare IPs (underneath security includes):
include /etc/nginx/includes/cloudflare_ip_list.conf;Test and Reload
sudo nginx -tsudo systemctl reload nginxCloudflare Dashboard Configuration
Step 1: Enable Proxy
- Log in to your Cloudflare dashboard
- Select your domain
- Navigate to DNS section
- Change proxy status from DNS only to Proxied for your A and AAAA records
Step 2: Configure SSL/TLS Settings
- Navigate to SSL/TLS section
- Set encryption mode to Full (strict)
Cloudflare Traffic Flow
Makes request
SSL encryption
(CF certificates)
SSL encryption
(Let's Encrypt)
Encrypted & cached
Step 3: Additional Cloudflare Settings
Configure the following settings in your Cloudflare dashboard:
- Cache Level: Standard or Aggressive
- Browser Cache TTL: Respect Existing Headers
- Always Use HTTPS: Enabled
- Automatic HTTPS Rewrites: Enabled
- Minimum TLS Version: TLS 1.2 or higher
- TLS 1.3: Enabled
- HTTP/3 (with QUIC): Enabled
- Brotli Compression: Enabled
Verify Configuration
Test Redirects
curl -I http://example.comcurl -I http://www.example.comcurl -I https://www.example.comcurl -I https://example.comAll requests should properly redirect to HTTPS with your preferred domain (with or without www).
Test SSL Configuration
Visit these testing tools to verify your SSL setup:
- SSL Labs: https://ssllabs.com/ (should achieve A+ rating)
- HTTP/3 Check: https://http3check.net/
Verify HTTP/3 in Browser
- Open your browser's Developer Tools (F12)
- Navigate to the Network tab
- Refresh your page
- Right-click on column headers and ensure Protocol is checked
- Look for h3 in the Protocol column (indicates HTTP/3)
📊 Performance Optimization Summary
| Optimization | Configuration | Expected Impact |
|---|---|---|
| Post Revisions | Disabled | Reduced database size |
| Memory Limit | 256MB | Better plugin/theme performance |
| WordPress Cron | Server-side (15 min) | Faster page loads |
| OpCache | 256MB / 20K files | 3-5x PHP execution speed |
| FastCGI Cache | 100MB / 60 min | 10-100x page load speed |
| Cloudflare | Proxied + Full (strict) | Global CDN, DDoS protection |
🔧 Additional Optimization Steps
- Web Application Firewall (WAF) plugin configuration
- Disabling WP REST API for non-logged-in users
- Additional Cloudflare dashboard settings
- Image optimization using plugins
- Database optimization
- CSS and JavaScript minification/concatenation
- Disallow file modifications (DISALLOW_FILE_MODS)
🎯 Best Practices & Tips
Permission Management Scripts
Use the provided bash scripts for quick permission changes:
Loosen Permissions (for updates)
cd ~/wp_bash_scripts/
bash 5.loosen_permissions.shTighten Permissions (after updates)
cd ~/wp_bash_scripts/
bash 6.tighten_permissions.shMonitoring & Maintenance
Check OpCache File Count
bash ~/wp_bash_scripts/opcache_files.shMonitor PHP-FPM Pool Usage
bash ~/wp_bash_scripts/pool_list_usage.shClear FastCGI Cache
To manually clear the cache for a specific page:
curl -X PURGE https://example.com/page-url/Security Considerations
- Always use hardened permissions when not actively updating
- Regularly update WordPress core, themes, and plugins
- Monitor server logs for suspicious activity
- Keep SSL certificates up to date (Let's Encrypt auto-renews)
- Review Cloudflare security settings periodically
- Implement database privilege restrictions as documented
Performance Monitoring
- Use browser DevTools to verify HTTP/3 usage
- Check X-FastCGI-Cache headers regularly
- Monitor OpCache memory usage and hit rates
- Review Nginx access logs for cache performance
- Test site speed using tools like GTmetrix or PageSpeed Insights
🎉 Conclusion
You have successfully completed the comprehensive WordPress site optimization process. Your site now benefits from:
- ✅ Optimized WordPress configuration (post revisions, memory, cron)
- ✅ PHP OpCache for accelerated script execution
- ✅ FastCGI caching for lightning-fast page loads
- ✅ Cloudflare integration for global CDN and DDoS protection
- ✅ Secure SSL/TLS configuration with HTTP/3 support
- ✅ Hardened file permissions and security settings
These optimizations work together to create a high-performance, secure WordPress hosting environment. Regular monitoring and maintenance will ensure your site continues to perform optimally.