Running PHP applications efficiently on a Linux VPS requires systematic validation, tuning, and iterative optimization. This tutorial provides a practical, engineering-focused guide to testing and tuning PHP memory limits, OPcache, Nginx FastCGI caching, kernel parameters, and application-level caching. It is tailored for Ubuntu-based VPS environments commonly used in engineering consulting, SaaS, and SME production workloads.

The approach follows a layered optimization strategy:

  1. Verify and baseline the stack
  2. Tune PHP memory and PHP-FPM process management
  3. Enable and optimize OPcache
  4. Configure Nginx caching and workers
  5. Apply compression, HTTP/2, and TLS optimizations
  6. Tune kernel and network parameters
  7. Add database and application-level caching
  8. Measure, validate, and iterate under load

Nginx & PHP-FPM Performance Tuning on Ubuntu VPS

Executive Summary

Running PHP applications efficiently on a Linux VPS requires systematic validation, tuning, and iterative optimization. This tutorial provides a practical, engineering-focused guide to testing and tuning PHP memory limits, OPcache, Nginx FastCGI caching, kernel parameters, and application-level caching. It is tailored for Ubuntu-based VPS environments commonly used in engineering consulting, SaaS, and SME production workloads.

The approach follows a layered optimization strategy:

  1. Verify and baseline the stack
  2. Tune PHP memory and PHP-FPM process management
  3. Enable and optimize OPcache
  4. Configure Nginx caching and workers
  5. Apply compression, HTTP/2, and TLS optimizations
  6. Tune kernel and network parameters
  7. Add database and application-level caching
  8. Measure, validate, and iterate under load

1. Prerequisites and Baseline Setup

1.1 Access and Stack Verification

Log into the VPS using SSH with sudo privileges:

 
ssh user@your-vps-ip 
Verify installed components: 
nginx -v 
php -v 
mysql --version

1.2 Install Required Packages (Ubuntu)

sudo apt update && sudo apt install -y \ nginx php-fpm php-mysql php-opcache php-redis \ mariadb-server redis-server htop curl

1.3 Backup Configuration Files

sudo cp -r /etc/nginx /etc/nginx.bak 

 References 

   1.0 Download the Entire Article- PdfLink