CentOS 7: PHP Caching

  LEMP, Nginx

Since you can get a shed load of RAM these day for next to nothing you might as well use to improve performance. Pretty easy to do, just tell your “server block” what to do.

Open up /etc/nginx/conf.d/example.cof drop this in about the “server {” tag e.g.

fastcgi_cache_path /dev/shm/nginx/ levels=1:2 keys_zone=CACHE:16m max_size=1024m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

server {

Note the /dev/shm/nginx this is RAM disk goodness. It’s actually made of crack. Anyway tell php what you’ve done by add “fastcgi_cache CACHE;”

location ~ .php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_cache CACHE;

fastcgi_cache_valid 200 60m;
}

Restart Nginx (My mind keeps pronouncing it “En jinx”, really annoying)

systemctl restart nginx