LESSON 7 โฑ๏ธ 10 min read

Hosting & Server Optimization

Hosting Types

TypeSpeedCostBest For
SharedSlow$5-20/moSmall blogs
VPSGood$20-100/moGrowing sites
Managed WPFast$30-300/moBusiness sites
CloudScalableVariableHigh traffic
DedicatedFastest$200+/moEnterprise

Managed WordPress Hosts

Top performers for WordPress-specific optimization:

HostHighlights
CloudwaysFlexible, affordable
KinstaGoogle Cloud, fast
WP EngineEnterprise features
FlywheelDesigner-friendly
SiteGroundGood support

PHP Optimization

PHP Version

Always use the latest stable PHP version:

// Check current version
echo phpversion();

// PHP 8.2+ is recommended
// 30-50% faster than PHP 7.4

PHP Configuration

; php.ini optimizations

; Memory limit
memory_limit = 256M

; Execution time
max_execution_time = 300

; OPcache settings
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60
opcache.fast_shutdown = 1
opcache.enable_cli = 0

; Realpath cache
realpath_cache_size = 4096K
realpath_cache_ttl = 600

PHP-FPM Tuning

; /etc/php/8.2/fpm/pool.d/www.conf

; Process manager
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

; Calculate max_children:
; (Total RAM - System RAM) / Average PHP Process Size
; Example: (4GB - 1GB) / 60MB = 50

Web Server Configuration

Nginx Optimization

# /etc/nginx/nginx.conf

worker_processes auto;
worker_connections 2048;

# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;

# FastCGI caching
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;

# Brotli (if available)
brotli on;
brotli_types text/plain text/css application/json application/javascript;

Apache Optimization

# .htaccess

# Enable compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json
</IfModule>

# Enable Keep-Alive
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

# ETags
FileETag MTime Size

MySQL/MariaDB Tuning

# /etc/mysql/mysql.conf.d/performance.cnf

[mysqld]
# InnoDB settings
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT

# Query cache (MySQL 5.7, deprecated in 8.0)
query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M

# Connection settings
max_connections = 150
wait_timeout = 300
interactive_timeout = 300

# Buffer sizes
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer_size = 4M

wp-config.php Optimizations

// Memory limit
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

// Reduce revisions
define('WP_POST_REVISIONS', 3);

// Autosave interval (seconds)
define('AUTOSAVE_INTERVAL', 120);

// Empty trash sooner (days)
define('EMPTY_TRASH_DAYS', 7);

// Disable cron if using system cron
define('DISABLE_WP_CRON', true);

// Faster image processing
define('WP_IMAGE_EDIT_OVERWRITE', true);

// External HTTP optimizations
define('WP_HTTP_BLOCK_EXTERNAL', false);

System-Level Cron

# Disable WordPress internal cron (in wp-config.php)
# define('DISABLE_WP_CRON', true);

# Add system cron job
crontab -e

# Run every 5 minutes
*/5 * * * * cd /var/www/html && php wp-cron.php > /dev/null 2>&1

# Or with WP-CLI
*/5 * * * * cd /var/www/html && wp cron event run --due-now > /dev/null 2>&1

Monitoring & Alerts

UptimeRobot / Pingdom

Set up monitoring:

  • HTTP check every 1-5 minutes
  • Alert on response time > 3s
  • Alert on downtime

Server Monitoring

# Install Netdata for real-time monitoring
bash <(curl -Ss https://my-netdata.io/kickstart.sh)

# Or use htop for quick checks
htop

Performance Checklist

ItemStatus
PHP 8.0+โ˜
OPcache enabledโ˜
Page cachingโ˜
Object caching (Redis)โ˜
CDN configuredโ˜
Gzip/Brotli enabledโ˜
HTTP/2 enabledโ˜
Database optimizedโ˜
Images optimizedโ˜
CSS/JS minifiedโ˜

Congratulations!

You've completed the WordPress Performance Optimization tutorial!

What You've Learned

  • โœ… Core Web Vitals and measurement
  • โœ… Multi-level caching strategies
  • โœ… Image optimization techniques
  • โœ… Database maintenance and tuning
  • โœ… CSS/JS optimization
  • โœ… Profiling and debugging
  • โœ… Server-level optimization

Target Performance

MetricTarget
LCP< 2.5s
INP< 200ms
CLS< 0.1
TTFB< 600ms
Lighthouse90+
๐ŸŽฏ Tutorial Complete! You're now equipped to build blazing-fast WordPress sites.
๐ŸŽ‰

Tutorial Complete!

You've finished all lessons in this series.

โ† Back to Tutorial Overview