A Symfony/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 systtem administration.
Declare independence from your it department sysadmin skills for symfony developers
1. Declare Independence
from your IT department
Sysadmin skills for Symfony developers
June 8, 2012 - Symfony Live Paris
Pablo Godel @pgodel
Friday, June 8, 2012
2. Agenda
- Why SysAdmin Skills
- Introduction to LAMP
- Hosting options
- Linux distributions
- Installing PHP options
- Deploying PHP
- Various production tips
- Monitoring
- Backups
Friday, June 8, 2012
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
⁃ Master of the parrilla
Friday, June 8, 2012
4. Who Am I?
⁃ Born in Argentina, living in the US since 1999
⁃ PHP & Symfony developer
⁃ Founder of the original PHP mailing list in spanish
⁃ Master of the parrilla
Friday, June 8, 2012
6. ServerGrove!
⁃ Founded ServerGrove Networks in 2005
⁃ Provider of web hosting specialized in PHP,
Symfony, ZendFramework, and others
⁃ Now with servers in Europe (and USA)
⁃ Mongohosting.com under beta!
Friday, June 8, 2012
7. Community is our teacher
⁃ Very active open source supporter through code
contributions and usergroups/conference sponsoring
Friday, June 8, 2012
37. Hosting Options
Shared Hosting
+ -
- Inexpensive - Shared resources
- Widely available - No/Limited Shell
- Easy to use - Many restrictions
- No maintenance - No control
- No updates - Fixed versions
- Instant provisioning - Multitude of CPs
- DNS/Email services
Friday, June 8, 2012
38. Hosting Options
Dedicated Servers
+ -
- Full control - Hard to plan
- No sharing - Software updates
- Best performance - SysAdmin skills
- Software / Hardware - Expensive to start
to specs - Parts replacements
- Control Panel licenses
Friday, June 8, 2012
40. Hosting Options
Virtual Servers / VPS
+ +
- Inexpensive - Custom configurations
- Widely available - Snapshots
- Choice of OS - Multiple Envs
- Root access
- Full shell
- Fast provisioning
- Custom software
Friday, June 8, 2012
41. Hosting Options
Cloud Hosting
+ -
Depends on implementation
Friday, June 8, 2012
42. Hosting Options
Cloud Hosting
Some are a shared hosting
with a fancy new name
Friday, June 8, 2012
43. Hosting Options
Cloud Hosting
Some are a shared hosting
with a fancy new name
Others let you start small
and scale easily
Friday, June 8, 2012
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
Friday, June 8, 2012
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
Friday, June 8, 2012
65. Installing PHP
CentOS
Third Party Repositories
- Remi RPM
http://blog.famillecollet.com/
- Webtatic
http://www.webtatic.com/
- ServerGrove: PHP 5.3.13 / 5.4.3
(always latest)
http://repos.servergrove.com
Friday, June 8, 2012
66. 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
Friday, June 8, 2012
68. Installing PHP
Ubuntu
Third Party Repositories
PHP 5.3.13 / 5.4.3
- Dotdeb:
http://www.dotdeb.org/
- ServerGrove: (always latest)
http://repos.servergrove.com
Friday, June 8, 2012
69. Installing PHP
Ubuntu
Third Party Repositories
echo “deb http://repos.servergrove.com/servergrove-ubuntu-
natty natty main” >> /etc/apt/sources.list.d/servergrove.list
apt-get install php53 # or php54
Friday, June 8, 2012
70. Installing PHP
From Source
wget http://us2.php.net/get/php-5.4.3.tar.bz2/from/
www.php.net/mirror
tar jxvf php-5.4.3.tar.bz2
cd php-5.4.3
./configure
make && make install
Friday, June 8, 2012
88. 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
Friday, June 8, 2012
89. Installing PHP
Web Server User
Permissions issues with clear cache
and uploads, Anyone?
Possible users
- apache
- nobody
- www-data
- ftp / ssh user (sometimes)
Friday, June 8, 2012
90. Installing PHP
Web Server User
Permissions issues with clear cache
and uploads, Anyone?
Fix:
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
Friday, June 8, 2012
92. 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
Friday, June 8, 2012
93. Deploying PHP
Before going live
- Limit access by IP
<Location /admin>
Order Deny,Allow
Deny from all
Allow from 1.2.3.4
</Location>
Friday, June 8, 2012
94. Deploying PHP
Before going live
- Add HTTP Authentication
<Location /admin>
Require valid-user
AuthType Basic
AuthName "SG"
AuthUserFile /path/users
</Location>
Friday, June 8, 2012
95. Deploying PHP
Before going live
- Quiet down Apache
ServerTokens Prod
Friday, June 8, 2012
96. Deploying PHP
Before going live
Move document root with .htaccess
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/web/.*$
RewriteRule ^(.*)$ /web/$1
Friday, June 8, 2012
97. 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
{
...
Friday, June 8, 2012
98. Deploying PHP
- server-side vi
- plain old FTP
- SFTP
- scp
- rsync + ssh
- git
- tar / gzip
- rpm / deb packages
- capistrano / capifony
Friday, June 8, 2012
99. Deploying PHP
- server-side vi
- plain old FTP
- SFTP
- scp
- rsync + ssh
- git
- tar / gzip
- rpm / deb packages
- capistrano / capifony
Friday, June 8, 2012
100. Deploying PHP
Effing Package Management
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
https://github.com/jordansissel/fpm
Friday, June 8, 2012
103. DNS Tips
The Power of the hosts file
Friday, June 8, 2012
104. DNS Tips
The Power of the hosts file
/etc/hosts
10.0.1.1 www.lottery.com
Friday, June 8, 2012
105. DNS Tips
The Power of the hosts file
/etc/hosts
10.0.1.1 example1.com example2.com
Friday, June 8, 2012
106. 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
Friday, June 8, 2012
107. 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
Friday, June 8, 2012
108. 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
Friday, June 8, 2012
109. DNS Tips
DNS records
dig -t A servergrove.eu @ns1.servergrove.com
;; ANSWER SECTION:
servergrove.eu. 3600 IN A 149.5.47.100
Friday, June 8, 2012
110. 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
Friday, June 8, 2012
111. DNS Tips
http://whereisitup.com
Friday, June 8, 2012
114. Monitoring
Apache Requests
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .your_domain.com
</Location>
ExtendedStatus On
Friday, June 8, 2012
115. Monitoring
Apache Requests
Friday, June 8, 2012