Your SlideShare is downloading. ×
0
Declare Independence from your IT department:
SysAdmin skills for PHP developers
Pablo Godel @pgodel - June 29th, 2013
Lon...
- Why SysAdmin Skills
- Introduction to LAMP
- Hosting options
- Linux distributions
- Installing PHP options
- Deploying ...
Who Am I?
⁃ Born in Argentina, living in the US since 1999
⁃ PHP & Symfony developer
⁃ Founder of the original PHP mailing...
Saturday, June 29, 13
Saturday, June 29, 13
⁃ Founded ServerGrove Networks in 2005
⁃ Provider of web hosting specialized in PHP,
Symfony, ZendFramework, MongoDB and o...
Very active open source supporter through code
contributions and usergroups/conference sponsoring
Community is our teacher...
Sysadmin Skills
Who needs them?
Saturday, June 29, 13
Text
IT is busy / Different Priorities
Saturday, June 29, 13
!Rocket Science
Saturday, June 29, 13
Lack of control
Saturday, June 29, 13
Less downtime
Saturday, June 29, 13
Better Performance
Saturday, June 29, 13
What do you prefer?
Saturday, June 29, 13
Or this?
Saturday, June 29, 13
An example...
I     s.
I ’   s  L.
E     Cs ,
...
LAMP
What is
Saturday, June 29, 13
Saturday, June 29, 13
Saturday, June 29, 13
LAMPSaturday, June 29, 13
LAMPSaturday, June 29, 13
LAMPSaturday, June 29, 13
LAMP
Scott Beale
Saturday, June 29, 13
LNMPSaturday, June 29, 13
LNMPSaturday, June 29, 13
LNPPSaturday, June 29, 13
LANMMPPSaturday, June 29, 13
LANMMPP
Why?
Saturday, June 29, 13
Why LANMMPP
Proven
Saturday, June 29, 13
Stable
Why LANMMPP
Saturday, June 29, 13
Secure
Why LANMMPP
Saturday, June 29, 13
Why LANMMPP
Free
Saturday, June 29, 13
Free*
Why LANMMPP
Saturday, June 29, 13
Inexpensive
Why LANMMPP
Saturday, June 29, 13
Easily Available
Why LANMMPP
Saturday, June 29, 13
Hosting Options
Saturday, June 29, 13
Hosting Options
Shared Hosting
- Inexpensive
- Widely available
- Easy to use
- No maintenance
- No updates
- Instant prov...
Hosting Options
Dedicated Servers
- Full control
- No sharing
- Best performance
- Software / Hardware
to specs
- Hard to ...
Hosting Options
Virtual Servers / VPS
- Shared resources
- Software updates
- SysAdmin skills
- Limited/No CP
- Lack of em...
Hosting Options
Virtual Servers / VPS
- Inexpensive
- Widely available
- Choice of OS
- Root access
- Full shell
- Fast pr...
Hosting Options
Cloud Hosting
Depends on implementation
+ -
Saturday, June 29, 13
Hosting Options
Cloud Hosting
Some are a shared hosting
with a fancy new name
Saturday, June 29, 13
Hosting Options
Cloud Hosting
Some are a shared hosting
with a fancy new name
Others let you start small
and scale easily
...
Hosting Options
Cloud Hosting
Some are a shared hosting
with a fancy new name
Others let you start small
and scale easily
...
Hosting Options
Cloud Hosting
Most suffer from some of the
shared hosting problems:
- vendor lock-in
- lack of control
- h...
Hosting Options
Which one to choose?
Saturday, June 29, 13
Hosting Options
Which one to choose?
I T D E P E N D S
Saturday, June 29, 13
Linux Distributions
Saturday, June 29, 13
Distributions
RedHat based
- Fedora
- RedHat Enterprise Linux (RHEL)
- CentOS
- Scientific Linux
Saturday, June 29, 13
Distributions
Debian based
- Debian
- Ubuntu
Saturday, June 29, 13
Distributions
Others
- Gentoo
- Slackware
- OpenSuse
- Archlinux
- any many many more!
http://distrowatch.com/
http://en.w...
Distributions
Key differences
- Configuration files
- Package Manager
- Managing Services
- Software versions
- Updates
Satu...
Distributions
Key differences
- Configuration files
CentOS
Ubuntu
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/network/int...
Distributions
Key differences
- Package Manager
CentOS
Ubuntu
yum install php-cli
apt-get install php5
Saturday, June 29, ...
Distributions
Key differences
- Package Manager
CentOS
Ubuntu
yum search php-cli
apt-cache search php
Saturday, June 29, 13
Distributions
Key differences
- Managing Services
CentOS
Ubuntu
service restart httpd
chkconfig --list httpd
chkconfig htt...
Distributions
Key differences
- Software versions
CentOS
Ubuntu
httpd-2.2.3
apache-2.2.17
Saturday, June 29, 13
Distributions
Key differences
- Updates
CentOS 5.x
Ubuntu 11
PHP 5.1.6
PHP 5.3.5
Saturday, June 29, 13
Distributions
Key similarities
- Based on Linux Kernel
- Screwed up or ancient PHP
- Lack of PHP extensions
Saturday, June...
Distributions
Which one to choose?
I T D E P E N D S
Saturday, June 29, 13
Distributions
Which one to choose?
- Best feeling
- Previous experience
- Workplace selection
- Coworker / friend knowledg...
First Experience
Saturday, June 29, 13
First Experience
- Run Linux natively
- Mac OSX
- Virtual Machine:
- VirtualBox
- Parallels
- VMware
- VPS
Saturday, June ...
First Experience
#!/bin/bash
Saturday, June 29, 13
First Experience
#!/bin/bash
Saturday, June 29, 13
First Experience
#!/bin/bash
Saturday, June 29, 13
First Experience
#!/bin/bash
Saturday, June 29, 13
First Experience
#!/bin/bash
Recommended Books:
- Learning the bash Shell
- bash Cookbook
Saturday, June 29, 13
First Experience
#!/bin/bash
Most Common Commands:
$ ls -l /path/
$ cd /path
$ pwd
$ cat /etc/passwd
$ less /etc/resolv.co...
First Experience
#!/bin/bash
User`s config files:
~/.bash_history
~/.bash_logout
~/.bash_profile
PATH=$PATH:$HOME/bin
expo...
First Experience
#!/bin/bash
Most common directories:
/etc
/tmp
/var/log
/var/run
/root
/home
/usr/local
/opt
Saturday, Ju...
Installing Apache/PHP
Saturday, June 29, 13
Installing Apache/PHP
# CentOS
$ yum install httpd php-cli mod_php
# Ubuntu
$ apt-get install apache2 libapache2-mod-php5
...
Installing PHP
CentOS
Third Party Repositories
- Remi RPM
http://blog.famillecollet.com/
- Webtatic
http://www.webtatic.co...
Installing PHP
CentOS
Third Party Repositories
cd /etc/yum.repos.d/
wget http://repos.servergrove.com/servergrove-centos-5...
Installing PHP
Ubuntu
Third Party Repositories
- Dotdeb:
http://www.dotdeb.org/
- ServerGrove: (always latest)
http://repo...
Installing PHP
Ubuntu
Third Party Repositories
echo “deb http://repos.servergrove.com/servergrove-ubuntu-
precise precise ...
Installing PHP
From Source
wget http://us2.php.net/get/php-5.4.12.tar.bz2/from/
www.php.net/mirror
tar jxvf php-5.4.12.tar...
Installing PHP
Recompiling
php -i |grep configure
./configure '--with-apxs2=/usr/sbin/apxs' '--prefix=/usr/local/
php53' '...
Installing PHP
Compiling for Apache
./configure '--with-apxs2=/usr/sbin/apxs'
make && make install
Saturday, June 29, 13
Installing PHP
Compiling for Nginx / PHP-FPM
./configure '--enable-fpm'
make && make install
Saturday, June 29, 13
Installing PHP
Compiling extension
./configure --with-curl --enable-ftp
make && make install
Saturday, June 29, 13
Installing PHP
Compiling extension
(dynamic)
cd ext/curl
phpize
./configure
make && make install
echo “extension=curl.so” ...
Installing PHP
Compiling extension
http://pecl.php.net/
Saturday, June 29, 13
Installing PHP
Compiling extension
(PECL)
pecl install apc
# or
pecl download apc
tar zxvf APC-3.1.13.tgz
cd APC-3.13
phpi...
Automate!
- Chef
- Puppet
- ...
Installing PHP
Saturday, June 29, 13
Installing PHP
Configuration
/etc/php/php.ini
/etc/php5/cli/php.ini
/usr/local/lib/php.ini
Default location
Other common lo...
Installing PHP
Configuration
php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/php5/lib
Loaded Configurat...
Installing PHP
Configuration
php -i | grep mongo
/usr/local/php5/php.d/50-extension-mongo.ini,
mongo
mongo.allow_empty_keys...
Installing PHP
Configuration
[PHP Modules]
apc
bcmath
bz2
Core
ctype
curl
date
dom
ereg
php -m
Saturday, June 29, 13
Installing PHP
Configuration
php.ini
extension_dir=/usr/lib/php/extensions/no-
debug-non-zts-20090626
extension=apc.so
exte...
Installing PHP
Configuration
php.ini
php -i | grep extension_dir
extension_dir => /usr/local/php5/lib/php/extensions/no-deb...
Installing PHP
Configuration
php.ini
date.timezone=UTC
display_errors = off
log_errors = on
error_log = /var/log/php.log
Sa...
Installing PHP
Configuration
Security
memory_limit = 128M
max_execution_time = 30
display_errors = off
expose_php = off
mai...
Installing PHP
Configuration
File uploads on .htaccess
php_value memory_limit 128M
php_value max_file_uploads 20
php_value m...
Installing PHP
Configuration
Include .htaccess
<Directory /path/to/document/root>
Include /path/to/.htaccess
</Directory>
A...
Installing PHP
Configuration
Apache
php_value date.timezone UTC
php_flag display_errors 1
php_value memory_limit 128M
php_va...
Installing PHP
Web Server User
- apache
- nobody
- www-data
- ftp / ssh user (sometimes)
Possible users
Permissions issues...
Installing PHP
Web Server User
Fix:
Permissions issues with clear cache
and uploads, Anyone?
rm -rf app/cache/*
rm -rf app...
Deploying PHP
Saturday, June 29, 13
Deploying PHP
Before going live
Make sure ntpd is
installed and running
to ensure accurate
server time
yum install ntp
chk...
Deploying PHP
Before going live
- Disable PHP in specific directories
<Location /uploads>
php_admin_flag engine off
</Locat...
Deploying PHP
Before going live
- Limit access by IP
<Location /admin>
Order Deny,Allow
Deny from all
Allow from 1.2.3.4
<...
Deploying PHP
Before going live
- Add HTTP Authentication
<Location /admin>
Require valid-user
AuthType Basic
AuthName "SG...
Deploying PHP
Before going live
- Quiet down Apache
ServerTokens Prod
Saturday, June 29, 13
Deploying PHP
Before going live
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} -f
RewriteR...
Deploying PHP
Before going live
- Case senstive filesystem
IPCheck_Form_Index_Login !=
IpCheck_Form_Index_Login
/path/to/fil...
Deploying PHP
- server-side vi
- plain old FTP
- SFTP
- scp
- rsync + ssh
- git
- tar / gzip
- rpm / deb packages
- capist...
Deploying PHP
- server-side vi
- plain old FTP
- SFTP
- scp
- rsync + ssh
- git
- tar / gzip
- rpm / deb packages
- capist...
Deploying PHP
Effing Package Management
https://github.com/jordansissel/fpm
Build packages for multiple platforms (deb, rpm...
Deploying PHP
Capistrano / Capifony
- multiple servers
- multiple environments
- setup shared folders (vendors, cache, log...
Deploying PHP
Setting up SSH
$ ssh-keygen -t dsa
~/.ssh/id_dsa.pub
$ ssh-copy-id user@remote-host
~/.ssh/authorized_keys
~...
Deploying PHP
Setting up SSH
~/.ssh/config
Host *
ForwardAgent yes
Port 22123
Host gh
HostName github.com
Port 22
Preferred...
Deploying PHP
Setting up SSH
/etc/ssh/sshd_config
Port 22
Port 22123
PermitRootLogin no
PasswordAuthentication no
Saturday,...
Deploying PHP Automate!
https://github.com/pgodel/m-sunshinephp/blob/master/web/deploy.php
<?php
exec('/usr/bin/env -i HOM...
DNS Tips
Saturday, June 29, 13
DNS Tips The Power of the hosts file
Saturday, June 29, 13
/etc/hosts
10.0.1.1 www.lottery.com
DNS Tips The Power of the hosts file
Saturday, June 29, 13
/etc/hosts
10.0.1.1 example1.com example2.com
DNS Tips The Power of the hosts file
Saturday, June 29, 13
DNS Tips
Virtual Document Root
UseCanonicalName Off
VirtualDocumentRoot /var/www/vhosts/%0/web
<Location /var/www/vhosts>
...
DNS Tips
Nameservers/Expiration
whois servergrove.com
...
Name Servers:
ns1.servergrove.com
ns2.servergrove.com
ns3.server...
DNS Tips
DNS records
dig -t A google.com
;; ANSWER SECTION:
google.com. 184 IN A 74.125.230.227
google.com. 184 IN A 74.12...
DNS Tips
DNS records
dig -t A servergrove.eu @ns1.servergrove.com
;; ANSWER SECTION:
servergrove.eu. 3600 IN A 149.5.47.10...
DNS Tips DNS Delegation
http://www.simpledns.com/lookup-dg.aspx
Saturday, June 29, 13
DNS Tips
traceroute
traceroute google.com
traceroute to google.com (173.194.37.33), 30 hops max, 40 byte packets
1 2.69-19...
DNS Tips
http://whereisitup.com
Saturday, June 29, 13
DNS Tips
mtr
Saturday, June 29, 13
Monitoring
Saturday, June 29, 13
Monitoring
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .your_domain.com
<...
Monitoring
Apache Requests
Saturday, June 29, 13
Monitoring
- Cacti
- Ganglia
- Zabbix
- collectd
- statsd / StatsDBundle
- graphite
Saturday, June 29, 13
Monitoring
statsd / StatsDBundle / Graphite
Saturday, June 29, 13
Monitoring
CPU / Memory / IO
top
Saturday, June 29, 13
Monitoring
IO
iotop
Saturday, June 29, 13
Monitoring
Network
iptraf
Saturday, June 29, 13
Monitoring
Handling logs
- Centralize logs with syslog
error_log = syslog
- Monolog supports syslog
- logstash, logster, l...
Monitoring
Handling logs
$ grep POST /var/log/apache2/access_log
Saturday, June 29, 13
Speeding up
Saturday, June 29, 13
Speeding up
- nginx/php-fpm
- APC
- ZendOptimizer+ (Included in PHP 5.5)
- Memcache
- nginx reverse proxy cache
- Varnish
...
Backups
Saturday, June 29, 13
Backups
- rsync
- rdiff-backup
- Unison
- Bacula
- Amanda
Saturday, June 29, 13
Backups
Don’t forget to
backup your DB!
http://blog.servergrove.com/2012/01/24/backup-your-mysql-
database-using-mysqldump...
Reading List
- Automating UNIX and Linux Administration
- Running Linux
- Learning the bash Shell: Unix Shell Programming
...
The End Questions?
Sysadmin skills for PHP developers
Saturday, June 29, 13
http://joind.in/8696
Thank you!
Sysadmin skills for PHP developers
Pablo Godel @pgodel
Saturday, June 29, 13
Upcoming SlideShare
Loading in...5
×

Lone Star PHP 2013 - Sysadmin Skills for PHP Developers

6,685

Published on

A PHP/web developer is not complete without knowing server administration. When looking for a job, it is quite likely that you will be required to know about installing and configuring a LAMP (Linux, Apache, MySQL and PHP). Your prospects of getting that job are much higher when you know these. In this session we will cover: - Introduction to LAMP servers - Frequently used Unix commands - Linux distro Differences - Prepare your LAMP server before going live - Overall LAMP Security - Performance tips to improve your website speed - Compiling PHP from source. Adding PHP extensions. - Basic description of web hosting options for PHP.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,685
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Lone Star PHP 2013 - Sysadmin Skills for PHP Developers"

  1. 1. Declare Independence from your IT department: SysAdmin skills for PHP developers Pablo Godel @pgodel - June 29th, 2013 Lone Star PHP Conference http://joind.in/8696 Saturday, June 29, 13
  2. 2. - Why SysAdmin Skills - Introduction to LAMP - Hosting options - Linux distributions - Installing PHP options - Deploying PHP -Various production tips - Monitoring - Backups Agenda Saturday, June 29, 13
  3. 3. Who Am I? ⁃ Born in Argentina, living in the US since 1999 ⁃ PHP & Symfony developer ⁃ Founder of the original PHP mailing list in spanish ⁃ Parrilla Lover ⁃ Co-founder of ServerGrove Saturday, June 29, 13
  4. 4. Saturday, June 29, 13
  5. 5. Saturday, June 29, 13
  6. 6. ⁃ Founded ServerGrove Networks in 2005 ⁃ Provider of web hosting specialized in PHP, Symfony, ZendFramework, MongoDB and others ⁃ Servers in USA and Europe! ServerGrove! Saturday, June 29, 13
  7. 7. Very active open source supporter through code contributions and usergroups/conference sponsoring Community is our teacher Saturday, June 29, 13
  8. 8. Sysadmin Skills Who needs them? Saturday, June 29, 13
  9. 9. Text IT is busy / Different Priorities Saturday, June 29, 13
  10. 10. !Rocket Science Saturday, June 29, 13
  11. 11. Lack of control Saturday, June 29, 13
  12. 12. Less downtime Saturday, June 29, 13
  13. 13. Better Performance Saturday, June 29, 13
  14. 14. What do you prefer? Saturday, June 29, 13
  15. 15. Or this? Saturday, June 29, 13
  16. 16. An example... I     s. I ’   s  L. E     Cs ,        . Saturday, June 29, 13
  17. 17. LAMP What is Saturday, June 29, 13
  18. 18. Saturday, June 29, 13
  19. 19. Saturday, June 29, 13
  20. 20. LAMPSaturday, June 29, 13
  21. 21. LAMPSaturday, June 29, 13
  22. 22. LAMPSaturday, June 29, 13
  23. 23. LAMP Scott Beale Saturday, June 29, 13
  24. 24. LNMPSaturday, June 29, 13
  25. 25. LNMPSaturday, June 29, 13
  26. 26. LNPPSaturday, June 29, 13
  27. 27. LANMMPPSaturday, June 29, 13
  28. 28. LANMMPP Why? Saturday, June 29, 13
  29. 29. Why LANMMPP Proven Saturday, June 29, 13
  30. 30. Stable Why LANMMPP Saturday, June 29, 13
  31. 31. Secure Why LANMMPP Saturday, June 29, 13
  32. 32. Why LANMMPP Free Saturday, June 29, 13
  33. 33. Free* Why LANMMPP Saturday, June 29, 13
  34. 34. Inexpensive Why LANMMPP Saturday, June 29, 13
  35. 35. Easily Available Why LANMMPP Saturday, June 29, 13
  36. 36. Hosting Options Saturday, June 29, 13
  37. 37. Hosting Options Shared Hosting - Inexpensive - Widely available - Easy to use - No maintenance - No updates - Instant provisioning - DNS/Email services - Shared resources - No/Limited Shell - Many restrictions - No control - Fixed versions - Multitude of CPs + - Saturday, June 29, 13
  38. 38. Hosting Options Dedicated Servers - Full control - No sharing - Best performance - Software / Hardware to specs - Hard to plan - Software updates - SysAdmin skills - Expensive to start - Parts replacements - Control Panel licenses + - Saturday, June 29, 13
  39. 39. Hosting Options Virtual Servers / VPS - Shared resources - Software updates - SysAdmin skills - Limited/No CP - Lack of email - Saturday, June 29, 13
  40. 40. Hosting Options Virtual Servers / VPS - Inexpensive - Widely available - Choice of OS - Root access - Full shell - Fast provisioning - Custom software - Custom configurations - Snapshots - Multiple Envs + + Saturday, June 29, 13
  41. 41. Hosting Options Cloud Hosting Depends on implementation + - Saturday, June 29, 13
  42. 42. Hosting Options Cloud Hosting Some are a shared hosting with a fancy new name Saturday, June 29, 13
  43. 43. Hosting Options Cloud Hosting Some are a shared hosting with a fancy new name Others let you start small and scale easily Saturday, June 29, 13
  44. 44. Hosting Options Cloud Hosting Some are a shared hosting with a fancy new name Others let you start small and scale easily Gets really expensive at scale Saturday, June 29, 13
  45. 45. Hosting Options Cloud Hosting Most suffer from some of the shared hosting problems: - vendor lock-in - lack of control - high learning curve - limited environment Saturday, June 29, 13
  46. 46. Hosting Options Which one to choose? Saturday, June 29, 13
  47. 47. Hosting Options Which one to choose? I T D E P E N D S Saturday, June 29, 13
  48. 48. Linux Distributions Saturday, June 29, 13
  49. 49. Distributions RedHat based - Fedora - RedHat Enterprise Linux (RHEL) - CentOS - Scientific Linux Saturday, June 29, 13
  50. 50. Distributions Debian based - Debian - Ubuntu Saturday, June 29, 13
  51. 51. Distributions Others - Gentoo - Slackware - OpenSuse - Archlinux - any many many more! http://distrowatch.com/ http://en.wikipedia.org/wiki/Linux_distribution Saturday, June 29, 13
  52. 52. Distributions Key differences - Configuration files - Package Manager - Managing Services - Software versions - Updates Saturday, June 29, 13
  53. 53. Distributions Key differences - Configuration files CentOS Ubuntu /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/network/interfaces Saturday, June 29, 13
  54. 54. Distributions Key differences - Package Manager CentOS Ubuntu yum install php-cli apt-get install php5 Saturday, June 29, 13
  55. 55. Distributions Key differences - Package Manager CentOS Ubuntu yum search php-cli apt-cache search php Saturday, June 29, 13
  56. 56. Distributions Key differences - Managing Services CentOS Ubuntu service restart httpd chkconfig --list httpd chkconfig httpd on service restart apache2 sudo update-rc.d apache2 enable Saturday, June 29, 13
  57. 57. Distributions Key differences - Software versions CentOS Ubuntu httpd-2.2.3 apache-2.2.17 Saturday, June 29, 13
  58. 58. Distributions Key differences - Updates CentOS 5.x Ubuntu 11 PHP 5.1.6 PHP 5.3.5 Saturday, June 29, 13
  59. 59. Distributions Key similarities - Based on Linux Kernel - Screwed up or ancient PHP - Lack of PHP extensions Saturday, June 29, 13
  60. 60. Distributions Which one to choose? I T D E P E N D S Saturday, June 29, 13
  61. 61. Distributions Which one to choose? - Best feeling - Previous experience - Workplace selection - Coworker / friend knowledge Saturday, June 29, 13
  62. 62. First Experience Saturday, June 29, 13
  63. 63. First Experience - Run Linux natively - Mac OSX - Virtual Machine: - VirtualBox - Parallels - VMware - VPS Saturday, June 29, 13
  64. 64. First Experience #!/bin/bash Saturday, June 29, 13
  65. 65. First Experience #!/bin/bash Saturday, June 29, 13
  66. 66. First Experience #!/bin/bash Saturday, June 29, 13
  67. 67. First Experience #!/bin/bash Saturday, June 29, 13
  68. 68. First Experience #!/bin/bash Recommended Books: - Learning the bash Shell - bash Cookbook Saturday, June 29, 13
  69. 69. First Experience #!/bin/bash Most Common Commands: $ ls -l /path/ $ cd /path $ pwd $ cat /etc/passwd $ less /etc/resolv.conf $ tail -f /var/log/* $ last $ lastb $ vi /etc/hosts Saturday, June 29, 13
  70. 70. First Experience #!/bin/bash User`s config files: ~/.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, June 29, 13
  71. 71. First Experience #!/bin/bash Most common directories: /etc /tmp /var/log /var/run /root /home /usr/local /opt Saturday, June 29, 13
  72. 72. Installing Apache/PHP Saturday, June 29, 13
  73. 73. Installing Apache/PHP # CentOS $ yum install httpd php-cli mod_php # Ubuntu $ apt-get install apache2 libapache2-mod-php5 Mac OSX - MAMP - Native Apache + Liip PHP installation - Zend Server CE Windows - WAMP - IIS + PHP Saturday, June 29, 13
  74. 74. Installing PHP CentOS Third Party Repositories - Remi RPM http://blog.famillecollet.com/ - Webtatic http://www.webtatic.com/ - ServerGrove: PHP 5.3.x / 5.4.x / 5.5.x (always latest) http://repos.servergrove.com Saturday, June 29, 13
  75. 75. Installing PHP CentOS Third Party Repositories cd /etc/yum.repos.d/ wget http://repos.servergrove.com/servergrove-centos-5/ servergrove-centos-5.repo yum install php53 # or php54 Saturday, June 29, 13
  76. 76. Installing PHP Ubuntu Third Party Repositories - Dotdeb: http://www.dotdeb.org/ - ServerGrove: (always latest) http://repos.servergrove.com PHP 5.3.x / 5.4.x / 5.5.x Saturday, June 29, 13
  77. 77. Installing PHP Ubuntu Third Party Repositories echo “deb http://repos.servergrove.com/servergrove-ubuntu- precise precise main” >> /etc/apt/sources.list.d/ servergrove.list apt-get install php53 # or php54 Saturday, June 29, 13
  78. 78. Installing PHP From Source wget http://us2.php.net/get/php-5.4.12.tar.bz2/from/ www.php.net/mirror tar jxvf php-5.4.12.tar.bz2 cd php-5.4.12 ./configure make && make install Saturday, June 29, 13
  79. 79. Installing PHP Recompiling 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, June 29, 13
  80. 80. Installing PHP Compiling for Apache ./configure '--with-apxs2=/usr/sbin/apxs' make && make install Saturday, June 29, 13
  81. 81. Installing PHP Compiling for Nginx / PHP-FPM ./configure '--enable-fpm' make && make install Saturday, June 29, 13
  82. 82. Installing PHP Compiling extension ./configure --with-curl --enable-ftp make && make install Saturday, June 29, 13
  83. 83. Installing PHP Compiling extension (dynamic) cd ext/curl phpize ./configure make && make install echo “extension=curl.so” >> php.ini Saturday, June 29, 13
  84. 84. Installing PHP Compiling extension http://pecl.php.net/ Saturday, June 29, 13
  85. 85. Installing PHP Compiling extension (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, June 29, 13
  86. 86. Automate! - Chef - Puppet - ... Installing PHP Saturday, June 29, 13
  87. 87. Installing PHP Configuration /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, June 29, 13
  88. 88. Installing PHP Configuration 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, Saturday, June 29, 13
  89. 89. Installing PHP Configuration 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 Saturday, June 29, 13
  90. 90. Installing PHP Configuration [PHP Modules] apc bcmath bz2 Core ctype curl date dom ereg php -m Saturday, June 29, 13
  91. 91. Installing PHP Configuration php.ini extension_dir=/usr/lib/php/extensions/no- debug-non-zts-20090626 extension=apc.so extension=mongo.so Saturday, June 29, 13
  92. 92. Installing PHP Configuration php.ini php -i | grep extension_dir extension_dir => /usr/local/php5/lib/php/extensions/no-debug- non-zts-20090626 Saturday, June 29, 13
  93. 93. Installing PHP Configuration php.ini date.timezone=UTC display_errors = off log_errors = on error_log = /var/log/php.log Saturday, June 29, 13
  94. 94. Installing PHP Configuration Security 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, June 29, 13
  95. 95. Installing PHP Configuration File uploads on .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 in Apache! Saturday, June 29, 13
  96. 96. Installing PHP Configuration Include .htaccess <Directory /path/to/document/root> Include /path/to/.htaccess </Directory> AllowOverride=None in Apache! Saturday, June 29, 13
  97. 97. Installing PHP Configuration Apache php_value date.timezone UTC php_flag display_errors 1 php_value memory_limit 128M php_value max_execution_time 0 Don’t forget to restart Apache Saturday, June 29, 13
  98. 98. Installing PHP Web Server User - apache - nobody - www-data - ftp / ssh user (sometimes) Possible users Permissions issues with clear cache and uploads, Anyone? Saturday, June 29, 13
  99. 99. Installing PHP Web Server User Fix: Permissions issues with clear cache and uploads, Anyone? 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 Saturday, June 29, 13
  100. 100. Deploying PHP Saturday, June 29, 13
  101. 101. Deploying PHP Before going live Make sure ntpd is installed and running to ensure accurate server time yum install ntp chkconfig ntpd on ntpdate pool.ntp.org Saturday, June 29, 13
  102. 102. Deploying PHP Before going live - Disable PHP in specific directories <Location /uploads> php_admin_flag engine off </Location> Saturday, June 29, 13
  103. 103. Deploying PHP Before going live - Limit access by IP <Location /admin> Order Deny,Allow Deny from all Allow from 1.2.3.4 </Location> Saturday, June 29, 13
  104. 104. Deploying PHP Before going live - Add HTTP Authentication <Location /admin> Require valid-user AuthType Basic AuthName "SG" AuthUserFile /path/users </Location> Saturday, June 29, 13
  105. 105. Deploying PHP Before going live - Quiet down Apache ServerTokens Prod Saturday, June 29, 13
  106. 106. Deploying PHP Before going live RewriteEngine On RewriteRule ^.htaccess$ - [F] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^.*$ - [NC,L] RewriteCond %{REQUEST_URI} !^/web/.*$ RewriteRule ^(.*)$ /web/$1 Move document root with .htaccess Saturday, June 29, 13
  107. 107. Deploying PHP Before going live - Case senstive filesystem IPCheck_Form_Index_Login != IpCheck_Form_Index_Login /path/to/file/IpCheck_Form_Index_Login.php <?php class IPCheck_Form_Index_Login { ... Saturday, June 29, 13
  108. 108. Deploying PHP - server-side vi - plain old FTP - SFTP - scp - rsync + ssh - git - tar / gzip - rpm / deb packages - capistrano / capifony Saturday, June 29, 13
  109. 109. Deploying PHP - server-side vi - plain old FTP - SFTP - scp - rsync + ssh - git - tar / gzip - rpm / deb packages - capistrano / capifony Saturday, June 29, 13
  110. 110. Deploying PHP Effing Package Management https://github.com/jordansissel/fpm Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity. 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, June 29, 13
  111. 111. Deploying PHP Capistrano / Capifony - multiple servers - multiple environments - setup shared folders (vendors, cache, logs, etc) - copy files - update vendors - multi versions - rollback - restart apache Saturday, June 29, 13
  112. 112. Deploying PHP Setting up SSH $ ssh-keygen -t dsa ~/.ssh/id_dsa.pub $ ssh-copy-id user@remote-host ~/.ssh/authorized_keys ~/.ssh/authorized_keys2 $ ssh-add Saturday, June 29, 13
  113. 113. Deploying PHP Setting up SSH ~/.ssh/config Host * ForwardAgent yes Port 22123 Host gh HostName github.com Port 22 PreferredAuthentications publickey IdentityFile ~/.ssh/me_rsa Saturday, June 29, 13
  114. 114. Deploying PHP Setting up SSH /etc/ssh/sshd_config Port 22 Port 22123 PermitRootLogin no PasswordAuthentication no Saturday, June 29, 13
  115. 115. Deploying PHP Automate! 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 Saturday, June 29, 13
  116. 116. DNS Tips Saturday, June 29, 13
  117. 117. DNS Tips The Power of the hosts file Saturday, June 29, 13
  118. 118. /etc/hosts 10.0.1.1 www.lottery.com DNS Tips The Power of the hosts file Saturday, June 29, 13
  119. 119. /etc/hosts 10.0.1.1 example1.com example2.com DNS Tips The Power of the hosts file Saturday, June 29, 13
  120. 120. DNS Tips 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, June 29, 13
  121. 121. DNS Tips Nameservers/Expiration 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, June 29, 13
  122. 122. DNS Tips DNS records 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, June 29, 13
  123. 123. DNS Tips DNS records dig -t A servergrove.eu @ns1.servergrove.com ;; ANSWER SECTION: servergrove.eu. 3600 IN A 149.5.47.100 Saturday, June 29, 13
  124. 124. DNS Tips DNS Delegation http://www.simpledns.com/lookup-dg.aspx Saturday, June 29, 13
  125. 125. DNS Tips 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, June 29, 13
  126. 126. DNS Tips http://whereisitup.com Saturday, June 29, 13
  127. 127. DNS Tips mtr Saturday, June 29, 13
  128. 128. Monitoring Saturday, June 29, 13
  129. 129. Monitoring <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from .your_domain.com </Location> ExtendedStatus On Apache Requests Saturday, June 29, 13
  130. 130. Monitoring Apache Requests Saturday, June 29, 13
  131. 131. Monitoring - Cacti - Ganglia - Zabbix - collectd - statsd / StatsDBundle - graphite Saturday, June 29, 13
  132. 132. Monitoring statsd / StatsDBundle / Graphite Saturday, June 29, 13
  133. 133. Monitoring CPU / Memory / IO top Saturday, June 29, 13
  134. 134. Monitoring IO iotop Saturday, June 29, 13
  135. 135. Monitoring Network iptraf Saturday, June 29, 13
  136. 136. Monitoring Handling logs - Centralize logs with syslog error_log = syslog - Monolog supports syslog - logstash, logster, loggly, logio Saturday, June 29, 13
  137. 137. Monitoring Handling logs $ grep POST /var/log/apache2/access_log Saturday, June 29, 13
  138. 138. Speeding up Saturday, June 29, 13
  139. 139. Speeding up - nginx/php-fpm - APC - ZendOptimizer+ (Included in PHP 5.5) - Memcache - nginx reverse proxy cache - Varnish Saturday, June 29, 13
  140. 140. Backups Saturday, June 29, 13
  141. 141. Backups - rsync - rdiff-backup - Unison - Bacula - Amanda Saturday, June 29, 13
  142. 142. Backups Don’t forget to backup your DB! http://blog.servergrove.com/2012/01/24/backup-your-mysql- database-using-mysqldump/ Saturday, June 29, 13
  143. 143. Reading List - Automating UNIX and Linux Administration - Running Linux - Learning the bash Shell: Unix Shell Programming Saturday, June 29, 13
  144. 144. The End Questions? Sysadmin skills for PHP developers Saturday, June 29, 13
  145. 145. http://joind.in/8696 Thank you! Sysadmin skills for PHP developers Pablo Godel @pgodel Saturday, June 29, 13
  1. A particular slide catching your eye?

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

×