Independizate de tu departamento IT:
Habilidades sysadmin para PHP devs
Pablo Godel @pgodel - 05/Oct/2013
Buenos Aires,Arg...
¿Quién soy?
⁃ Argentino viviendo en Estados Unidos desde 1999
⁃ Desarrollador PHP & Symfony
⁃ Fundador de la primera lista...
Saturday, October 5, 13
Saturday, October 5, 13
⁃ Fundada en 2005
⁃ Proveedor de servicios de hosting especializado en PHP,
Symfony, ZendFramework, y otros
⁃ Servidores e...
La comunidad es nuestra guia
⁃ Muy activos en la comunidad de Open
Source contribuyendo con código o
patrocinando eventos ...
La comunidad es nuestra guia
Saturday, October 5, 13
La comunidad es nuestra guia
Saturday, October 5, 13
Habilidades de
Sysadmin
¿Quién las necesita?
Saturday, October 5, 13
Text
IT está ocupado o con otras prioidades
Saturday, October 5, 13
¡No es “Rocket Science”!
Saturday, October 5, 13
Falta de control
Saturday, October 5, 13
Menos downtime
Saturday, October 5, 13
Mejor Performance
Saturday, October 5, 13
¿Qué preferís?
Saturday, October 5, 13
¿O esto?
Saturday, October 5, 13
Un ejemplo...
I     s.
I ’   s  L.
E     Cs ,
...
LAMP
¿Qué es?
Saturday, October 5, 13
Saturday, October 5, 13
Saturday, October 5, 13
LAMPSaturday, October 5, 13
LAMPSaturday, October 5, 13
LAMPSaturday, October 5, 13
LAMP
Scott Beale
Saturday, October 5, 13
LNMPSaturday, October 5, 13
LNMPSaturday, October 5, 13
LNPPSaturday, October 5, 13
LANMMPPSaturday, October 5, 13
LANMMPP
¿Porqué?
Saturday, October 5, 13
¿Porqué LANMMPP?
Probado
Saturday, October 5, 13
Estable
¿Porqué LANMMPP?
Saturday, October 5, 13
Seguro
¿Porqué LANMMPP?
Saturday, October 5, 13
Gratis
¿Porqué LANMMPP?
Saturday, October 5, 13
Gratis*
¿Porqué LANMMPP?
Saturday, October 5, 13
Bajo costo
¿Porqué LANMMPP?
Saturday, October 5, 13
Fácil de obtener
¿Porqué LANMMPP?
Saturday, October 5, 13
Distros de Linux
Saturday, October 5, 13
Distros
Basadas en RedHat
- Fedora
- RedHat Enterprise Linux (RHEL)
- CentOS
- Scientific Linux
Saturday, October 5, 13
Basadas en Debian
- Debian
- Ubuntu
Distros
Saturday, October 5, 13
Otras
- Gentoo
- Slackware
- OpenSuse
- Archlinux
- y muchas más!
http://distrowatch.com/
http://en.wikipedia.org/wiki/Lin...
Diferencias principales
- Archivos de configuración
- Administración de Paquetes
- Manejo de Servicios
- Versiones de softw...
- Archivos de configuración
CentOS
Ubuntu
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/network/interfaces
Distros
Diferen...
- Administración de Paquetes
CentOS
Ubuntu
yum install php-cli
apt-get install php5
Distros
Diferencias principales
Saturd...
CentOS
Ubuntu
yum search php-cli
apt-cache search php
Distros
Diferencias principales
- Administración de Paquetes
Saturda...
- Administración de Servicios
CentOS
Ubuntu
service restart httpd
chkconfig --list httpd
chkconfig httpd on
service restar...
- Versiones de Software
CentOS
Ubuntu
httpd-2.2.3
apache-2.2.17
Distros
Diferencias principales
Saturday, October 5, 13
- Actualizaciones
CentOS 5.x
Ubuntu 11
PHP 5.1.6
PHP 5.3.5
Distros
Diferencias principales
Saturday, October 5, 13
- Basadas en el kernel de Linux
- PHP desactualizado
- Falta de extensiones de PHP
Distros
Diferencias principales
Saturda...
¿Cuál elegir?
D E P E N D E
Distros
Saturday, October 5, 13
- El que se sienta mejor
- Experiencia previa
- Elegido en el trabajo
- Amigo/compañero de trabajo
con conocimiento
Distro...
Primera Experiencia
Saturday, October 5, 13
- Correr Linux nativamente
- Mac OSX
- Máquina Virtual:
- VirtualBox
- Parallels
- VMware
- VPS
Primera Experiencia
Saturd...
Primera Experiencia
#!/bin/bash
Saturday, October 5, 13
Primera Experiencia
#!/bin/bash
Saturday, October 5, 13
Primera Experiencia
#!/bin/bash
Saturday, October 5, 13
Primera Experiencia
#!/bin/bash
Saturday, October 5, 13
Primera Experiencia
#!/bin/bash
Libros recomendados:
- Learning the bash Shell
- bash Cookbook
Saturday, October 5, 13
Primera Experiencia
#!/bin/bash
Comandos más comunes:
$ ls -l /path/
$ cd /path
$ pwd
$ cat /etc/passwd
$ less /etc/resolv...
Primera Experiencia
#!/bin/bash
Archivos de configuración del usuario:
~/.bash_history
~/.bash_logout
~/.bash_profile
PATH...
Primera Experiencia
#!/bin/bash
Directorios más comunes:
/etc
/tmp
/var/log
/var/run
/root
/home
/usr/local
/opt
Saturday,...
Instalando Apache/PHP
Saturday, October 5, 13
Instalando Apache/PHP
# CentOS
$ yum install httpd php-cli mod_php
# Ubuntu
$ apt-get install apache2 libapache2-mod-php5
...
CentOS
Repositorios de 3ros
- Remi RPM
http://blog.famillecollet.com/
- Webtatic
http://www.webtatic.com/
- ServerGrove: P...
cd /etc/yum.repos.d/
wget http://repos.servergrove.com/servergrove-rhel-6/
servergrove-rhel-6.repo
yum install php55 # or ...
Ubuntu
Repositorios de 3ros
- Dotdeb:
http://www.dotdeb.org/
- ServerGrove: (siempre lo último)
http://repos.servergrove.c...
echo “deb http://repos.servergrove.com/servergrove-ubuntu-
precise precise main” >> /etc/apt/sources.list.d/
servergrove.l...
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 p...
Recompilando
php -i |grep configure
./configure '--with-apxs2=/usr/sbin/apxs' '--prefix=/usr/local/
php53' '--with-config-...
Compilando para Apache
./configure '--with-apxs2=/usr/sbin/apxs'
make && make install
Saturday, October 5, 13
Compilando para
PHP-FPM
./configure '--enable-fpm'
make && make install
Saturday, October 5, 13
Compilando una extensión
./configure --with-curl --enable-ftp
make && make install
Saturday, October 5, 13
cd ext/curl
phpize
./configure
make && make install
echo “extension=curl.so” >> php.ini
Compilando una extensión
(dinámica...
http://pecl.php.net/
Compilando una extensión
Saturday, October 5, 13
Compilando una extensión
(PECL)
pecl install apc
# or
pecl download apc
tar zxvf APC-3.1.13.tgz
cd APC-3.13
phpize
./confi...
Automatizá!
- Chef
- Puppet
- Ansible
Instalando PHP
Saturday, October 5, 13
Configuración
/etc/php/php.ini
/etc/php5/cli/php.ini
/usr/local/lib/php.ini
Default location
Other common locations
/etc/ph...
php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/php5/lib
Loaded Configuration File => /usr/local/php5-...
php -i | grep mongo
/usr/local/php5/php.d/50-extension-mongo.ini,
mongo
mongo.allow_empty_keys => 0 => 0
mongo.allow_persi...
[PHP Modules]
apc
bcmath
bz2
Core
ctype
curl
date
dom
ereg
php -m
Configuración
Saturday, October 5, 13
Configuración
php.ini
extension_dir=/usr/lib/php/extensions/no-
debug-non-zts-20090626
extension=apc.so
extension=mongo.so
...
php -i | grep extension_dir
extension_dir => /usr/local/php5/lib/php/extensions/no-debug-
non-zts-20090626
Configuración
ph...
date.timezone=UTC
display_errors = off
log_errors = on
error_log = /var/log/php.log
Configuración
php.ini
Saturday, October...
Configuración
Seguridad
memory_limit = 128M
max_execution_time = 30
display_errors = off
expose_php = off
mail.log = /var/l...
Configuración
Subida de archivos
con .htaccess
php_value memory_limit 128M
php_value max_file_uploads 20
php_value max_input...
Configuración
Include .htaccess
<Directory /path/to/document/root>
Include /path/to/.htaccess
</Directory>
AllowOverride=No...
Configuración
Apache
php_value date.timezone UTC
php_flag display_errors 1
php_value memory_limit 128M
php_value max_executi...
Usuario del Servidor Web
- apache
- nobody
- www-data
- ftp / ssh user (a veces)
Posibles usuarios
¿Problemas con permisos...
Solución:
rm -rf app/cache/*
rm -rf app/logs/*
sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_in...
Deployando PHP
Saturday, October 5, 13
Antes de salir al aire
Asegurate que ntpd
este instalado y
corriendo
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.or...
- Deshabilitar PHP en lugares específicos
<Location /uploads>
php_admin_flag engine off
</Location>
Antes de salir al aire
...
- Limitar acceso por IP
<Location /admin>
Order Deny,Allow
Deny from all
Allow from 1.2.3.4
</Location>
Antes de salir al ...
- Agregar autenticación HTTP
<Location /admin>
Require valid-user
AuthType Basic
AuthName "SG"
AuthUserFile /path/users
</...
- Callá Apache
ServerTokens Prod
Antes de salir al aire
Saturday, October 5, 13
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteCond %{...
- Mayúsculas/minúsculas
IPCheck_Form_Index_Login !=
IpCheck_Form_Index_Login
/path/to/file/IpCheck_Form_Index_Login.php
<?p...
Effing Package Management
https://github.com/jordansissel/fpm
Crear paquetes para múltiples plataformas (deb, rpm, etc) con...
Capistrano / Capifony
- multiples servidores
- multiples entornos (dev/qa/prod)
- configura directorios compartidos (vendor...
Configurando SSH
$ ssh-keygen -t dsa
~/.ssh/id_dsa.pub
$ ssh-copy-id user@remote-host
~/.ssh/authorized_keys
~/.ssh/authori...
~/.ssh/config
Host *
ForwardAgent yes
Port 22123
Host gh
HostName github.com
Port 22
PreferredAuthentications publickey
Ide...
/etc/ssh/sshd_config
Port 22
Port 22123
PermitRootLogin no
PasswordAuthentication no
Configurando SSH
Saturday, October 5, 13
Automatizá!
https://github.com/pgodel/m-sunshinephp/blob/master/web/deploy.php
<?php
exec('/usr/bin/env -i HOME=/var/
www/...
Tips de DNS
Saturday, October 5, 13
El poder del archivo hosts
Saturday, October 5, 13
/etc/hosts
10.0.1.1 www.lottery.com
El poder del archivo hosts
Saturday, October 5, 13
/etc/hosts
10.0.1.1 example1.com example2.com
El poder del archivo hosts
Saturday, October 5, 13
Virtual Document Root
UseCanonicalName Off
VirtualDocumentRoot /var/www/vhosts/%0/web
<Location /var/www/vhosts>
AllowOver...
Nameservers/Expiración
whois servergrove.com
...
Name Servers:
ns1.servergrove.com
ns2.servergrove.com
ns3.servergrove.com...
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.2...
dig -t A servergrove.eu @ns1.servergrove.com
;; ANSWER SECTION:
servergrove.eu. 3600 IN A 149.5.47.100
Registros DNS
Satur...
Delegación DNS
http://www.simpledns.com/lookup-dg.aspx
Saturday, October 5, 13
traceroute
traceroute google.com
traceroute to google.com (173.194.37.33), 30 hops max, 40 byte packets
1 2.69-195-222.sta...
http://whereisitup.com
Saturday, October 5, 13
mtr
Saturday, October 5, 13
Monitoreo
Saturday, October 5, 13
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .your_domain.com
</Location>
...
Requests de Apache
Saturday, October 5, 13
- Cacti
- Ganglia
- Zabbix
- collectd
- statsd / StatsDBundle
- graphite
Saturday, October 5, 13
statsd / StatsDBundle / Graphite
Saturday, October 5, 13
CPU / Memory / IO
top
Saturday, October 5, 13
IO
iotop
Saturday, October 5, 13
Tráfico de Red
iptraf
Saturday, October 5, 13
$ grep POST /var/log/apache2/access_log
Manejando logs
Saturday, October 5, 13
Manejando logs
- Centralizar logs con syslog
error_log = syslog
- Monolog soporta syslog
- logstash, logster, loggly, logi...
Acelerando
Saturday, October 5, 13
Acelerando
- nginx/php-fpm
- APC (PHP 5.4 y anterior)
- ZendOptimizer+ (incluido in PHP 5.5)
- Memcache
- nginx reverse pr...
Backups
Saturday, October 5, 13
Backups
- rsync
- rdiff-backup
- Unison
- Bacula
- Amanda
Saturday, October 5, 13
Backups
No te olvides de
backupear tu DB!
http://blog.servergrove.com/2012/01/24/backup-your-mysql-
database-using-mysqldu...
Reading List
- Automating UNIX and Linux Administration
- Running Linux
- Learning the bash Shell: Unix Shell Programming
...
The End ¿Preguntas?
Habilidades sysadmin para PHP devs
Saturday, October 5, 13
Gracias!
Habilidades sysadmin para PHP devs
Pablo Godel @pgodel
Saturday, October 5, 13
Upcoming SlideShare
Loading in...5
×

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

8,133

Published on

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.

1 Comment
1 Like
Statistics
Notes
  • http://bhami.com/rosetta.html
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
8,133
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
20
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 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. 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. 3. Saturday, October 5, 13
  4. 4. Saturday, October 5, 13
  5. 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. 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. 7. La comunidad es nuestra guia Saturday, October 5, 13
  8. 8. La comunidad es nuestra guia Saturday, October 5, 13
  9. 9. Habilidades de Sysadmin ¿Quién las necesita? Saturday, October 5, 13
  10. 10. Text IT está ocupado o con otras prioidades Saturday, October 5, 13
  11. 11. ¡No es “Rocket Science”! Saturday, October 5, 13
  12. 12. Falta de control Saturday, October 5, 13
  13. 13. Menos downtime Saturday, October 5, 13
  14. 14. Mejor Performance Saturday, October 5, 13
  15. 15. ¿Qué preferís? Saturday, October 5, 13
  16. 16. ¿O esto? Saturday, October 5, 13
  17. 17. Un ejemplo... I     s. I ’   s  L. E     Cs ,        . Saturday, October 5, 13
  18. 18. LAMP ¿Qué es? Saturday, October 5, 13
  19. 19. Saturday, October 5, 13
  20. 20. Saturday, October 5, 13
  21. 21. LAMPSaturday, October 5, 13
  22. 22. LAMPSaturday, October 5, 13
  23. 23. LAMPSaturday, October 5, 13
  24. 24. LAMP Scott Beale Saturday, October 5, 13
  25. 25. LNMPSaturday, October 5, 13
  26. 26. LNMPSaturday, October 5, 13
  27. 27. LNPPSaturday, October 5, 13
  28. 28. LANMMPPSaturday, October 5, 13
  29. 29. LANMMPP ¿Porqué? Saturday, October 5, 13
  30. 30. ¿Porqué LANMMPP? Probado Saturday, October 5, 13
  31. 31. Estable ¿Porqué LANMMPP? Saturday, October 5, 13
  32. 32. Seguro ¿Porqué LANMMPP? Saturday, October 5, 13
  33. 33. Gratis ¿Porqué LANMMPP? Saturday, October 5, 13
  34. 34. Gratis* ¿Porqué LANMMPP? Saturday, October 5, 13
  35. 35. Bajo costo ¿Porqué LANMMPP? Saturday, October 5, 13
  36. 36. Fácil de obtener ¿Porqué LANMMPP? Saturday, October 5, 13
  37. 37. Distros de Linux Saturday, October 5, 13
  38. 38. Distros Basadas en RedHat - Fedora - RedHat Enterprise Linux (RHEL) - CentOS - Scientific Linux Saturday, October 5, 13
  39. 39. Basadas en Debian - Debian - Ubuntu Distros Saturday, October 5, 13
  40. 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. 41. Diferencias principales - Archivos de configuración - Administración de Paquetes - Manejo de Servicios - Versiones de software - Actualizaciones Distros Saturday, October 5, 13
  42. 42. - Archivos de configuración CentOS Ubuntu /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/network/interfaces Distros Diferencias principales Saturday, October 5, 13
  43. 43. - Administración de Paquetes CentOS Ubuntu yum install php-cli apt-get install php5 Distros Diferencias principales Saturday, October 5, 13
  44. 44. CentOS Ubuntu yum search php-cli apt-cache search php Distros Diferencias principales - Administración de Paquetes Saturday, October 5, 13
  45. 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. 46. - Versiones de Software CentOS Ubuntu httpd-2.2.3 apache-2.2.17 Distros Diferencias principales Saturday, October 5, 13
  47. 47. - Actualizaciones CentOS 5.x Ubuntu 11 PHP 5.1.6 PHP 5.3.5 Distros Diferencias principales Saturday, October 5, 13
  48. 48. - Basadas en el kernel de Linux - PHP desactualizado - Falta de extensiones de PHP Distros Diferencias principales Saturday, October 5, 13
  49. 49. ¿Cuál elegir? D E P E N D E Distros Saturday, October 5, 13
  50. 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. 51. Primera Experiencia Saturday, October 5, 13
  52. 52. - Correr Linux nativamente - Mac OSX - Máquina Virtual: - VirtualBox - Parallels - VMware - VPS Primera Experiencia Saturday, October 5, 13
  53. 53. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  54. 54. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  55. 55. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  56. 56. Primera Experiencia #!/bin/bash Saturday, October 5, 13
  57. 57. Primera Experiencia #!/bin/bash Libros recomendados: - Learning the bash Shell - bash Cookbook Saturday, October 5, 13
  58. 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. 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. 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. 61. Instalando Apache/PHP Saturday, October 5, 13
  62. 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. 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. 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. 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. 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. 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. 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. 69. Compilando para Apache ./configure '--with-apxs2=/usr/sbin/apxs' make && make install Saturday, October 5, 13
  70. 70. Compilando para PHP-FPM ./configure '--enable-fpm' make && make install Saturday, October 5, 13
  71. 71. Compilando una extensión ./configure --with-curl --enable-ftp make && make install Saturday, October 5, 13
  72. 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. 73. http://pecl.php.net/ Compilando una extensión Saturday, October 5, 13
  74. 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. 75. Automatizá! - Chef - Puppet - Ansible Instalando PHP Saturday, October 5, 13
  76. 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. 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. 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. 79. [PHP Modules] apc bcmath bz2 Core ctype curl date dom ereg php -m Configuración Saturday, October 5, 13
  80. 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. 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. 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. 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. 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. 85. Configuración Include .htaccess <Directory /path/to/document/root> Include /path/to/.htaccess </Directory> AllowOverride=None en Apache! Saturday, October 5, 13
  86. 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. 87. Usuario del Servidor Web - apache - nobody - www-data - ftp / ssh user (a veces) Posibles usuarios ¿Problemas con permisos? Saturday, October 5, 13
  88. 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. 89. Deployando PHP Saturday, October 5, 13
  90. 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. 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. 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. 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. 94. - Callá Apache ServerTokens Prod Antes de salir al aire Saturday, October 5, 13
  95. 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. 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. 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. 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. 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. 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. 101. /etc/ssh/sshd_config Port 22 Port 22123 PermitRootLogin no PasswordAuthentication no Configurando SSH Saturday, October 5, 13
  102. 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. 103. Tips de DNS Saturday, October 5, 13
  104. 104. El poder del archivo hosts Saturday, October 5, 13
  105. 105. /etc/hosts 10.0.1.1 www.lottery.com El poder del archivo hosts Saturday, October 5, 13
  106. 106. /etc/hosts 10.0.1.1 example1.com example2.com El poder del archivo hosts Saturday, October 5, 13
  107. 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. 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. 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. 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. 111. Delegación DNS http://www.simpledns.com/lookup-dg.aspx Saturday, October 5, 13
  112. 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. 113. http://whereisitup.com Saturday, October 5, 13
  114. 114. mtr Saturday, October 5, 13
  115. 115. Monitoreo Saturday, October 5, 13
  116. 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. 117. Requests de Apache Saturday, October 5, 13
  118. 118. - Cacti - Ganglia - Zabbix - collectd - statsd / StatsDBundle - graphite Saturday, October 5, 13
  119. 119. statsd / StatsDBundle / Graphite Saturday, October 5, 13
  120. 120. CPU / Memory / IO top Saturday, October 5, 13
  121. 121. IO iotop Saturday, October 5, 13
  122. 122. Tráfico de Red iptraf Saturday, October 5, 13
  123. 123. $ grep POST /var/log/apache2/access_log Manejando logs Saturday, October 5, 13
  124. 124. Manejando logs - Centralizar logs con syslog error_log = syslog - Monolog soporta syslog - logstash, logster, loggly, logio Saturday, October 5, 13
  125. 125. Acelerando Saturday, October 5, 13
  126. 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. 127. Backups Saturday, October 5, 13
  128. 128. Backups - rsync - rdiff-backup - Unison - Bacula - Amanda Saturday, October 5, 13
  129. 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. 130. Reading List - Automating UNIX and Linux Administration - Running Linux - Learning the bash Shell: Unix Shell Programming Saturday, October 5, 13
  131. 131. The End ¿Preguntas? Habilidades sysadmin para PHP devs Saturday, October 5, 13
  132. 132. Gracias! Habilidades sysadmin para PHP devs Pablo Godel @pgodel Saturday, October 5, 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×