Moving to a Virtual Private Server is a significant step up from shared hosting — and with that step comes both greater opportunity and greater responsibility. On a VPS, you have dedicated resources and root access, which means you can implement server-level optimizations that are simply impossible on shared hosting. You’re also responsible for configuring those optimizations yourself.
This guide covers the most impactful VPS-level web server optimizations, from choosing the right web server software to fine-tuning caching, database performance, and system resources. Whether you’re running Apache, Nginx, or LiteSpeed, there’s substantial performance to be gained from proper configuration.
Choose the Right Web Server Software
If you’re setting up a new VPS or considering migrating, your choice of web server software has a major impact on performance — especially under load.
- Nginx: Generally faster than Apache for serving static files and handling high numbers of concurrent connections. Uses an event-driven, asynchronous architecture that consumes significantly less memory per connection. The preferred choice for high-traffic sites
- Apache with MPM Event: The default Apache configuration (prefork) creates a new process for each connection, which is resource-intensive. Switching to the Event Multi-Processing Module brings Apache much closer to Nginx’s performance profile
- LiteSpeed: A commercial web server (with a free open-source version called OpenLiteSpeed) that outperforms both Apache and Nginx in many benchmarks, particularly for PHP workloads. Natively compatible with Apache .htaccess files, making migration straightforward
For most WordPress or PHP-based sites on a VPS, Nginx + PHP-FPM or LiteSpeed are the highest-performance configurations available.
Configure PHP-FPM for Optimal Performance
PHP-FPM (FastCGI Process Manager) is the recommended way to run PHP on a VPS. Unlike mod_php (which loads PHP into every Apache process), PHP-FPM runs PHP as a separate service with its own process pool, using resources much more efficiently.
Key PHP-FPM configuration settings to tune (found in /etc/php-fpm.d/www.conf or similar):
- pm = dynamic: Use dynamic process management rather than static for better resource efficiency
- pm.max_children: Set based on your available RAM. A rough formula: (Total RAM – OS overhead) / average PHP process size. For a 2GB VPS, 20-30 is a reasonable starting point
- pm.start_servers, pm.min_spare_servers, pm.max_spare_servers: Tune these to keep warm processes available without over-provisioning
- pm.max_requests = 500: Restart PHP workers after 500 requests to prevent memory leaks from accumulating
Enable OPcache for PHP
OPcache is a PHP bytecode cache that stores compiled PHP scripts in memory, eliminating the need to recompile them on every request. It’s one of the highest-impact PHP optimizations available and is included with PHP 5.5+.
Add or verify these settings in your php.ini:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
OPcache alone can reduce PHP execution time by 50-70% for typical WordPress and PHP applications.
Configure Nginx for Performance
If you’re running Nginx, several configuration tweaks make a significant difference:
- Enable gzip compression: Add gzip on; and gzip_types text/html text/css application/javascript application/json; to your nginx.conf
- Set worker_processes to auto: This automatically sets the number of Nginx worker processes equal to the number of CPU cores
- Increase worker_connections: Set worker_connections to 1024 or higher in the events block
- Enable sendfile and tcp_nopush: These directives optimize file transfer performance for static assets
- Configure FastCGI caching: Nginx’s FastCGI cache can store the output of PHP-generated pages and serve them as static files, similar to a full-page cache plugin but handled at the server level
Implement Redis or Memcached for Object Caching
On a VPS, you can run a dedicated in-memory caching service like Redis or Memcached. These store frequently accessed data — database query results, session data, computed values — in RAM, dramatically reducing database load.
For WordPress, Redis object caching with the Redis Object Cache plugin is a particularly powerful combination:
- Install Redis on your VPS: sudo apt install redis-server
- Configure Redis to use an appropriate amount of memory: Set maxmemory 256mb and maxmemory-policy allkeys-lru in /etc/redis/redis.conf
- Install the Redis Object Cache plugin in WordPress and connect it to your Redis instance
Sites with high database query loads — WooCommerce stores, membership sites, busy blogs — see the most dramatic improvements from Redis caching, often reducing database load by 80% or more.
Tune MySQL/MariaDB for Your Workload
The default MySQL and MariaDB configurations are intentionally conservative to run on low-memory systems. On a VPS with dedicated RAM, you can tune these settings significantly upward.
Key settings to adjust in /etc/mysql/my.cnf:
- innodb_buffer_pool_size: The most important MySQL setting. Set to 60-70% of available RAM for a dedicated database server, or 25-30% if MySQL shares the VPS with your web server. This keeps frequently accessed data in memory
- query_cache_size: Deprecated in MySQL 8.0 but useful in older versions for caching query results
- max_connections: Tune to match your expected concurrent traffic — too high wastes memory, too low causes connection errors
- innodb_log_file_size: Larger log files improve write performance for sites with heavy database writes
Configure a Full-Page Cache at the Server Level
Application-level caching plugins are effective, but server-level caching is faster because it doesn’t require invoking PHP at all. On Nginx, FastCGI caching can serve cached pages in under 5 milliseconds — compared to 100-500ms for an uncached PHP request.
For Nginx FastCGI caching, add to your nginx.conf:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=MYAPP:10m inactive=60m;
fastcgi_cache_key ‘$scheme$request_method$host$request_uri’;
Then in your server block, add:
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m;
fastcgi_cache_bypass $no_cache;
Monitor Resource Usage and Set Up Alerts
Unlike shared hosting where the provider monitors the server, on a VPS you’re responsible for knowing when resources are being exhausted. Set up monitoring early — before you have a problem.
- Install a monitoring tool: Netdata (netdata.cloud) provides real-time performance monitoring with a free self-hosted option and takes about 5 minutes to install
- Monitor key metrics: CPU usage, memory usage, disk I/O, and MySQL query times
- Set up alerts: Configure email or SMS alerts when CPU exceeds 80% or available memory drops below 20%
- Review slow query logs: Enable MySQL’s slow query log to identify queries taking over 1 second — these are your highest-priority optimization targets
Keep Software Updated
Running outdated software on a VPS is both a security risk and a performance liability. PHP 8.x is substantially faster than PHP 7.x. MySQL 8 includes significant performance improvements over MySQL 5.7. Nginx and Apache both release performance improvements in minor version updates.
On Ubuntu/Debian systems, set up automatic security updates:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
A well-configured VPS can handle ten times the traffic of shared hosting at the same cost — and do it faster. The optimizations in this guide, particularly OPcache, Redis object caching, and server-level full-page caching, transform what a modest VPS can handle. The investment of time in proper configuration pays for itself immediately in better performance and lower hosting costs per visitor served.