PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilidades sysadmin para PHP devs
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilidades sysadmin para PHP devs

on

  • 7,156 views

Un programador PHP/web no está completo sin conocimientos de administración de servidores. Cuando buscas un trabajo, seguramente te encontrarás con el requerimiento de conocimientos para configurar ...

Un programador PHP/web no está completo sin conocimientos de administración de servidores. Cuando buscas un trabajo, seguramente te encontrarás con el requerimiento de conocimientos para configurar un servidor (Linux, Apache, MySQL and PHP). Las posibilidades de que consigas ese trabajo son mayores si conoces sobre servidores.

Statistics

Views

Total Views
7,156
Views on SlideShare
7,044
Embed Views
112

Actions

Likes
1
Downloads
17
Comments
1

2 Embeds 112

https://twitter.com 111
http://kred.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • http://bhami.com/rosetta.html
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilidades sysadmin para PHP devs Presentation Transcript

  • 1. Independizate de tu departamento IT: Habilidades sysadmin para PHP devs Pablo Godel @pgodel - 05/Oct/2013 Buenos Aires,Argentina Saturday, October 5, 13
  • 2. ¿Quién soy? ⁃ Argentino viviendo en Estados Unidos desde 1999 ⁃ Desarrollador PHP & Symfony ⁃ Fundador de la primera lista de discusión de PHP de habla hispana - Socio fundador de ServerGrove ⁃ Amante de la parrilla Saturday, October 5, 13
  • 3. Saturday, October 5, 13
  • 4. Saturday, October 5, 13
  • 5. ⁃ Fundada en 2005 ⁃ Proveedor de servicios de hosting especializado en PHP, Symfony, ZendFramework, y otros ⁃ Servidores en Estados Unidos y Europa ⁃ Work with us! jobs@servergrove.com ServerGrove! Saturday, October 5, 13
  • 6. La comunidad es nuestra guia ⁃ Muy activos en la comunidad de Open Source contribuyendo con código o patrocinando eventos y grupos de usuarios Saturday, October 5, 13
  • 7. La comunidad es nuestra guia Saturday, October 5, 13
  • 8. La comunidad es nuestra guia Saturday, October 5, 13
  • 9. Habilidades de Sysadmin ¿Quién las necesita? Saturday, October 5, 13
  • 10. Text IT está ocupado o con otras prioidades Saturday, October 5, 13
  • 11. ¡No es “Rocket Science”! Saturday, October 5, 13
  • 12. Falta de control Saturday, October 5, 13
  • 13. Menos downtime Saturday, October 5, 13
  • 14. Mejor Performance Saturday, October 5, 13
  • 15. ¿Qué preferís? Saturday, October 5, 13
  • 16. ¿O esto? Saturday, October 5, 13
  • 17. Un ejemplo... I     s. I ’   s  L. E     Cs ,        . Saturday, October 5, 13
  • 18. LAMP ¿Qué es? Saturday, October 5, 13
  • 19. Saturday, October 5, 13
  • 20. Saturday, October 5, 13
  • 21. LAMPSaturday, October 5, 13
  • 22. LAMPSaturday, October 5, 13
  • 23. LAMPSaturday, October 5, 13
  • 24. LAMP Scott Beale Saturday, October 5, 13
  • 25. LNMPSaturday, October 5, 13
  • 26. LNMPSaturday, October 5, 13
  • 27. LNPPSaturday, October 5, 13
  • 28. LANMMPPSaturday, October 5, 13
  • 29. LANMMPP ¿Porqué? Saturday, October 5, 13
  • 30. ¿Porqué LANMMPP? Probado Saturday, October 5, 13
  • 31. Estable ¿Porqué LANMMPP? Saturday, October 5, 13
  • 32. Seguro ¿Porqué LANMMPP? Saturday, October 5, 13
  • 33. Gratis ¿Porqué LANMMPP? Saturday, October 5, 13
  • 34. Gratis* ¿Porqué LANMMPP? Saturday, October 5, 13
  • 35. Bajo costo ¿Porqué LANMMPP? Saturday, October 5, 13
  • 36. Fácil de obtener ¿Porqué LANMMPP? Saturday, October 5, 13
  • 37. Distros de Linux Saturday, October 5, 13
  • 38. Distros Basadas en RedHat - Fedora - RedHat Enterprise Linux (RHEL) - CentOS - Scientific Linux Saturday, October 5, 13
  • 39. Basadas en Debian - Debian - Ubuntu Distros Saturday, October 5, 13
  • 40. Otras - Gentoo - Slackware - OpenSuse - Archlinux - y muchas más! http://distrowatch.com/ http://en.wikipedia.org/wiki/Linux_distribution Distros Saturday, October 5, 13
  • 41. Diferencias principales - Archivos de configuración - Administración de Paquetes - Manejo de Servicios - Versiones de software - Actualizaciones Distros Saturday, October 5, 13
  • 42. - Archivos de configuración CentOS Ubuntu /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/network/interfaces Distros Diferencias principales Saturday, October 5, 13
  • 43. - Administración de Paquetes CentOS Ubuntu yum install php-cli apt-get install php5 Distros Diferencias principales Saturday, October 5, 13
  • 44. CentOS Ubuntu yum search php-cli apt-cache search php Distros Diferencias principales - Administración de Paquetes Saturday, October 5, 13
  • 45. - Administración de Servicios CentOS Ubuntu service restart httpd chkconfig --list httpd chkconfig httpd on service restart apache2 sudo update-rc.d apache2 enable Distros Diferencias principales Saturday, October 5, 13
  • 46. - Versiones de Software CentOS Ubuntu httpd-2.2.3 apache-2.2.17 Distros Diferencias principales Saturday, October 5, 13
  • 47. - Actualizaciones CentOS 5.x Ubuntu 11 PHP 5.1.6 PHP 5.3.5 Distros Diferencias principales Saturday, October 5, 13
  • 48. - Basadas en el kernel de Linux - PHP desactualizado - Falta de extensiones de PHP Distros Diferencias principales Saturday, October 5, 13
  • 49. ¿Cuál elegir? D E P E N D E Distros Saturday, October 5, 13
  • 50. - El que se sienta mejor - Experiencia previa - Elegido en el trabajo - Amigo/compañero de trabajo con conocimiento Distros ¿Cuál elegir? Saturday, October 5, 13
  • 51. Primera Experiencia Saturday, October 5, 13
  • 52. - Correr Linux nativamente - Mac OSX - Máquina Virtual: - VirtualBox - Parallels - VMware - VPS Primera Experiencia Saturday, October 5, 13
  • 53. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  • 54. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  • 55. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  • 56. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  • 57. Primera Experiencia #!/bin/bash Libros recomendados: - Learning the bash Shell - bash Cookbook Saturday, October 5, 13
  • 58. Primera Experiencia #!/bin/bash Comandos más comunes: $ ls -l /path/ $ cd /path $ pwd $ cat /etc/passwd $ less /etc/resolv.conf $ tail -f /var/log/* $ last $ lastb $ vi /etc/hosts Saturday, October 5, 13
  • 59. Primera Experiencia #!/bin/bash Archivos de configuración del usuario: ~/.bash_history ~/.bash_logout ~/.bash_profile PATH=$PATH:$HOME/bin export PATH ~/.bashrc alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' Saturday, October 5, 13
  • 60. Primera Experiencia #!/bin/bash Directorios más comunes: /etc /tmp /var/log /var/run /root /home /usr/local /opt Saturday, October 5, 13
  • 61. Instalando Apache/PHP Saturday, October 5, 13
  • 62. Instalando Apache/PHP # CentOS $ yum install httpd php-cli mod_php # Ubuntu $ apt-get install apache2 libapache2-mod-php5 Mac OSX - MAMP - Apache nativo + instalación de PHP de Liip - Zend Server CE Windows - WAMP - IIS + PHP Saturday, October 5, 13
  • 63. CentOS Repositorios de 3ros - Remi RPM http://blog.famillecollet.com/ - Webtatic http://www.webtatic.com/ - ServerGrove: PHP 5.3.x / 5.4.x / 5.5.x (siempre lo último) http://repos.servergrove.com Saturday, October 5, 13
  • 64. cd /etc/yum.repos.d/ wget http://repos.servergrove.com/servergrove-rhel-6/ servergrove-rhel-6.repo yum install php55 # or php54 CentOS Repositorios de 3ros Saturday, October 5, 13
  • 65. Ubuntu Repositorios de 3ros - Dotdeb: http://www.dotdeb.org/ - ServerGrove: (siempre lo último) http://repos.servergrove.com PHP 5.3.x / 5.4.x / 5.5.x Saturday, October 5, 13
  • 66. echo “deb http://repos.servergrove.com/servergrove-ubuntu- precise precise main” >> /etc/apt/sources.list.d/ servergrove.list apt-get install php53 # or php54 Ubuntu Repositorios de 3ros Saturday, October 5, 13
  • 67. Desde código fuente wget http://us2.php.net/get/php-5.5.4.tar.bz2/from/ www.php.net/mirror tar jxvf php-5.5.4.tar.bz2 cd php-5.5.4 ./configure make && make install Instalando PHP Saturday, October 5, 13
  • 68. Recompilando php -i |grep configure ./configure '--with-apxs2=/usr/sbin/apxs' '--prefix=/usr/local/ php53' '--with-config-file-scan-dir=/etc/php53/conf.d' '-- enable-bcmath' '--enable-ctype' '--enable-exif' '--enable- mbstring' '--enable-ftp' '--enable-intl' '--enable-sockets' '-- enable-sysvmsg' '--enable-pcntl' '--with-bz2' '--with-curl' '-- with-gettext' '--with-gd' '--enable-gd-native-ttf' '--enable-exif' '-- with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-t1lib=/usr' '--with-mcrypt' '--with-openssl' '--with-kerberos' '--with-iconv' '--with-xsl' '--with-xmlrpc' '--with-zlib' '--with-mysql=mysqlnd' '-- with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' make && make install Saturday, October 5, 13
  • 69. Compilando para Apache ./configure '--with-apxs2=/usr/sbin/apxs' make && make install Saturday, October 5, 13
  • 70. Compilando para PHP-FPM ./configure '--enable-fpm' make && make install Saturday, October 5, 13
  • 71. Compilando una extensión ./configure --with-curl --enable-ftp make && make install Saturday, October 5, 13
  • 72. cd ext/curl phpize ./configure make && make install echo “extension=curl.so” >> php.ini Compilando una extensión (dinámicamente) Saturday, October 5, 13
  • 73. http://pecl.php.net/ Compilando una extensión Saturday, October 5, 13
  • 74. Compilando una extensión (PECL) pecl install apc # or pecl download apc tar zxvf APC-3.1.13.tgz cd APC-3.13 phpize ./configure make && make install echo “extension=apc.so” >> php.ini Saturday, October 5, 13
  • 75. Automatizá! - Chef - Puppet - Ansible Instalando PHP Saturday, October 5, 13
  • 76. Configuración /etc/php/php.ini /etc/php5/cli/php.ini /usr/local/lib/php.ini Default location Other common locations /etc/php5/apache2/php.ini Saturday, October 5, 13
  • 77. php -i | grep php.ini Configuration File (php.ini) Path => /usr/local/php5/lib Loaded Configuration File => /usr/local/php5-20110426-093151/ lib/php.ini Scan this dir for additional .ini files => /usr/local/php5/php.d Additional .ini files parsed => /usr/local/php5/php.d/10- extension_dir.ini, Configuración Saturday, October 5, 13
  • 78. php -i | grep mongo /usr/local/php5/php.d/50-extension-mongo.ini, mongo mongo.allow_empty_keys => 0 => 0 mongo.allow_persistent => 1 => 1 mongo.auto_reconnect => 1 => 1 mongo.chunk_size => 262144 => 262144 mongo.cmd => $ => $ mongo.default_host => localhost => localhost mongo.default_port => 27017 => 27017 Configuración Saturday, October 5, 13
  • 79. [PHP Modules] apc bcmath bz2 Core ctype curl date dom ereg php -m Configuración Saturday, October 5, 13
  • 80. Configuración php.ini extension_dir=/usr/lib/php/extensions/no- debug-non-zts-20090626 extension=apc.so extension=mongo.so Saturday, October 5, 13
  • 81. php -i | grep extension_dir extension_dir => /usr/local/php5/lib/php/extensions/no-debug- non-zts-20090626 Configuración php.ini Saturday, October 5, 13
  • 82. date.timezone=UTC display_errors = off log_errors = on error_log = /var/log/php.log Configuración php.ini Saturday, October 5, 13
  • 83. Configuración Seguridad memory_limit = 128M max_execution_time = 30 display_errors = off expose_php = off mail.log = /var/log/phpmails.log disable_functions = exec allow_url_fopen = off Saturday, October 5, 13
  • 84. Configuración Subida de archivos con .htaccess php_value memory_limit 128M php_value max_file_uploads 20 php_value max_input_time -1 php_value post_max_size 8M php_value upload_max_filesize 2M php_value max_execution_time 0 AllowOverride=All en Apache! Saturday, October 5, 13
  • 85. Configuración Include .htaccess <Directory /path/to/document/root> Include /path/to/.htaccess </Directory> AllowOverride=None en Apache! Saturday, October 5, 13
  • 86. Configuración Apache php_value date.timezone UTC php_flag display_errors 1 php_value memory_limit 128M php_value max_execution_time 0 No te olvides de reiniciar Apache Saturday, October 5, 13
  • 87. Usuario del Servidor Web - apache - nobody - www-data - ftp / ssh user (a veces) Posibles usuarios ¿Problemas con permisos? Saturday, October 5, 13
  • 88. Solución: rm -rf app/cache/* rm -rf app/logs/* sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs http://symfony.com/doc/current/book/installation.html ¿Problemas con permisos? Usuario del Servidor Web Saturday, October 5, 13
  • 89. Deployando PHP Saturday, October 5, 13
  • 90. Antes de salir al aire Asegurate que ntpd este instalado y corriendo yum install ntp chkconfig ntpd on ntpdate pool.ntp.org Saturday, October 5, 13
  • 91. - Deshabilitar PHP en lugares específicos <Location /uploads> php_admin_flag engine off </Location> Antes de salir al aire Saturday, October 5, 13
  • 92. - Limitar acceso por IP <Location /admin> Order Deny,Allow Deny from all Allow from 1.2.3.4 </Location> Antes de salir al aire Saturday, October 5, 13
  • 93. - Agregar autenticación HTTP <Location /admin> Require valid-user AuthType Basic AuthName "SG" AuthUserFile /path/users </Location> Antes de salir al aire Saturday, October 5, 13
  • 94. - Callá Apache ServerTokens Prod Antes de salir al aire Saturday, October 5, 13
  • 95. RewriteEngine On RewriteRule ^.htaccess$ - [F] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^.*$ - [NC,L] RewriteCond %{REQUEST_URI} !^/web/.*$ RewriteRule ^(.*)$ /web/$1 Mover document root con .htaccess Antes de salir al aire Saturday, October 5, 13
  • 96. - Mayúsculas/minúsculas IPCheck_Form_Index_Login != IpCheck_Form_Index_Login /path/to/file/IpCheck_Form_Index_Login.php <?php class IPCheck_Form_Index_Login { ... Antes de salir al aire Saturday, October 5, 13
  • 97. Effing Package Management https://github.com/jordansissel/fpm Crear paquetes para múltiples plataformas (deb, rpm, etc) con gran facilidad. fpm -s dir -t rpm -n "sfapp" -v 1.0 /var/www/sfapp fpm -s dir -t deb -a all -n sfapp -v 1.0 /etc/apache2/ conf.d/my.conf /var/www/sfapp Saturday, October 5, 13
  • 98. Capistrano / Capifony - multiples servidores - multiples entornos (dev/qa/prod) - configura directorios compartidos (vendors, cache, logs, etc) - copia archivos - actualiza vendors - multiples versiones - rollback Saturday, October 5, 13
  • 99. Configurando SSH $ ssh-keygen -t dsa ~/.ssh/id_dsa.pub $ ssh-copy-id user@remote-host ~/.ssh/authorized_keys ~/.ssh/authorized_keys2 $ ssh-add Saturday, October 5, 13
  • 100. ~/.ssh/config Host * ForwardAgent yes Port 22123 Host gh HostName github.com Port 22 PreferredAuthentications publickey IdentityFile ~/.ssh/me_rsa Configurando SSH Saturday, October 5, 13
  • 101. /etc/ssh/sshd_config Port 22 Port 22123 PermitRootLogin no PasswordAuthentication no Configurando SSH Saturday, October 5, 13
  • 102. Automatizá! https://github.com/pgodel/m-sunshinephp/blob/master/web/deploy.php <?php exec('/usr/bin/env -i HOME=/var/ www/vhosts/m.sunshinephp.com/m- sunshine git pull origin master'); http://m.sunshinephp.com/deploy.php Deployando PHP Saturday, October 5, 13
  • 103. Tips de DNS Saturday, October 5, 13
  • 104. El poder del archivo hosts Saturday, October 5, 13
  • 105. /etc/hosts 10.0.1.1 www.lottery.com El poder del archivo hosts Saturday, October 5, 13
  • 106. /etc/hosts 10.0.1.1 example1.com example2.com El poder del archivo hosts Saturday, October 5, 13
  • 107. Virtual Document Root UseCanonicalName Off VirtualDocumentRoot /var/www/vhosts/%0/web <Location /var/www/vhosts> AllowOverride All Options +FollowSymLinks </Location> example.com => /var/www/vhosts/example.com/web example2.com => /var/www/vhosts/example2.com/web Saturday, October 5, 13
  • 108. Nameservers/Expiración whois servergrove.com ... Name Servers: ns1.servergrove.com ns2.servergrove.com ns3.servergrove.com Creation date: 19 May 2005 23:34:36 Expiration date: 19 May 2014 23:34:00 Saturday, October 5, 13
  • 109. Registros DNS dig -t A google.com ;; ANSWER SECTION: google.com. 184 IN A 74.125.230.227 google.com. 184 IN A 74.125.230.228 google.com. 184 IN A 74.125.230.229 google.com. 184 IN A 74.125.230.230 google.com. 184 IN A 74.125.230.231 google.com. 184 IN A 74.125.230.232 google.com. 184 IN A 74.125.230.233 google.com. 184 IN A 74.125.230.238 google.com. 184 IN A 74.125.230.224 google.com. 184 IN A 74.125.230.225 google.com. 184 IN A 74.125.230.226 Saturday, October 5, 13
  • 110. dig -t A servergrove.eu @ns1.servergrove.com ;; ANSWER SECTION: servergrove.eu. 3600 IN A 149.5.47.100 Registros DNS Saturday, October 5, 13
  • 111. Delegación DNS http://www.simpledns.com/lookup-dg.aspx Saturday, October 5, 13
  • 112. traceroute traceroute google.com traceroute to google.com (173.194.37.33), 30 hops max, 40 byte packets 1 2.69-195-222.static.servergrove.com (69.195.222.2) 0.360 ms 0.365 ms 0.432 ms 2 t0-1-0-5.br2.mia.terremark.net (66.165.161.45) 1.558 ms 1.546 ms 1.532 ms 3 core1-1-0-0.mia.net.google.com (198.32.124.133) 0.238 ms 0.224 ms 0.230 ms 4 209.85.253.74 (209.85.253.74) 0.266 ms 0.283 ms 0.312 ms 5 209.85.254.252 (209.85.254.252) 12.764 ms 12.757 ms 12.749 ms 6 64.233.175.92 (64.233.175.92) 14.177 ms 14.257 ms 14.359 ms 7 atl14s07-in-f1.1e100.net (173.194.37.33) 13.653 ms 13.606 ms 13.618 ms Saturday, October 5, 13
  • 113. http://whereisitup.com Saturday, October 5, 13
  • 114. mtr Saturday, October 5, 13
  • 115. Monitoreo Saturday, October 5, 13
  • 116. <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from .your_domain.com </Location> ExtendedStatus On Requests de Apache Saturday, October 5, 13
  • 117. Requests de Apache Saturday, October 5, 13
  • 118. - Cacti - Ganglia - Zabbix - collectd - statsd / StatsDBundle - graphite Saturday, October 5, 13
  • 119. statsd / StatsDBundle / Graphite Saturday, October 5, 13
  • 120. CPU / Memory / IO top Saturday, October 5, 13
  • 121. IO iotop Saturday, October 5, 13
  • 122. Tráfico de Red iptraf Saturday, October 5, 13
  • 123. $ grep POST /var/log/apache2/access_log Manejando logs Saturday, October 5, 13
  • 124. Manejando logs - Centralizar logs con syslog error_log = syslog - Monolog soporta syslog - logstash, logster, loggly, logio Saturday, October 5, 13
  • 125. Acelerando Saturday, October 5, 13
  • 126. Acelerando - nginx/php-fpm - APC (PHP 5.4 y anterior) - ZendOptimizer+ (incluido in PHP 5.5) - Memcache - nginx reverse proxy cache - Varnish Saturday, October 5, 13
  • 127. Backups Saturday, October 5, 13
  • 128. Backups - rsync - rdiff-backup - Unison - Bacula - Amanda Saturday, October 5, 13
  • 129. Backups No te olvides de backupear tu DB! http://blog.servergrove.com/2012/01/24/backup-your-mysql- database-using-mysqldump/ Saturday, October 5, 13
  • 130. Reading List - Automating UNIX and Linux Administration - Running Linux - Learning the bash Shell: Unix Shell Programming Saturday, October 5, 13
  • 131. The End ¿Preguntas? Habilidades sysadmin para PHP devs Saturday, October 5, 13
  • 132. Gracias! Habilidades sysadmin para PHP devs Pablo Godel @pgodel Saturday, October 5, 13