Skip to content

Nginx + OPcache Settings That Actually Matter for Laravel on a VPS

M Mohamed Khalifa
Skip the copy-pasted mega-configs. These are the handful of Nginx and OPcache directives that produce measurable gains on a typical Laravel VPS.

On a typical 2-4GB VPS, three changes account for most of the win:

1. OPcache with validation off

opcache.memory_consumption=192
opcache.validate_timestamps=0

PHP stops re-reading files on every request; reset the cache on deploy instead.

2. Static asset caching in Nginx

location ~* \.(css|js|webp|woff2)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

3. FastCGI buffers

Bump fastcgi_buffers so large HTML responses are not written to disk. Measure before and after with wrk — on a recent client server these three changes doubled requests per second.

Back to Blog DevOps & Servers

Next deploy

Got a project in mind? Let's build it right.

Open a production channel. Architecture first. Delivery owned end to end.

visitor@khalifadev:~ ● ready

$ Contact::connect();

✓ channel open

info@khalifadev.com

$ Mail::send( 'next-system' );