SlideShare a Scribd company logo
1 of 25
Download to read offline
Optimizing Wordpress/PHP 
Optimizing Wordpress/PHP
 webserver performance
           and protecting your server from common 
           security exploits and attacks


   prepared especially for:
  WordCamp 2010 Philippines
          p           pp
       October 2, 2010
Target Audience
                 Target Audience
• WordCamp Philippines 2010
         p      pp
  – Developer Track talks
  – Netrepreuneurs
  – VPS U
    VPS Users

• This is Not
  This is Not
  –   For change‐resistant people
  –   For those afraid of the unix shell
  –   For those on shared hosting
  –   For those looking for a talk on MS IIS or Microsoft 
      Anything.
Why Optimize?
               Why Optimize?
• Visitors Attention span is small.
                      p
   – Need to load FAST
• Google ranks faster loading pages higher than 
  slow ones
   l
• Be ready to get slashdott’d or digg’d
• Save money on server costs
  Save money on server costs. 
• Save sleep and reduce server downtime. 
• Offer more value and specialization to your
  Offer more value and specialization to your 
  clients.
• Increase your lifespan and overall happiness!
Serving your PHP: Quick History
  Serving your PHP: Quick History
• The web outgrows CGI ‐> mod php for Apache 
     e eb outg o s CG          od_p p o pac e
  intro’d around same time as FastCGI (~1995)
       p                  g     g        p
• The practice of bundling a single interpreted 
  instance of php with the httpd became more 
  prevalent and FastCGI fell to wayside.
• For the past 15 yrs Apache has dominated the 
  Internet’s httpd server landscape. To this day, 
  57.12% of all sites run on Apache. Addntly, 
  57 12% of all sites run on Apache Addntly
  mod_php is the most popular apache module, 
  running on over 20mm hosts as of 4/2007. 
         g                             /
mod_php
           mod php weaknesses
• Slow, Fat &Insecure
  S o , at & secu e
• Bloated footprint.
   – Every httpd process is tied to the mod_p p
          y p p                                  php
     interpreter. This means all files, incl. css, js are served 
     with mod_php tied to httpd. Unnecessary and set 
     trend for development of non threaded php
     trend for development of non‐threaded php
     extensions
• Security 
   – Every php script must be run by the user defined in 
     your httpd.conf. Different scripts all have same non‐
     privileged access creating a security vulnerability
     privileged access creating a security vulnerability
OSS Proliferation
            OSS Proliferation
• The proliferation of open source software has
  The proliferation of open source software has 
  created netrepreneurs and a need: Affordable 
  Performance and Scalability.
  Performance and Scalability
• There are many alternatives now to fill the 
  void left by Apache and mod_php. Today we 
  void left by Apache and mod php Today we
  cover the russian NGINX (engine‐X) httpd
  proxy serving to php‐fpm (forked process 
  proxy serving to php fpm (forked process
  manager) sockets.
What is NGINX?
             What is NGINX?
• Nginx is a lightweight high‐performance
        is a lightweight, high performance 
  reverse proxy load balancer web server
• Best known user is Russian search engine
  Best known user is Russian search engine, 
  rambler.  500,000,000 requests per day
• N i i
  Nginx is asynchronous and event‐driven , 
                 h           d       di
  ‘streaming’, apache is threaded and slower
Performance Comparison
       Performance Comparison
• First, let’s talk  an Apples vs. Apples comparison, 
       ,                 pp         pp       p      ,
  (OS, Hardware & benchmarking tools) both 
  Tested on:
   – Virtual Images: Sun VirtualBox OSE v3 2 8 on debian
     Virtual Images: Sun VirtualBox OSE v3.2.8 on debian‐
     6.0‐unstable guest
   – Intel Core Duo 1.667GHz
   – 1024MB RAM
   – Debian‐5.0‐STABLE, kernel 2.6.26‐2
   – siege 2 66
     siege 2.66
   – ab 2.3
   – wordpress 3.0.1
httpd details
• Apache Image
  Apache Image
  – Apache 2.2.9 mpm‐prefork
  – Php 5 2 6 mod php
          5.2.6 mod_php
  – All installed using .deb packages
• nGINX I
   GINX Image
  – PHP 5.3.3 w/ php‐fpm
  – Nginx/0.7.67
  – Both built from source
Benchmark Test Details
        Benchmark Test Details
• Wireless connection out to router ~50m away 
                                            y
  and back to VM Image. Ping time <1ms
• Tested a medium sized wp‐blog index page with 
  full range of plugins
  full range of plugins enabled
• Siege Tests (3 Tests ea.)
  – 360s Each
    360s Each
  – 3 Concurrency Levels: 15, 40, 90
• ApacheBench Tests (3 Tests ea.)
  – 1000 Requests
  – 3 Concurrency Levels, 15, 40, 90
Siege Test: 15 Concurrent Connections
                    Hits – Mean Response Time (ms) – Hits /sec

       100%

           90%

           80%

           70%

           60%                                                            nginx
           50%                                                            apache

           40%

           30%

           20%

           10%

           0%
                                 hits          response mean   hits/sec

15               apache      nginx
hits                      1076          1558

response 
response
mean                      4.47          2.96
hits/sec                  2.99          4.32
Siege Test: 15 Concurrent Connections
               Total MB Transf rd Shortest  Longest Response
               Total MB Transf’rd – Shortest – Longest Response
      12



      10



       8



       6                                                                                                        apache
                                                                                                                nginx

       4



       2



       0
                     data transferred (MB)
                     data transferred (MB)           shortest response time (ms)
                                                     shortest response time (ms)   longest response time (ms)
                                                                                   longest response time (ms)
15                          apache           nginx

data transferred 
(MB)                           4.19           6.16

shortest response 
shortest response
time (ms)                      3.66           1.05

longest response 
time (ms)                      9.93           5.79
Siege Test: 40 Concurrent Connections
                Hits – Mean Response Time (ms) – Hits /sec
            100%

             90%

             80%

             70%

              60%

              50%
                                                                       nginx
              40%
                                                                       apache
              30%

              20%

               10%

                0%

                                    hits

                                            response mean
40          apache          nginx                           hits/sec

hits                 783            1614

   p
response 
mean (s)             17.4            8.31
hits/s               2.18            4.49
Siege Test: 40 Concurrent Connections
35         Total MB Transf’rd – Shortest – Longest Response
30


25


20
                                                                                                          apache
                                                                                                           p
15                                                                                                        nginx


10


5


0
               data transferred (MB)           shortest response time (ms)   longest response time (ms)

     40           apache      nginx
     data 
     transferred 
     (MB)                 3.05          6.38
     shortest 
     response 
     time (ms)           4.484          2.09
     longest 
     response 
     time (ms)           29.67         11.32
Siege Test: 90 Concurrent Connections
                   Hits – Mean Response Time (ms) – Hits /sec

            100%

            90%

            80%

            70%

            60%                                                       nginx
            50%                                                       apache

            40%

            30%

            20%

            10%

             0%
                            hits           response mean   hits/sec


90          apache      nginx
hits                  10           1635
response 
mean                 8.51          18.79
hits/sec             0.03           4.54
Siege Test: 90 Concurrent Connections
         Total MB Transf’rd – Shortest – Longest Response
 400

 350

 300

 250

 200                                                                                                            apache
                                                                                                                nginx
 150

 100

  50

     0
                    data transferred (MB)            shortest response time (ms)   longest response time (ms)

90                  apache           nginx
data transferred 
(MB)                            0.04          6.47
shortest response 
time (ms)                           0         1.55
                                                                 Apache Image 
                                                                 Apache Image
longest response 
time (ms)                        360         20.82               Crashed!!!!
Apache ….. Come on!
         Apache ….. Come on!
• Apache used so much memory, drove load avg
  beyond 40, here you see mysqld kernel panic
A Quick Word on Virtualized 
               Development
                   l
• Since I’ve been in the RP I easily get frustrated when on a 
  remote ssh developing and my internet or power goes out. 
  Or, I need to work and the venues wifi isn’t working.
   – Use VirtualBox images for ‘local development’
   – Build a standard wordpress image – You can use it over and over 
     again.
   – Edit your local /etc/hosts file to match the intended hostname 
     of the final product; point at the IP of your image.
     of the final product; point at the IP of your image
   – Develop and have fun. 
   – You WILL save time, hair and your health this way. You’ll also be 
     able to get more work done.
     able to get more work done
   – When you’re done then dump your db, tar your wp dir up and 
     scp her over to the target server.
Build nginx from source
         Build nginx from source
• Instructions conf files and init scripts up at
  Instructions , conf files and init scripts up at 
• Dependencies
   – Lib
     Libevent t
   – Init.d script
   – Fastcgi_params.conf
   – Wordpress_params.conf (for clean urls)
   – Debian‐style vhost dir’s /sites‐available /sites‐
     enabled
Build php & php fpm from source
    Build php & php‐fpm from source
•   Cool points about php‐fpm:
     – Can run as many php instances as you want on different ports, users, mem
                           h                             d ff
       limits, timeouts, etc, etc. Each application can have it’s own ‘virtualized’ php
       installation. These php processes are totally de‐coupled from the webserver. 
       This leaves the webserver to do what it does best – SERVE to the appropriate 
       handler.
       handler
•   Dependencies, Instructions , conf files and init scripts up at  
    http://bit.ly/9vkDBA
•   Long story short is
     – Download 5.3.3‐stable, the fpm is built‐in.
     – Use ./configure –help to see all build flags
     – At the end you’re going to want to look over and customize the php‐fpm.conf, 
       p p ,
       php.ini , and build an init.d script
                                         p
          • Php‐fpm.conf
               – Change default log location to your liking
               – Change pid to match your init.d script
               – Tweak the process manager.  Set the ‘harakiri’ process suicide timeout
Install memcached
            Install memcached
• Instructions conf files and init scripts up at
  Instructions , conf files and init scripts up at 
  http://bit.ly/9vkDBA
• Dependencies
   – libmemcached‐0.41
   – sqlite3
       li 3
Optimizations for Wordpress
    Optimizations for Wordpress
• Plugins
  – Quotemarks replacer
     • Disables wptexturize function Saves cpu from constant
       Disables wptexturize function. Saves cpu from constant 
       regex search.
     • http://wordpress.org/extend/plugins/quotmarks‐
       replacer/
  – FlexiCache
     • http://wordpress.org/extend/plugins/flexicache/
     • Use memcached
Common Security Exploits
        Common Security Exploits
•   mysql not behind iptables
           not behind iptables
•   Php internal port not behind iptables
•   ssh allowing password and keyless access
      h ll i             d dk l
•   ssh not on a non‐standard port
Questions
• It’s question & answer time!
  It s question & answer time!
Thank you
              Thank you
• Thank you to the sponsors and to you for
  Thank you to the sponsors and to you for 
     attending WordCamp Philippines.

              • Go get ‘em!

              • ‐Eric Malloy
           • AT
              A‐Team Solution
                      S l ti
       • Revision 0.01 01/10/2010

More Related Content

What's hot

Testing applications with traffic control in containers / Alban Crequy (Kinvolk)
Testing applications with traffic control in containers / Alban Crequy (Kinvolk)Testing applications with traffic control in containers / Alban Crequy (Kinvolk)
Testing applications with traffic control in containers / Alban Crequy (Kinvolk)Ontico
 
실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례John Kim
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on NetscalerMark Hillick
 
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...Ontico
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackMatt Ray
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesSeveralnines
 
Troubleshooting RabbitMQ and services that use it
Troubleshooting RabbitMQ and services that use itTroubleshooting RabbitMQ and services that use it
Troubleshooting RabbitMQ and services that use itMichael Klishin
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Trygve Vea
 
Installation Openstack Swift
Installation Openstack SwiftInstallation Openstack Swift
Installation Openstack Swiftymtech
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기Ji-Woong Choi
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Zabbix
 
Java on Linux for devs and ops
Java on Linux for devs and opsJava on Linux for devs and ops
Java on Linux for devs and opsaragozin
 
Caching the Uncacheable [Long Version]
Caching the Uncacheable [Long Version]Caching the Uncacheable [Long Version]
Caching the Uncacheable [Long Version]Fastly
 
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기NAVER D2
 
Nginx internals
Nginx internalsNginx internals
Nginx internalsliqiang xu
 

What's hot (20)

Testing applications with traffic control in containers / Alban Crequy (Kinvolk)
Testing applications with traffic control in containers / Alban Crequy (Kinvolk)Testing applications with traffic control in containers / Alban Crequy (Kinvolk)
Testing applications with traffic control in containers / Alban Crequy (Kinvolk)
 
Deployment de Rails
Deployment de RailsDeployment de Rails
Deployment de Rails
 
실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례실시간 서비스 플랫폼 개발 사례
실시간 서비스 플랫폼 개발 사례
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on Netscaler
 
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...
Как сделать высоконагруженный сервис, не зная количество нагрузки / Олег Обле...
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
 
How to monitor NGINX
How to monitor NGINXHow to monitor NGINX
How to monitor NGINX
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
 
Troubleshooting RabbitMQ and services that use it
Troubleshooting RabbitMQ and services that use itTroubleshooting RabbitMQ and services that use it
Troubleshooting RabbitMQ and services that use it
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!
 
Installation Openstack Swift
Installation Openstack SwiftInstallation Openstack Swift
Installation Openstack Swift
 
From LAMP to LNNP
From LAMP to LNNPFrom LAMP to LNNP
From LAMP to LNNP
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
 
Java on Linux for devs and ops
Java on Linux for devs and opsJava on Linux for devs and ops
Java on Linux for devs and ops
 
Caching the Uncacheable [Long Version]
Caching the Uncacheable [Long Version]Caching the Uncacheable [Long Version]
Caching the Uncacheable [Long Version]
 
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
 
Nginx internals
Nginx internalsNginx internals
Nginx internals
 

Similar to Optimizing wordpress

Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولefazati
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningGraham Dumpleton
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
Full Stack Load Testing
Full Stack Load Testing Full Stack Load Testing
Full Stack Load Testing Terral R Jordan
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceScyllaDB
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginnerswebhostingguy
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for WindowsFord AntiTrust
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & ScalabilityJoseph Scott
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + MemcachedFord AntiTrust
 
Tuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish CacheTuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish CachePer Buer
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsPerrin Harkins
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp
 

Similar to Optimizing wordpress (20)

Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصول
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Full Stack Load Testing
Full Stack Load Testing Full Stack Load Testing
Full Stack Load Testing
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
 
Velocity 2010 - ATS
Velocity 2010 - ATSVelocity 2010 - ATS
Velocity 2010 - ATS
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
 
Usenix lisa 2011
Usenix lisa 2011Usenix lisa 2011
Usenix lisa 2011
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Nginx
NginxNginx
Nginx
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + Memcached
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
Tuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish CacheTuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish Cache
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
 
Understanding
Understanding Understanding
Understanding
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Optimizing wordpress

  • 1. Optimizing Wordpress/PHP  Optimizing Wordpress/PHP webserver performance and protecting your server from common  security exploits and attacks prepared especially for: WordCamp 2010 Philippines p pp October 2, 2010
  • 2. Target Audience Target Audience • WordCamp Philippines 2010 p pp – Developer Track talks – Netrepreuneurs – VPS U VPS Users • This is Not This is Not – For change‐resistant people – For those afraid of the unix shell – For those on shared hosting – For those looking for a talk on MS IIS or Microsoft  Anything.
  • 3. Why Optimize? Why Optimize? • Visitors Attention span is small. p – Need to load FAST • Google ranks faster loading pages higher than  slow ones l • Be ready to get slashdott’d or digg’d • Save money on server costs Save money on server costs.  • Save sleep and reduce server downtime.  • Offer more value and specialization to your Offer more value and specialization to your  clients. • Increase your lifespan and overall happiness!
  • 4. Serving your PHP: Quick History Serving your PHP: Quick History • The web outgrows CGI ‐> mod php for Apache  e eb outg o s CG od_p p o pac e intro’d around same time as FastCGI (~1995) p g g p • The practice of bundling a single interpreted  instance of php with the httpd became more  prevalent and FastCGI fell to wayside. • For the past 15 yrs Apache has dominated the  Internet’s httpd server landscape. To this day,  57.12% of all sites run on Apache. Addntly,  57 12% of all sites run on Apache Addntly mod_php is the most popular apache module,  running on over 20mm hosts as of 4/2007.  g /
  • 5. mod_php mod php weaknesses • Slow, Fat &Insecure S o , at & secu e • Bloated footprint. – Every httpd process is tied to the mod_p p y p p php interpreter. This means all files, incl. css, js are served  with mod_php tied to httpd. Unnecessary and set  trend for development of non threaded php trend for development of non‐threaded php extensions • Security  – Every php script must be run by the user defined in  your httpd.conf. Different scripts all have same non‐ privileged access creating a security vulnerability privileged access creating a security vulnerability
  • 6. OSS Proliferation OSS Proliferation • The proliferation of open source software has The proliferation of open source software has  created netrepreneurs and a need: Affordable  Performance and Scalability. Performance and Scalability • There are many alternatives now to fill the  void left by Apache and mod_php. Today we  void left by Apache and mod php Today we cover the russian NGINX (engine‐X) httpd proxy serving to php‐fpm (forked process  proxy serving to php fpm (forked process manager) sockets.
  • 7. What is NGINX? What is NGINX? • Nginx is a lightweight high‐performance is a lightweight, high performance  reverse proxy load balancer web server • Best known user is Russian search engine Best known user is Russian search engine,  rambler.  500,000,000 requests per day • N i i Nginx is asynchronous and event‐driven ,  h d di ‘streaming’, apache is threaded and slower
  • 8. Performance Comparison Performance Comparison • First, let’s talk  an Apples vs. Apples comparison,  , pp pp p , (OS, Hardware & benchmarking tools) both  Tested on: – Virtual Images: Sun VirtualBox OSE v3 2 8 on debian Virtual Images: Sun VirtualBox OSE v3.2.8 on debian‐ 6.0‐unstable guest – Intel Core Duo 1.667GHz – 1024MB RAM – Debian‐5.0‐STABLE, kernel 2.6.26‐2 – siege 2 66 siege 2.66 – ab 2.3 – wordpress 3.0.1
  • 9. httpd details • Apache Image Apache Image – Apache 2.2.9 mpm‐prefork – Php 5 2 6 mod php 5.2.6 mod_php – All installed using .deb packages • nGINX I GINX Image – PHP 5.3.3 w/ php‐fpm – Nginx/0.7.67 – Both built from source
  • 10. Benchmark Test Details Benchmark Test Details • Wireless connection out to router ~50m away  y and back to VM Image. Ping time <1ms • Tested a medium sized wp‐blog index page with  full range of plugins full range of plugins enabled • Siege Tests (3 Tests ea.) – 360s Each 360s Each – 3 Concurrency Levels: 15, 40, 90 • ApacheBench Tests (3 Tests ea.) – 1000 Requests – 3 Concurrency Levels, 15, 40, 90
  • 11. Siege Test: 15 Concurrent Connections Hits – Mean Response Time (ms) – Hits /sec 100% 90% 80% 70% 60% nginx 50% apache 40% 30% 20% 10% 0% hits response mean hits/sec 15 apache nginx hits 1076 1558 response  response mean 4.47 2.96 hits/sec 2.99 4.32
  • 12. Siege Test: 15 Concurrent Connections Total MB Transf rd Shortest  Longest Response Total MB Transf’rd – Shortest – Longest Response 12 10 8 6 apache nginx 4 2 0 data transferred (MB) data transferred (MB) shortest response time (ms) shortest response time (ms) longest response time (ms) longest response time (ms) 15 apache nginx data transferred  (MB) 4.19 6.16 shortest response  shortest response time (ms) 3.66 1.05 longest response  time (ms) 9.93 5.79
  • 13. Siege Test: 40 Concurrent Connections Hits – Mean Response Time (ms) – Hits /sec 100% 90% 80% 70% 60% 50% nginx 40% apache 30% 20% 10% 0% hits response mean 40 apache nginx hits/sec hits 783 1614 p response  mean (s) 17.4 8.31 hits/s 2.18 4.49
  • 14. Siege Test: 40 Concurrent Connections 35 Total MB Transf’rd – Shortest – Longest Response 30 25 20 apache p 15 nginx 10 5 0 data transferred (MB) shortest response time (ms) longest response time (ms) 40 apache nginx data  transferred  (MB) 3.05 6.38 shortest  response  time (ms) 4.484 2.09 longest  response  time (ms) 29.67 11.32
  • 15. Siege Test: 90 Concurrent Connections Hits – Mean Response Time (ms) – Hits /sec 100% 90% 80% 70% 60% nginx 50% apache 40% 30% 20% 10% 0% hits response mean hits/sec 90 apache nginx hits 10 1635 response  mean 8.51 18.79 hits/sec 0.03 4.54
  • 16. Siege Test: 90 Concurrent Connections Total MB Transf’rd – Shortest – Longest Response 400 350 300 250 200 apache nginx 150 100 50 0 data transferred (MB) shortest response time (ms) longest response time (ms) 90 apache nginx data transferred  (MB) 0.04 6.47 shortest response  time (ms) 0 1.55 Apache Image  Apache Image longest response  time (ms) 360 20.82 Crashed!!!!
  • 17. Apache ….. Come on! Apache ….. Come on! • Apache used so much memory, drove load avg beyond 40, here you see mysqld kernel panic
  • 18. A Quick Word on Virtualized  Development l • Since I’ve been in the RP I easily get frustrated when on a  remote ssh developing and my internet or power goes out.  Or, I need to work and the venues wifi isn’t working. – Use VirtualBox images for ‘local development’ – Build a standard wordpress image – You can use it over and over  again. – Edit your local /etc/hosts file to match the intended hostname  of the final product; point at the IP of your image. of the final product; point at the IP of your image – Develop and have fun.  – You WILL save time, hair and your health this way. You’ll also be  able to get more work done. able to get more work done – When you’re done then dump your db, tar your wp dir up and  scp her over to the target server.
  • 19. Build nginx from source Build nginx from source • Instructions conf files and init scripts up at Instructions , conf files and init scripts up at  • Dependencies – Lib Libevent t – Init.d script – Fastcgi_params.conf – Wordpress_params.conf (for clean urls) – Debian‐style vhost dir’s /sites‐available /sites‐ enabled
  • 20. Build php & php fpm from source Build php & php‐fpm from source • Cool points about php‐fpm: – Can run as many php instances as you want on different ports, users, mem h d ff limits, timeouts, etc, etc. Each application can have it’s own ‘virtualized’ php installation. These php processes are totally de‐coupled from the webserver.  This leaves the webserver to do what it does best – SERVE to the appropriate  handler. handler • Dependencies, Instructions , conf files and init scripts up at   http://bit.ly/9vkDBA • Long story short is – Download 5.3.3‐stable, the fpm is built‐in. – Use ./configure –help to see all build flags – At the end you’re going to want to look over and customize the php‐fpm.conf,  p p , php.ini , and build an init.d script p • Php‐fpm.conf – Change default log location to your liking – Change pid to match your init.d script – Tweak the process manager.  Set the ‘harakiri’ process suicide timeout
  • 21. Install memcached Install memcached • Instructions conf files and init scripts up at Instructions , conf files and init scripts up at  http://bit.ly/9vkDBA • Dependencies – libmemcached‐0.41 – sqlite3 li 3
  • 22. Optimizations for Wordpress Optimizations for Wordpress • Plugins – Quotemarks replacer • Disables wptexturize function Saves cpu from constant Disables wptexturize function. Saves cpu from constant  regex search. • http://wordpress.org/extend/plugins/quotmarks‐ replacer/ – FlexiCache • http://wordpress.org/extend/plugins/flexicache/ • Use memcached
  • 23. Common Security Exploits Common Security Exploits • mysql not behind iptables not behind iptables • Php internal port not behind iptables • ssh allowing password and keyless access h ll i d dk l • ssh not on a non‐standard port
  • 24. Questions • It’s question & answer time! It s question & answer time!
  • 25. Thank you Thank you • Thank you to the sponsors and to you for Thank you to the sponsors and to you for  attending WordCamp Philippines. • Go get ‘em! • ‐Eric Malloy • AT A‐Team Solution S l ti • Revision 0.01 01/10/2010