July 18

Optimizing PHP Page Cache Speeds on Apache Servers

GE
Galaxy Elevate Team
5 Min Read

Server-Side Caching for PHP Applications

PHP page caching on Apache can reduce server response times from 800ms to under 50ms. Here is the exact configuration we use for our clients.

Enable mod_expires

The Apache mod_expires module controls cache headers for static and dynamic content. Enable it in your .htaccess or server config:

ExpiresActive On\nExpiresByType text/html "access plus 1 hour"\nExpiresByType image/jpeg "access plus 1 year"\nExpiresByType text/css "access plus 1 month"

Enable mod_deflate

Compression reduces file sizes by 60-80%. Enable gzip for HTML, CSS, JS, and JSON responses.

PHP OPcache Configuration

OPcache stores compiled PHP scripts in shared memory, eliminating file reads on every request. Set these values in php.ini:

  • opcache.enable=1
  • opcache.memory_consumption=256
  • opcache.max_accelerated_files=20000
  • opcache.validate_timestamps=0 (production only)
← Back to blog
Web Dev & UX
Share: Facebook Twitter LinkedIn