SlideShare a Scribd company logo
Optimización de servidor web
Con
Nginx y PHP-FPM
Yannick Warnier
@ywarnier
Introducción a Nginx y PHP FPM
http://t3n.de/news/wp-content/uploads/2016/03/nginx-hoster-benchmark-nginx-vs-apache.jpg
PHP-FPM
● FastCGI Process Manager
● Implementación alternativa de PHP FastCGI
● Con funcionalidades adicionales utiles para sitios de
todos tamaños, en particular sitios muy activos
● Integrado en PHP desde PHP 5.4 en Nov 2011
Introducción a Nginx y PHP FPM
PHP-FPM
● Gestión de procesos avanzada
● Posibilidad workers con uid/ambientes distintos
● ...y php.ini distintos
● Soporte de upload acelerado
● Slow log
● ...
PHP-FPM + Nginx
Apache + modPHP
Apache
HDD / SSD
DB
Mod-PHP
Apache + modPHP
Apache
HDD / SSD
DB
Mod-PHP
Apache + modPHP
Apache
HDD / SSD
DB
Mod-PHP
Apache + modPHP
Apache
HDD / SSD
DB
Mod-PHP
Nginx + PHP-FPM
Nginx
HDD / SSD
DB
PHP-FPM
PHP-FPM
PHP-FPM
Nginx + PHP-FPM
Nginx
HDD / SSD
DB
PHP-FPM
PHP-FPM
PHP-FPM
Nginx + PHP-FPM
Nginx
Asíncrono
HDD / SSD
DB
PHP-FPM
PHP-FPM
PHP-FPM
Nginx + PHP-FPM
Nginx
Asíncrono
HDD / SSD
DB
PHP-FPM
PHP-FPM
PHP-FPM
Nginx + PHP-FPM
Nginx
Asíncrono
HDD / SSD
DB
PHP-FPM
PHP-FPM
PHP-FPM
Instalar PHP-FPM
Configurar PHP-FPM
user@server:~$ sudo vim /etc/php/7.1/fpm/
conf.d/       php­fpm.conf  php.ini       pool.d/   
user@server:~$ sudo vim /etc/php/7.1/fpm/php.ini
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The following is a summary of its search order:
Configurar PHP-FPM
user@server:~$ sudo vim /etc/php/7.1/fpm/pool.d/www.conf
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
; …
user = www­data
group = www­data
; …
listen = /run/php/php7.1­fpm.sock
listen.owner = www­data
listen.group = www­data
; …
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s;
Configurar PHP-FPM
user@server:~$ sudo vim /etc/php/7.1/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s;
pm.max_requests = 500
access.log = log/$pool.access.log
slowlog = log/$pool.log.slow
request_slowlog_timeout = 0
Configurar PHP-FPM
user@server:~$ sudo vim /etc/php/7.1/fpm/pool.d/www.conf
;php_admin_value[sendmail_path] = /usr/sbin/sendmail ­t 
­i ­f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm­php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
En resumen: todo por defecto!
Configurar Nginx
- sudo apt-get install nginx-full
- sudo vim /etc/nginx/nginx.conf
user www­data;
worker_processes auto;
pid /run/nginx.pid;
events {
    worker_connections 768;
    # multi_accept on;
}
Configurar Nginx
- sudo apt-get install nginx-full
- sudo vim /etc/nginx/nginx.conf
http {
    ##
    # Basic Settings
    ##
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;
Configurar Nginx
- sudo apt-get install nginx-full
- sudo vim /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    index index.html index.htm index.nginx­debian.html;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
Configurar Nginx
- sudo apt-get install nginx-full
- sudo vim /etc/nginx/sites-available/default
server {
    # ...
    # pass the PHP scripts to FastCGI server
    # listening on 127.0.0.1:9000
    #
    location ~ .php$ {
       include snippets/fastcgi­php.conf;
       # With php7.1­fpm:
       fastcgi_pass unix:/run/php/php7.1­fpm.sock;
    }
Configurar Nginx
- sudo service php-fpm restart
- sudo service apache2 stop (si tiene Apache)
- sudo service nginx restart
Ventajas
- Asíncrono (libevent)
- Balanceador de carga (directiva “upstream”)
- Reverse Proxy (caché)
- Soporte SSL completo
- Soporte moderación
- limit_conn / limit_conn_zone
- limit_rate
- limit_req / limit_req_zone
- max_conns (upstream)
- queue
- Compresión
@ywarnier
BeezNest

More Related Content

PPTX
Diseases caused by bacteria
PPTX
Approach to chest pain
DOCX
Dengue fever
PPTX
Nginx [engine x] and you (and WordPress)
PDF
Nginx pres
PDF
10 Million hits a day with WordPress using a $15 VPS
PPTX
Maximizing PHP Performance with NGINX
PPTX
20151229 wnmp & phalcon micro app - part I
Diseases caused by bacteria
Approach to chest pain
Dengue fever
Nginx [engine x] and you (and WordPress)
Nginx pres
10 Million hits a day with WordPress using a $15 VPS
Maximizing PHP Performance with NGINX
20151229 wnmp & phalcon micro app - part I

Similar to Introducción a Nginx y PHP FPM (20)

PDF
Speed up your development environment PHP + Nginx + Fedora + PG
PDF
Sofia WP User Group Presentation
PPTX
PHP and FastCGI Performance Optimizations
PPTX
Drupal 8 and NGINX
PPTX
PHP conference Berlin 2015: running PHP on Nginx
PDF
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
PDF
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
PPTX
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
PDF
Django deployment and rpm+yum
PDF
Use Xdebug to profile PHP
PPTX
Joomla! Performance on Steroids
PDF
Magento caching
PDF
Last Month in PHP - June 2016
DOCX
How to install and configure LEMP stack
PDF
OSCamp 2019 | #3 Ansible: Foreman Discovery by Adam Ruzicka
PDF
Docker for mac & local developer environment optimization
PDF
WordPress Powered by AMIMOTO HHVM
PDF
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
PDF
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!
PDF
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Speed up your development environment PHP + Nginx + Fedora + PG
Sofia WP User Group Presentation
PHP and FastCGI Performance Optimizations
Drupal 8 and NGINX
PHP conference Berlin 2015: running PHP on Nginx
Magento's Imagine eCommerce Conference 2011 - Hosting Magento: Performance an...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Django deployment and rpm+yum
Use Xdebug to profile PHP
Joomla! Performance on Steroids
Magento caching
Last Month in PHP - June 2016
How to install and configure LEMP stack
OSCamp 2019 | #3 Ansible: Foreman Discovery by Adam Ruzicka
Docker for mac & local developer environment optimization
WordPress Powered by AMIMOTO HHVM
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Ad

More from Yannick Warnier (20)

PDF
Chamilo, 12 ans déjà
PDF
Chamilo en FLISOL Perú 2018
PDF
Novedades de PHP 7.*
PDF
The benefits of using Git
PDF
Skillms, solution de gestion des talents
PDF
Chamilo "Lectoura", proyecto Hackaton EdTech, Lima 2017
PDF
Novedades de Chamilo 1.11 - 2017
PDF
Chamilo, qu'est-ce? - Chamilo Camp Lyon 2017
PDF
L'avenir de Chamilo - 2017
ODP
Desarrollo del plugin Chamilo-Wordpress
PDF
Calidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CI
PDF
Como usar un aula virtual como recurso educativo - Caso Chamilo
PDF
Asociación Chamilo
PDF
Crear cursos-virtuales-chamilo-flisol-2014
PDF
Chamilo LMS y otros LMSes - Universidad de Valencia, España - Octubre 2013
PDF
Prepa certificación docente Chamilo 1.8 (CHACOBU)
PDF
Chamilo advantages against other LMSes
ODP
Taller de optimizacion de servidores web tipo LAMP
PDF
Chamilo, c'est pas le Pérou - Jeudis du libre
PDF
TICs en educación y Chamilo, introducción para Maestria en Edumática, 2011
Chamilo, 12 ans déjà
Chamilo en FLISOL Perú 2018
Novedades de PHP 7.*
The benefits of using Git
Skillms, solution de gestion des talents
Chamilo "Lectoura", proyecto Hackaton EdTech, Lima 2017
Novedades de Chamilo 1.11 - 2017
Chamilo, qu'est-ce? - Chamilo Camp Lyon 2017
L'avenir de Chamilo - 2017
Desarrollo del plugin Chamilo-Wordpress
Calidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CI
Como usar un aula virtual como recurso educativo - Caso Chamilo
Asociación Chamilo
Crear cursos-virtuales-chamilo-flisol-2014
Chamilo LMS y otros LMSes - Universidad de Valencia, España - Octubre 2013
Prepa certificación docente Chamilo 1.8 (CHACOBU)
Chamilo advantages against other LMSes
Taller de optimizacion de servidores web tipo LAMP
Chamilo, c'est pas le Pérou - Jeudis du libre
TICs en educación y Chamilo, introducción para Maestria en Edumática, 2011
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Introducción a Nginx y PHP FPM