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.
Lone Star PHP 2013 - Sysadmin Skills for PHP Developers
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. - 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. 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
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. Very active open source supporter through code
contributions and usergroups/conference sponsoring
Community is our teacher
Saturday, June 29, 13
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. 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
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. 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. 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
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. 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
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. 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. 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. 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. 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. 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
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. 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
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. Deploying PHP
Before going live
- Disable PHP in specific directories
<Location /uploads>
php_admin_flag engine off
</Location>
Saturday, June 29, 13
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. 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
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. 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. 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. 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. 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
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. 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. DNS Tips DNS Delegation
http://www.simpledns.com/lookup-dg.aspx
Saturday, June 29, 13
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