Comments on Configuring Your LEMP System (Linux, nginx, MySQL, PHP-FPM) For Maximum Performance

Configuring Your LEMP System (Linux, nginx, MySQL, PHP-FPM) For Maximum Performance If you are using nginx as your webserver, you are looking for a performance boost and better speed. nginx is fast by default, but you can optimize its performance and the performance of all parts (like PHP and MySQL) that work together with nginx. Here is a small, incomprehensive list of tips and tricks to configure your LEMP system (Linux, nginx, MySQL, PHP-FPM) for maximum performance. These tricks work for me, but your mileage may vary. Do not implement them all at once, but one by one and check what effect the modification has on your system's performance.

12 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Maarten

Thanks Falko,

I find this a very useful post and it made me evaluate my config files for more improvements!

By: valentin ciopei

A verry usefull giude. Thank you

By:

Hi Falko,

Firstly thanks for the How-To!

When I used the suggested config above for APC: apc.shm_size="512" ,  after reloading the php5-fpm process got killed and could not be started, as long as this setting is enabled.

And the log says:

[apc-error] apc_mmap: mmap failed: No space left on device

 I though it's about allocating RAM to the APC, so why it's talking here about "device" ? Anyway my VPS has 1.5GB free RAM.

Any idea?

Wahid 

 

 

By: josimar camargo

very nice post,,,

 very very thanks

By: bobural

Hi,

 Is it too much to ask for an updated how to... for the new nginx 1.4.2 and php-fpm with a MySQL database? I am trying to adapt this tutorial but I am a bit lost :(

thank you very much...

B.

By: misterm

good morning

when I activate this

location ~ \.php$ { # Setup var defaults set $no_cache ""; # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie if ($request_method !~ ^(GET|HEAD)$) { set $no_cache "1"; } # Drop no cache cookie if need be # (for some reason, add_header fails if included in prior if-block) if ($no_cache = "1") { add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/"; add_header X-Microcachable "0"; } # Bypass cache if no-cache cookie is set if ($http_cookie ~* "_mcnc") { set $no_cache "1"; } # Bypass cache if flag is set fastcgi_no_cache $no_cache; fastcgi_cache_bypass $no_cache; fastcgi_cache microcache; fastcgi_cache_key $scheme$host$request_uri$request_method; fastcgi_cache_valid 200 301 302 10m; fastcgi_cache_use_stale updating error timeout invalid_header http_500; fastcgi_pass_header Set-Cookie; fastcgi_pass_header Cookie; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/lib/php5-fpm/web1.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_intercept_errors on; }

I have an error message that appears when I look if my config is good.

nginx -t

 

nginx: [emerg] the size 10485760 of shared memory zone "microcache" conflicts with already declared size 0 in /etc/nginx/nginx.conf:130

 

logic?

thank you

Mz

By: Kevin

Put the vhost configuration after the cache settings. I would recommend at the end of the http{} block.

e.g. include /etc/nginx/conf.d/*.conf;

By: Phil

Hello Falko,

Can you remember me all the packet to install ? (apt-get install ????)

Thanks you

By: tham

My page auto download when access page

Please help me

By: ben

@tham:probably you use <? echo "test"; ?> , namely the short php tags. there is an option in the php.ini where you can change it. 

By: Bengi

Very  very  thank you

By: Roman

Best config i found. Thank you!