SlideShare a Scribd company logo
10 Million hits a day
with WordPress using a $15 VPS
$ whoami
Paolo Tonin
Sysadmin @bakeca.it
Starting a new
WordPress Project is
straightforward
10 minutes setup
deployed on a simple VPS
10 minutes setup
Your website become popular
No Silver Bullet!
Modernize our
stack
Modernize our stack
From
Modernize our stack
To LEMP
#1 PHP Optimization
Switch over
PHP-FPM
#1 PHP-FPM
PHP-FPM (FastCGI Process Manager) is an alternative
PHP FastCGI implementation with some additional
features useful for sites of any size, especially
busier sites.
* Built in from PHP 5.4
#1 PHP-FPM
$ sudo apt-get install -y php7.1-fpm
$ sudo yum install -y php-fpm
# ps fax | grep fpm
833 ? Ss 0:08 php-fpm: master process
(/etc/php-fpm.conf)
1778 ? S 0:02 _ php-fpm: pool www
1779 ? S 0:02 _ php-fpm: pool www
1780 ? S 0:02 _ php-fpm: pool www
1781 ? S 0:02 _ php-fpm: pool www
Let’s dive into
some details
#1 PHP-FPM
pm = dynamic
Similar to Apache prefork
#1 PHP-FPM
pm = ondemand
Ideal for hosting many
small websites with small
amount of request
#1 PHP-FPM
pm = static
Fixed php-fpm process
number to archieve your
server’s max performance
#1 PHP-FPM
; /etc/php-fpm.d/www.conf
[www]
pm = static
pm.max_children = 10
user = sitename
group = sitename
; listen on unix socket over tcp socket
listen = /var/run/php-fpm/sitename-php-fpm.sock
listen.owner = sitename
listen.group = nginx
listen.mode = 0660
; /etc/php-fpm.d/www.conf
; try to avoid memory leaks, it enables php-fpm
process respawning
pm.max_requests = 700
; audit slow request with stack trace log
slowlog = /var/log/php-fpm/sitename-slow.log
request_slowlog_timeout = 30s
; similar to “max_execution_time”, it has more
priority than php.ini max_execution_time
request_terminate_timeout = 180
; log PHP Warning, Error, Fatal (not by default)
catch_workers_output = yes
#1.1 PHP Optimization
PHP 7 + OpCache
; enable-opcache-file
; php.ini
opcache.memory_consumption = 512
opcache.max_accelerated_files = 10000
opcache.interned_strings_buffer = 128
opcache.file_cache = /var/tmp
opcache.huge_code_pages =1
; php-cli.ini for WP-CLI and cronjobs
opcache.enable_cli = 1
opcache.file_cache = /var/tmp	
opcache.file_cache_only = 1
#1.1 PHP OpCache
#1.1 PHP OpCache
; sysctl.conf
; enable hugepages, PHP7 only
vm.nr_hugepages = 512
# cat /proc/meminfo | grep Huge
AnonHugePages: 6144 kB
HugePages_Total: 512
HugePages_Free: 300
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
#1.1 PHP OpCache
# ps ef -o command,vsize,rss,size -C php-fpm
COMMAND VSZ RSS SIZE
php-fpm: master process (/e 933836 278428 6204
_ php-fpm: pool www 1031728 42692 92916
_ php-fpm: pool www 1026596 40596 87784
_ php-fpm: pool www 1025452 37780 86640
_ php-fpm: pool www 1026252 35368 87440
Check php-fpm Memory Consumption
40MB * 50 php-fpm processes = 2GB RAM
#2 Replace webserver
245 million
total sites and counting…
running on NGINX
#2 Replace webserver
Many config examples on
https://www.nginx.com/resources/
wiki/start/index.html
#2 Replace webserver
* Netcraft Sept 2017
#2.1 nginx
System config limits
# /etc/security/limits.conf
# overrides ulimit values
#<domain> <type> <item> <value>
nginx hard nofile 100000
nginx soft nofile 100000
#2.1 nginx
Nginx config limits
# nginx.conf
user nginx;
worker_processes auto;
worker_rlimit_nofile 10000;
events {
worker_connections 16384;
multi_accept on;
use epoll;
}
#2.1 nginx
Gzip compression
# nginx.conf (continue)
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_buffers 32 8k;
#2.1 nginx
Limit filesystem activity for
static contents
# nginx.conf (continue)
open_file_cache max=10000 inactive=10s;
open_file_cache_valid 20s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
#2.2 nginx
Nginx as reverse proxy
#2.2 nginx
HTTP Caching primer
Expires: contains the datetime after which
the response is considered stale. It has
priority over Cache-Control
Cache-Control: used to specify directives for
caching mechanism in both, request and
response
Last-Modified: contains the date and time
at which the origin server believes the
resource was last modified. HTTP dates are
always expressed in GMT
ETag: it’s an identifier for a specific version
of a resource
proxy_cache_path /tmp/cache keys_zone=one:10m levels=1:2
inactive=60m;
server {
listen 80;
server_name mywordpressdomain.com
location / {
proxy_pass http://localhost:8080
proxy_cache one;
}
}
#2.2 nginx
HTTP Caching primer
add_header X-Cache-Status $upstream_cache_status
MISS Response not found in cache; go to upstream
and save the results in the cache
STALE Serve the stale content from the cache,
because the upstream is not responding correctly
HIT Serve valid content, fresh content direct from
cache
#2.2 nginx
HTTP Caching instrumentation
proxy_cache_path /tmp/cache keys_zone=one:10m levels=1:2
inactive=60m;
server {
listen 80;
server_name mywordpressdomain.com
location / {
proxy_pass http://localhost:8080
proxy_cache one;
add_header X-Cache-Status $upstream_cache_status;
}
}
#2.2 nginx
HTTP Caching primer
PURGE verb is not supported
in the OSS version
$ curl -X PURGE -D - “http://domain.com/*"
Cache dynamic contents
with fastcgi-cache
(microcaching)
“Go Big or Go Home”
#2.3 nginx
php-fpm fastcgi cache
# ps fax | grep nginx
922 ? Ss 0:00 nginx: master process /usr/sbin/nginx -
c /etc/nginx/nginx.conf
3988 ? S 0:00 _ nginx: worker process
3989 ? S 0:00 _ nginx: worker process
3990 ? S 0:00 _ nginx: cache manager process
Cache Manager activated periodically to check the
state of the cache.
The cache manager removes the data that was
accessed recently as well the cache considered
inactive
#2.3 nginx
php-fpm fastcgi cache
; nginx.conf http block
upstream php-web {
server unix:/var/run/php-fpm/sitename.sock
weight=100;
server unix:/var/run/php-fpm/sitename.sock
weight=100;
}
fastcgi_cache_path /var/tmp/nginx-fastcgi-cache
levels=1:2 keys_zone=WPCACHE:100m max_size=1024m
inactive=1h;
#2.3 nginx
php-fpm fastcgi cache
; creates a cache version with these discriminants
fastcgi_cache_key
"$scheme$request_method$host$request_uri;
; at least 1 request to populate with a new cache
element
fastcgi_cache_lock on;
; consider stale response errors
fastcgi_cache_use_stale error timeout invalid_header
http_500;
#2.3 nginx
php-fpm fastcgi cache
; enables revalidation of expired cache with the
"If-Modified-Since" and "If-None-Match" header
fields.
fastcgi_cache_revalidate on;
; no cache for redirects
fastcgi_cache_valid 301 0;
fastcgi_cache_valid 3m;
; cache only GET http verb
fastcgi_cache_methods GET;
#2.3 nginx
php-fpm fastcgi cache
# WARNING: Ignore cache-control; without these
fcgi_cache doesn't works
fastcgi_ignore_headers Cache-Control Expires Set-
Cookie;
fastcgi_pass_header Cookie;
#2.3 nginx
php-fpm fastcgi cache
# WARNING: Ignore cache-control; without these
fcgi_cache doesn't works
fastcgi_ignore_headers Cache-Control Expires Set-
Cookie;
fastcgi_pass_header Cookie;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME
$realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param HTTPS off;
fastcgi_intercept_errors on;
fastcgi_pass php-web;
# Enable fastcgi_cache
fastcgi_cache WPCACHE;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
}
Bonus content
WordPress plugins
WP Offload S3 copies files from your WordPress
Media Library to Amazon S3 and rewrites URLs to
serve the files from S3, CloudFront, or another CDN
WP Offload S3
WordPress plugins
Replacement for wpdb class. It supports partition
of data as well as replication and read write splits
Used for commercial service wordpress.com
WordPress plugins
Cache database results into Memcached, it also
support integration with CDN providers
“Talk is cheap,
show me the code”
(cit. Linus Torvalds)
Demo
10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS

More Related Content

What's hot

Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
Rodolfo Carvalho
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Martin Etmajer
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
William Yeh
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
Lorin Hochstein
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011
Carlos Sanchez
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
Saewoong Lee
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
Carlos Sanchez
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
Carlos Sanchez
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerRunning High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Sematext Group, Inc.
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
Carlos Sanchez
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
Ben Hall
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)
Ivan Rossi
 
Herd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration managementHerd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration management
Frederik Engelen
 
Docker ansible-make-chef-puppet-unnecessary-minnihan
Docker ansible-make-chef-puppet-unnecessary-minnihanDocker ansible-make-chef-puppet-unnecessary-minnihan
Docker ansible-make-chef-puppet-unnecessary-minnihan
jbminn
 
Ansible at work
Ansible at workAnsible at work
Ansible at work
Bas Meijer
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
Geeta Vinnakota
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
Ben Hall
 

What's hot (20)

Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerRunning High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)
 
Herd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration managementHerd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration management
 
Docker ansible-make-chef-puppet-unnecessary-minnihan
Docker ansible-make-chef-puppet-unnecessary-minnihanDocker ansible-make-chef-puppet-unnecessary-minnihan
Docker ansible-make-chef-puppet-unnecessary-minnihan
 
Ansible at work
Ansible at workAnsible at work
Ansible at work
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
 

Similar to 10 Million hits a day with WordPress using a $15 VPS

Running PHP on nginx
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
Harald Zeitlhofer
 
Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
Harald Zeitlhofer
 
Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)
Justin Foell
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
Seravo
 
WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
Nginx pres
Nginx presNginx pres
Nginx pres
James Fuller
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
Kevin Jones
 
Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
Wataru OKAMOTO
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
Wataru OKAMOTO
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on Nginx
Harald Zeitlhofer
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
Mathew Beane
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
NGINX, Inc.
 
Speed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PGSpeed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PG
Marcus Sá
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - Cascadia
Dana Luther
 
Docker for mac & local developer environment optimization
Docker for mac & local developer environment optimizationDocker for mac & local developer environment optimization
Docker for mac & local developer environment optimization
Radek Baczynski
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
Dana Luther
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
RootGate
 
Lonestar php scalingmagento
Lonestar php scalingmagentoLonestar php scalingmagento
Lonestar php scalingmagento
Mathew Beane
 

Similar to 10 Million hits a day with WordPress using a $15 VPS (20)

Running PHP on nginx
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
 
Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
 
Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on Nginx
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Speed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PGSpeed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PG
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - Cascadia
 
Docker for mac & local developer environment optimization
Docker for mac & local developer environment optimizationDocker for mac & local developer environment optimization
Docker for mac & local developer environment optimization
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
 
Lonestar php scalingmagento
Lonestar php scalingmagentoLonestar php scalingmagento
Lonestar php scalingmagento
 

Recently uploaded

Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
Trending Blogers
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
uehowe
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
cuobya
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
bseovas
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
ukwwuq
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
zoowe
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 

Recently uploaded (20)

Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 

10 Million hits a day with WordPress using a $15 VPS

  • 1. 10 Million hits a day with WordPress using a $15 VPS
  • 3.
  • 4. Starting a new WordPress Project is straightforward
  • 5. 10 minutes setup deployed on a simple VPS
  • 8.
  • 9.
  • 16. #1 PHP-FPM PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. * Built in from PHP 5.4
  • 17. #1 PHP-FPM $ sudo apt-get install -y php7.1-fpm $ sudo yum install -y php-fpm # ps fax | grep fpm 833 ? Ss 0:08 php-fpm: master process (/etc/php-fpm.conf) 1778 ? S 0:02 _ php-fpm: pool www 1779 ? S 0:02 _ php-fpm: pool www 1780 ? S 0:02 _ php-fpm: pool www 1781 ? S 0:02 _ php-fpm: pool www
  • 19.
  • 20. #1 PHP-FPM pm = dynamic Similar to Apache prefork
  • 21. #1 PHP-FPM pm = ondemand Ideal for hosting many small websites with small amount of request
  • 22. #1 PHP-FPM pm = static Fixed php-fpm process number to archieve your server’s max performance
  • 23. #1 PHP-FPM ; /etc/php-fpm.d/www.conf [www] pm = static pm.max_children = 10 user = sitename group = sitename ; listen on unix socket over tcp socket listen = /var/run/php-fpm/sitename-php-fpm.sock listen.owner = sitename listen.group = nginx listen.mode = 0660
  • 24. ; /etc/php-fpm.d/www.conf ; try to avoid memory leaks, it enables php-fpm process respawning pm.max_requests = 700 ; audit slow request with stack trace log slowlog = /var/log/php-fpm/sitename-slow.log request_slowlog_timeout = 30s ; similar to “max_execution_time”, it has more priority than php.ini max_execution_time request_terminate_timeout = 180 ; log PHP Warning, Error, Fatal (not by default) catch_workers_output = yes
  • 26. ; enable-opcache-file ; php.ini opcache.memory_consumption = 512 opcache.max_accelerated_files = 10000 opcache.interned_strings_buffer = 128 opcache.file_cache = /var/tmp opcache.huge_code_pages =1 ; php-cli.ini for WP-CLI and cronjobs opcache.enable_cli = 1 opcache.file_cache = /var/tmp opcache.file_cache_only = 1 #1.1 PHP OpCache
  • 27. #1.1 PHP OpCache ; sysctl.conf ; enable hugepages, PHP7 only vm.nr_hugepages = 512 # cat /proc/meminfo | grep Huge AnonHugePages: 6144 kB HugePages_Total: 512 HugePages_Free: 300 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
  • 28. #1.1 PHP OpCache # ps ef -o command,vsize,rss,size -C php-fpm COMMAND VSZ RSS SIZE php-fpm: master process (/e 933836 278428 6204 _ php-fpm: pool www 1031728 42692 92916 _ php-fpm: pool www 1026596 40596 87784 _ php-fpm: pool www 1025452 37780 86640 _ php-fpm: pool www 1026252 35368 87440 Check php-fpm Memory Consumption 40MB * 50 php-fpm processes = 2GB RAM
  • 29. #2 Replace webserver 245 million total sites and counting… running on NGINX
  • 30. #2 Replace webserver Many config examples on https://www.nginx.com/resources/ wiki/start/index.html
  • 31. #2 Replace webserver * Netcraft Sept 2017
  • 32. #2.1 nginx System config limits # /etc/security/limits.conf # overrides ulimit values #<domain> <type> <item> <value> nginx hard nofile 100000 nginx soft nofile 100000
  • 33. #2.1 nginx Nginx config limits # nginx.conf user nginx; worker_processes auto; worker_rlimit_nofile 10000; events { worker_connections 16384; multi_accept on; use epoll; }
  • 34. #2.1 nginx Gzip compression # nginx.conf (continue) gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_min_length 256; gzip_buffers 32 8k;
  • 35. #2.1 nginx Limit filesystem activity for static contents # nginx.conf (continue) open_file_cache max=10000 inactive=10s; open_file_cache_valid 20s; open_file_cache_min_uses 2; open_file_cache_errors on;
  • 36. #2.2 nginx Nginx as reverse proxy
  • 38. Expires: contains the datetime after which the response is considered stale. It has priority over Cache-Control Cache-Control: used to specify directives for caching mechanism in both, request and response
  • 39. Last-Modified: contains the date and time at which the origin server believes the resource was last modified. HTTP dates are always expressed in GMT ETag: it’s an identifier for a specific version of a resource
  • 40. proxy_cache_path /tmp/cache keys_zone=one:10m levels=1:2 inactive=60m; server { listen 80; server_name mywordpressdomain.com location / { proxy_pass http://localhost:8080 proxy_cache one; } } #2.2 nginx HTTP Caching primer
  • 41. add_header X-Cache-Status $upstream_cache_status MISS Response not found in cache; go to upstream and save the results in the cache STALE Serve the stale content from the cache, because the upstream is not responding correctly HIT Serve valid content, fresh content direct from cache #2.2 nginx HTTP Caching instrumentation
  • 42. proxy_cache_path /tmp/cache keys_zone=one:10m levels=1:2 inactive=60m; server { listen 80; server_name mywordpressdomain.com location / { proxy_pass http://localhost:8080 proxy_cache one; add_header X-Cache-Status $upstream_cache_status; } } #2.2 nginx HTTP Caching primer
  • 43. PURGE verb is not supported in the OSS version $ curl -X PURGE -D - “http://domain.com/*"
  • 44. Cache dynamic contents with fastcgi-cache (microcaching) “Go Big or Go Home”
  • 45. #2.3 nginx php-fpm fastcgi cache # ps fax | grep nginx 922 ? Ss 0:00 nginx: master process /usr/sbin/nginx - c /etc/nginx/nginx.conf 3988 ? S 0:00 _ nginx: worker process 3989 ? S 0:00 _ nginx: worker process 3990 ? S 0:00 _ nginx: cache manager process Cache Manager activated periodically to check the state of the cache. The cache manager removes the data that was accessed recently as well the cache considered inactive
  • 46. #2.3 nginx php-fpm fastcgi cache ; nginx.conf http block upstream php-web { server unix:/var/run/php-fpm/sitename.sock weight=100; server unix:/var/run/php-fpm/sitename.sock weight=100; } fastcgi_cache_path /var/tmp/nginx-fastcgi-cache levels=1:2 keys_zone=WPCACHE:100m max_size=1024m inactive=1h;
  • 47.
  • 48. #2.3 nginx php-fpm fastcgi cache ; creates a cache version with these discriminants fastcgi_cache_key "$scheme$request_method$host$request_uri; ; at least 1 request to populate with a new cache element fastcgi_cache_lock on; ; consider stale response errors fastcgi_cache_use_stale error timeout invalid_header http_500;
  • 49. #2.3 nginx php-fpm fastcgi cache ; enables revalidation of expired cache with the "If-Modified-Since" and "If-None-Match" header fields. fastcgi_cache_revalidate on; ; no cache for redirects fastcgi_cache_valid 301 0; fastcgi_cache_valid 3m; ; cache only GET http verb fastcgi_cache_methods GET;
  • 50. #2.3 nginx php-fpm fastcgi cache # WARNING: Ignore cache-control; without these fcgi_cache doesn't works fastcgi_ignore_headers Cache-Control Expires Set- Cookie; fastcgi_pass_header Cookie;
  • 51. #2.3 nginx php-fpm fastcgi cache # WARNING: Ignore cache-control; without these fcgi_cache doesn't works fastcgi_ignore_headers Cache-Control Expires Set- Cookie; fastcgi_pass_header Cookie;
  • 52. location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.*)$; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param HTTPS off; fastcgi_intercept_errors on; fastcgi_pass php-web; # Enable fastcgi_cache fastcgi_cache WPCACHE; fastcgi_cache_bypass $no_cache; fastcgi_no_cache $no_cache; }
  • 54. WordPress plugins WP Offload S3 copies files from your WordPress Media Library to Amazon S3 and rewrites URLs to serve the files from S3, CloudFront, or another CDN WP Offload S3
  • 55. WordPress plugins Replacement for wpdb class. It supports partition of data as well as replication and read write splits Used for commercial service wordpress.com
  • 56. WordPress plugins Cache database results into Memcached, it also support integration with CDN providers
  • 57. “Talk is cheap, show me the code” (cit. Linus Torvalds)
  • 58. Demo