How to Optimize WordPress Performance on an Ubuntu VPS
A fast WordPress website provides a better experience for visitors, reduces unnecessary server resource consumption, and can improve important website performance metrics.
However, installing WordPress on a VPS does not automatically guarantee optimal performance.
WordPress performance depends on several components working together, including the web server, PHP runtime, database, caching configuration, website content, and available server resources.
In this tutorial, you will learn how to optimize WordPress performance on an Ubuntu VPS using Nginx, PHP-FPM, PHP OPcache, Redis or Memcached object caching, MariaDB optimization, image compression, and performance monitoring.
We will also explain how to measure improvements using Core Web Vitals and how to apply configuration changes safely on production websites.
This guide is designed for WordPress installations running on Ubuntu 24.04 LTS, Ubuntu 26.04 LTS, and other supported Ubuntu releases.
Prerequisites
- An Ubuntu VPS with root or sudo access.
- A working WordPress installation.
- Nginx or another supported web server.
- PHP-FPM configured for the WordPress website.
- MariaDB or MySQL.
- SSH access to the server.
- A recent, verified backup of the WordPress files and database.
This tutorial assumes a typical Nginx, PHP-FPM, and MariaDB installation.
Commands and configuration paths may differ depending on your Linux distribution, PHP version, and hosting control panel.
If you have not installed WordPress yet, see our WordPress installation guide for Ubuntu VPS servers.
1. Understand What Makes WordPress Slow
WordPress performance problems can originate from several different components.
Common causes include:
- Insufficient VPS CPU or RAM.
- Too many PHP-FPM workers consuming memory.
- Slow database queries.
- Missing object caching.
- Missing or incorrectly configured page caching.
- Large images and unoptimized media files.
- Excessive WordPress plugins.
- Slow external API requests.
- Unoptimized themes and JavaScript.
- High disk I/O latency.
- Background tasks and excessive WordPress cron activity.
Before changing server settings, identify which components are responsible for the slowdown.
Important: Increasing VPS resources does not automatically resolve inefficient PHP code, database queries, or poorly configured caching.
2. Measure WordPress Performance Before Making Changes
Establish a performance baseline before optimizing your server.
Useful measurements include:
- Time to First Byte (TTFB).
- Largest Contentful Paint (LCP).
- Interaction to Next Paint (INP).
- Cumulative Layout Shift (CLS).
- Total page weight.
- Number of HTTP requests.
- PHP response time.
- Database query execution time.
- CPU and RAM utilization.
Useful testing tools include:
- Google PageSpeed Insights.
- Chrome Lighthouse.
- Chrome DevTools.
- WebPageTest.
- Linux monitoring utilities.
You can also inspect HTTP response headers using:
curl -I https://example.com/
Replace example.com with your WordPress domain.
For a basic response timing test:
curl -o /dev/null -s \
-w 'DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' \
https://example.com/
Run several tests under comparable conditions before and after optimization.
Note: Command-line response timing is useful for troubleshooting but does not replace browser-based Core Web Vitals measurements.
3. Check VPS CPU, RAM, and Disk Resources
Before modifying PHP or database settings, inspect the available server resources.
Check memory:
free -h
Check CPU and running processes:
top
Check disk usage:
df -hT
Check block devices:
lsblk
Check system load:
uptime
For additional monitoring, install:
sudo apt install -y htop sysstat
Then use:
htop
And:
iostat -xz 1
Pay attention to sustained CPU saturation, memory pressure, swap activity, and disk latency.
For additional monitoring techniques, see our Linux VPS resource monitoring tutorial.
4. Keep Ubuntu, PHP, and WordPress Updated
Running supported software versions is important for security, compatibility, and performance.
Update the Ubuntu package index:
sudo apt update
Review available upgrades:
apt list --upgradable
Apply approved operating system updates during a maintenance window.
Check the installed PHP version:
php -v
Check Nginx:
nginx -v
Check MariaDB:
mariadb --version
WordPress core, themes, and plugins should also be kept updated.
Important: Test major PHP, WordPress, and database upgrades in a staging environment before deploying them to production.
5. Optimize PHP-FPM for WordPress
PHP-FPM manages PHP worker processes responsible for executing WordPress requests.
Incorrect PHP-FPM settings can cause excessive memory consumption, slow requests, or unnecessary process creation.
Identify the active PHP-FPM service:
systemctl list-units --type=service | grep php
PHP-FPM pool configurations are commonly located under:
/etc/php/VERSION/fpm/pool.d/
For example:
/etc/php/8.3/fpm/pool.d/www.conf
Replace the example PHP version with the version installed on your VPS.
Before editing a pool configuration, create a timestamped backup:
sudo cp -a /etc/php/8.3/fpm/pool.d/www.conf \
"/etc/php/8.3/fpm/pool.d/www.conf.bak.$(date +%Y%m%d-%H%M%S)"
Open the configuration:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
Important PHP-FPM settings include:
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 500
Important: These are illustrative values, not universal recommendations.
The correct configuration depends on available RAM, the number of websites, PHP worker memory consumption, and expected request concurrency.
6. Calculate an Appropriate PHP-FPM Worker Limit
Each PHP-FPM worker consumes memory.
A basic sizing estimate is:
Maximum PHP Workers =
Memory Available for PHP / Average PHP Worker Memory
For example, suppose a VPS has 4 GB of RAM and approximately 1 GB is available for PHP workers after accounting for the operating system, database, web server, and other services.
If each PHP worker consumes approximately 100 MB:
1024 MB / 100 MB = approximately 10 workers
In this example, a pm.max_children value near 10 may be a reasonable initial estimate.
Actual PHP worker memory consumption should be measured under representative application workloads.
Do not allocate all available VPS memory to PHP-FPM.
After modifying PHP-FPM configuration, validate it using the matching PHP-FPM binary.
For example:
sudo php-fpm8.3 -t
If validation succeeds, restart the corresponding service during a maintenance window:
sudo systemctl restart php8.3-fpm
Verify:
sudo systemctl status php8.3-fpm --no-pager
7. Enable PHP OPcache
PHP OPcache improves PHP performance by storing compiled PHP bytecode in shared memory.
This reduces the need to repeatedly parse and compile PHP scripts.
Install OPcache if necessary:
sudo apt install -y php-opcache
Check whether OPcache is available:
php -m | grep -i opcache
OPcache settings are commonly configured in a PHP INI file under:
/etc/php/VERSION/fpm/conf.d/
Locate the active configuration:
php --ini
Note: PHP CLI and PHP-FPM may load different configuration files. Inspect the FPM configuration rather than assuming the CLI settings apply to the website.
Common OPcache settings include:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
These values are examples and should be adjusted according to application size and available memory.
Keeping timestamp validation enabled is generally appropriate for environments where WordPress files are updated through normal application workflows.
Disabling timestamp validation requires a reliable OPcache invalidation or PHP-FPM restart process whenever application code changes.
After updating the relevant configuration, validate and restart PHP-FPM as appropriate.
8. Configure Persistent Object Caching
WordPress repeatedly retrieves information from its database.
Persistent object caching can reduce repeated database operations by storing reusable objects between requests.
Two commonly used technologies are:
- Redis.
- Memcached.
Both can provide effective object caching when supported by the WordPress installation and its caching integration.
However, they should not be enabled simultaneously through competing object cache drop-ins.
WordPress normally uses a single persistent object cache integration.
9. Install Redis for WordPress Object Caching
Redis is a popular choice for WordPress object caching.
Install Redis and the PHP Redis extension:
sudo apt install -y redis-server php-redis
Enable Redis:
sudo systemctl enable --now redis-server
Verify connectivity:
redis-cli ping
Expected response:
PONG
Redis should be configured to accept connections only from trusted applications.
For a single-server WordPress installation, localhost is generally appropriate.
Install a maintained WordPress Redis object caching integration and follow its configuration instructions.
Important: Installing Redis and the PHP extension does not automatically activate persistent object caching in WordPress.
For complete Redis installation and security instructions, see our Redis installation tutorial.
10. Use Memcached as an Alternative
Memcached is another high-performance memory caching system.
It is suitable for applications that require simple temporary key-value caching.
Install Memcached:
sudo apt install -y memcached php-memcached
Enable the service:
sudo systemctl enable --now memcached
Verify that Memcached listens on localhost:
sudo ss -tlnp | grep 11211
For local WordPress installations, Memcached should generally bind to:
127.0.0.1:11211
Install a compatible WordPress object caching integration to activate persistent object caching.
Important: Never expose Memcached directly to the public internet.
For detailed instructions, see our Memcached installation and configuration tutorial.
11. Understand Page Caching vs. Object Caching
Page caching and object caching serve different purposes.
Object caching stores reusable application data, reducing repeated database queries and computations.
Page caching stores generated HTTP responses so that eligible requests can be served without executing the complete WordPress application.
For anonymous visitors, page caching can significantly reduce PHP and database workload.
However, page caching must be configured carefully for websites containing personalized or authenticated content.
12. Configure Nginx FastCGI Cache
Nginx FastCGI Cache can cache eligible PHP-generated responses.
This can reduce repeated WordPress processing for anonymous visitors.
Important: FastCGI caching requires careful integration with your existing Nginx virtual host configuration.
Do not copy caching directives into production without reviewing the current server configuration, WordPress routing rules, and application requirements.
Before modifying Nginx, create a timestamped backup of the relevant configuration file.
For example:
sudo cp -a /etc/nginx/sites-available/example.com \
"/etc/nginx/sites-available/example.com.bak.$(date +%Y%m%d-%H%M%S)"
Replace the example filename with your actual virtual host configuration.
Define a cache storage location in the Nginx HTTP configuration context:
fastcgi_cache_path /var/cache/nginx/wordpress
levels=1:2
keys_zone=WORDPRESS:100m
inactive=60m
max_size=1g
use_temp_path=off;
The cache directory must be writable by the appropriate Nginx worker processes.
For example, on a standard Ubuntu installation using the www-data account:
sudo mkdir -p /var/cache/nginx/wordpress
sudo chown -R www-data:www-data /var/cache/nginx/wordpress
Next, configure cache eligibility and bypass rules appropriate for your website.
A simplified example of request-based bypass logic is:
set $skip_cache 0;
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
if ($request_uri ~* "/wp-admin/|/wp-login.php|/cart/|/checkout/|/my-account/") {
set $skip_cache 1;
}
if ($http_cookie ~* "wordpress_logged_in_|wp-postpass_|woocommerce_items_in_cart|wp_woocommerce_session_") {
set $skip_cache 1;
}
These conditions illustrate common bypass requirements. They are not a complete production caching policy.
For example, WooCommerce installations may use customized checkout paths, additional session cookies, or application-specific endpoints.
A FastCGI cache configuration must also define the appropriate cache key, cache validity periods, cache bypass conditions, and response caching restrictions.
Security warning: Never cache authenticated or customer-specific responses in a shared public cache.
Before enabling FastCGI caching, test anonymous browsing, login/logout behavior, shopping carts, checkout, and account pages.
Validate Nginx configuration:
sudo nginx -t
Only reload Nginx if validation succeeds:
sudo systemctl reload nginx
Note: This section provides the architecture and essential safety considerations. FastCGI Cache must be integrated with the actual Nginx PHP location block and should not be enabled using incomplete example directives.
13. Configure Safe Caching for WooCommerce
WooCommerce requires additional caching considerations because some pages contain customer-specific information.
Typical pages that should bypass shared full-page caching include:
- Shopping cart.
- Checkout.
- Customer account pages.
- Authenticated customer sessions.
- Pages containing personalized or session-dependent content.
WooCommerce may also require exclusions for session cookies, AJAX requests, and custom endpoints.
Do not rely exclusively on URL-based exclusions.
Test the complete purchasing workflow after modifying caching.
Important: Object caching can still be useful for WooCommerce, provided the integration correctly handles customer-specific data and cache invalidation.
14. Optimize MariaDB for WordPress
WordPress stores posts, settings, users, comments, and other application data in MariaDB or MySQL.
Slow database queries can significantly increase page generation time.
Check the database version:
mariadb --version
Inspect database service status:
sudo systemctl status mariadb --no-pager
Review available memory:
free -h
Important MariaDB settings include:
innodb_buffer_pool_size.max_connections.innodb_log_file_sizeor version-specific redo log capacity settings.- Temporary table limits.
- Slow query logging.
For InnoDB-based WordPress installations, the buffer pool is particularly important.
However, allocating excessive memory to MariaDB can cause memory pressure on a VPS also running Nginx, PHP-FPM, and caching services.
Do not blindly allocate a fixed percentage of total VPS RAM to the database.
Instead, evaluate the complete server workload.
15. Enable MariaDB Slow Query Logging
Slow query logging helps identify database queries that take longer than expected.
Check the current configuration:
sudo mariadb -e "SHOW VARIABLES LIKE 'slow_query_log';"
Check the slow query threshold:
sudo mariadb -e "SHOW VARIABLES LIKE 'long_query_time';"
For temporary diagnostics, you can enable slow query logging dynamically:
sudo mariadb -e "SET GLOBAL slow_query_log = ON;"
Set a threshold:
sudo mariadb -e "SET GLOBAL long_query_time = 1;"
Verify the log location:
sudo mariadb -e "SHOW VARIABLES LIKE 'slow_query_log_file';"
Important: Dynamic settings may not persist after a database restart.
Slow query logs can grow significantly on busy websites. Monitor log size and disable or adjust logging when the diagnostic period is complete.
Analyze recurring slow queries before changing database configuration.
16. Optimize WordPress Database Tables
WordPress databases can accumulate temporary and obsolete information over time.
Examples include:
- Old post revisions.
- Expired transients.
- Spam comments.
- Orphaned metadata.
- Unused plugin tables.
Use a maintained WordPress database optimization tool or WP-CLI commands appropriate for your installation.
Always back up the database before deleting or optimizing application data.
Important: Do not delete database tables or metadata merely because they appear unused. Plugins and themes may depend on them.
17. Optimize WordPress Images
Large images are a common cause of slow WordPress pages.
Image optimization can reduce transferred data and improve loading performance.
Recommended practices include:
- Resize images to appropriate display dimensions.
- Use modern image formats such as WebP or AVIF where supported.
- Compress images without unnecessary quality loss.
- Use responsive images.
- Lazy-load suitable below-the-fold images.
- Avoid lazy-loading the primary above-the-fold image when it delays LCP.
- Specify image dimensions to reduce layout shifts.
WordPress supports responsive image markup and can generate multiple image sizes.
However, themes and plugins must use these capabilities correctly.
Test image changes on desktop and mobile devices.
18. Optimize CSS and JavaScript
WordPress themes and plugins may load JavaScript and CSS that are not necessary for every page.
Excessive scripts can increase page weight, delay rendering, and negatively affect interaction responsiveness.
Recommended improvements include:
- Remove unnecessary plugins and scripts.
- Minify CSS and JavaScript where appropriate.
- Defer noncritical JavaScript when compatible.
- Avoid unnecessary third-party tracking scripts.
- Reduce render-blocking resources.
- Use efficient themes and page builders.
- Load assets only where required.
Important: Combining, deferring, or delaying JavaScript can break menus, checkout forms, payment integrations, and other interactive components.
Test all critical website functionality after making frontend optimization changes.
19. Enable Compression in Nginx
HTTP response compression can reduce the amount of data transferred to visitors.
Nginx commonly supports gzip compression.
Check the existing configuration before making changes:
sudo nginx -T | grep -i gzip
Example gzip settings include:
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_comp_level 5;
gzip_types
text/plain
text/css
application/javascript
application/json
application/xml
image/svg+xml;
These directives belong in an appropriate Nginx configuration context.
Do not add duplicate or conflicting compression settings.
After modifying the configuration:
sudo nginx -t
If validation succeeds:
sudo systemctl reload nginx
Verify compression using an HTTP request with an appropriate Accept-Encoding header.
Modern browsers may also benefit from Brotli compression when supported by the server or CDN.
20. Use a CDN for Static Content
A content delivery network can serve cached static assets from locations closer to visitors.
Common CDN-cacheable resources include:
- Images.
- Stylesheets.
- JavaScript files.
- Fonts.
- Other public static assets.
A CDN can reduce bandwidth usage at the origin and improve delivery times for geographically distributed visitors.
However, CDN caching rules must respect authenticated sessions and personalized application content.
Important: Do not enable aggressive full-page CDN caching for WooCommerce or authenticated WordPress pages without appropriate bypass rules.
21. Optimize WordPress Cron Jobs
WordPress includes WP-Cron, which schedules background tasks such as updates, scheduled publishing, and plugin maintenance operations.
By default, WP-Cron can be triggered by website traffic.
On busy websites, using a system cron job may provide more predictable scheduling.
Before changing the configuration, back up wp-config.php.
Add the following constant before the WordPress configuration stop marker:
define('DISABLE_WP_CRON', true);
Then configure a system cron job to execute WordPress scheduled tasks.
For example, using WP-CLI:
*/5 * * * * cd /var/www/example.com && /usr/local/bin/wp cron event run --due-now --quiet
Replace the example WordPress directory and WP-CLI path with the correct values.
Run the command as the appropriate website account, not unnecessarily as root.
Important: Do not disable WP-Cron unless a functioning replacement scheduler has been configured and tested.
22. Reduce Unnecessary WordPress Plugins
Plugins can introduce additional PHP processing, database queries, scheduled tasks, and frontend assets.
However, the number of installed plugins alone is not a reliable performance metric.
A small number of inefficient plugins can cause more performance problems than a larger number of well-optimized plugins.
Review plugins based on:
- Database query activity.
- PHP execution time.
- Memory consumption.
- Frontend asset loading.
- Background tasks.
- Compatibility and maintenance status.
Remove plugins that are unnecessary or no longer maintained.
Test replacements in staging before modifying production functionality.
23. Monitor WordPress Performance After Optimization
Performance optimization should be treated as an ongoing process.
Monitor:
- CPU utilization.
- RAM and swap usage.
- Disk I/O latency.
- PHP-FPM worker utilization.
- Database query performance.
- Redis or Memcached cache effectiveness.
- Web server response times.
- Application errors.
- Core Web Vitals.
For real-time Linux monitoring, see our Netdata installation tutorial.
For a more advanced monitoring stack, see our Prometheus and Grafana tutorial.
24. Understand WordPress Core Web Vitals
Core Web Vitals measure important aspects of real-world website experience.
The three primary metrics are:
| Metric | What It Measures | Good Threshold |
|---|---|---|
| Largest Contentful Paint (LCP) | Loading performance | 2.5 seconds or less |
| Interaction to Next Paint (INP) | Interaction responsiveness | 200 milliseconds or less |
| Cumulative Layout Shift (CLS) | Visual stability | 0.1 or less |
These thresholds are evaluated using real-user experience data, commonly at the 75th percentile.
Improving server response time can contribute to better loading performance, but Core Web Vitals also depend on frontend code, images, layout stability, and browser execution.
Use both laboratory testing and real-user measurements when evaluating improvements.
25. Troubleshooting Common WordPress Performance Problems
High PHP-FPM Memory Usage
Check:
ps aux | grep '[p]hp-fpm'
free -h
Review PHP-FPM worker limits and actual process memory consumption.
Slow Database Queries
Review MariaDB slow query logs and investigate frequently repeated expensive queries.
Do not assume that increasing the InnoDB buffer pool will resolve inefficient queries.
Redis or Memcached Is Running but WordPress Is Still Slow
Verify that WordPress has an active, compatible persistent object cache integration.
Confirm that cache requests are producing useful hits.
Object caching does not eliminate all PHP processing or frontend bottlenecks.
FastCGI Cache Does Not Produce Cache Hits
Review the cache configuration, bypass rules, response headers, and cache directory permissions.
Some responses may intentionally bypass caching because they contain cookies, authentication information, or personalized content.
WooCommerce Cart or Checkout Problems
Disable the affected page caching layer and review cache exclusions.
Ensure authenticated sessions and customer-specific responses are not served from a shared cache.
Website Is Fast for Anonymous Visitors but Slow for Logged-In Users
This can occur because anonymous requests benefit from full-page caching while authenticated requests still execute WordPress and PHP.
Investigate PHP-FPM performance, database queries, object caching, and application-specific workloads.
26. Safe Production Optimization and Rollback
Before modifying production WordPress infrastructure:
- Create a verified backup of WordPress files and the database.
- Back up configuration files with timestamps.
- Record the original settings.
- Make one significant change at a time.
- Validate configuration syntax before reloading services.
- Measure performance before and after each change.
- Test login, administration, forms, and checkout functionality.
- Keep a documented rollback procedure.
For Nginx changes, validate configuration using:
sudo nginx -t
For PHP-FPM changes, use the matching PHP-FPM validation command.
If a change causes problems, restore the relevant timestamped configuration backup and reload or restart the affected service after validating the restored configuration.
Important: Database tuning changes may require additional version-specific rollback procedures. Do not assume that every database parameter can be reversed safely without considering its operational effects.
27. Recommended WordPress Optimization Checklist
- Use a supported Ubuntu release.
- Keep WordPress, PHP, Nginx, and MariaDB updated.
- Measure performance before making changes.
- Configure PHP-FPM according to available RAM.
- Enable and tune PHP OPcache.
- Use Redis or Memcached when appropriate.
- Configure safe page caching for anonymous visitors.
- Exclude authenticated and personalized content from shared caches.
- Optimize database queries.
- Compress and resize images.
- Reduce unnecessary JavaScript and CSS.
- Enable suitable HTTP compression.
- Use a CDN when beneficial.
- Configure WordPress background tasks appropriately.
- Monitor CPU, RAM, disk I/O, and application performance.
- Test Core Web Vitals regularly.
- Maintain verified backups and rollback procedures.
Related WordPress and Ubuntu VPS Tutorials
- How to Host WordPress on an Ubuntu VPS with Nginx and Free SSL
- How to Install PHP and PHP-FPM on an Ubuntu VPS
- How to Install and Configure Redis on an Ubuntu VPS
- How to Monitor CPU, RAM, Disk, and Network Usage on a Linux VPS
- How to Install Netdata for Real-Time Linux VPS Monitoring
- How to Install Prometheus and Grafana on an Ubuntu VPS
Run a Faster WordPress Website with Owned Networks
WordPress performance depends on efficient application configuration, reliable server resources, and properly implemented caching.
With Owned Networks KVM VPS hosting, you can deploy WordPress with full root access and configure Nginx, PHP-FPM, Redis, MariaDB, and other services according to your workload.
Whether you manage a business website, content platform, or WooCommerce store, a properly configured VPS provides the flexibility needed to optimize your hosting environment.
Explore Owned Networks VPS Hosting and build a faster WordPress hosting environment.