---

LAMPS 101

Linux

  • Originally a toy
  • Now the basis for all serious computing
    • 3/4 of all smartphones
    • 97% of all supercomputers
    • 66% of all web servers
  • Still kinda sucks for desktop

Official Standards

  • POSIX (IEEE)
  • Linux Standard Base (ISO/IEC 23360)
    • Filesystem Hierarchy Standard

Real Standards

  • Debian
    • Ubuntu
  • Fedora
    • Red Hat
    • CentOS
  • Gentoo
    • Chrome OS
  • Slackware, Mandriva, Arch, SUSE, Etc.

What Linux Is

  • The Linux Kernel
  • The GNU system (i.e. anything useful)
  • Various distribution-based utilities
    • Installer systems: aptitude, yum

Where are all the files?

  • FHS (Filesystem Hierarchy Standard)
  • Single filesystem at /

Where are all the files?

/bin -- for single user mode
/boot -- for boot time
/dev -- device special files
/etc -- system-wide configs
/opt -- add-on packages
/home -- users
/sbin -- system binaries
/lib -- for /bin
/media -- media mounts
/mnt -- temporary mounts
/proc -- proc filesystem
/tmp -- temporary files, per process
/usr -- read-only user data
/usr/bin -- master binaries
/usr/lib -- libraries
/usr/local -- host local data
/var -- variable files, always changing
/var/log -- logs
/var/run -- for running procs, user info
/var/tmp -- will survive reboots
/var/cache -- caches

Where are all the files?

/bin, /usr/bin, /usr/local/bin -- programs to run
/etc -- system-wide configs
/home -- users
/proc -- proc filesystem
/tmp, /var/tmp -- temporary files, per process
/var/log -- logs
/var/run -- for running procs, user info
/opt -- add-on application software

Apache

Apache

  • Preceded by NCSA httpd (CGI)
  • Succeeded by nginx (fastcgi)

Apache

  • The old way: Modules
    • Kept process monolithic
    • No need for IPC

apache1.png

Apache

  • The old way: Modules
    • Kept process monolithic
    • No need for IPC

apache2.png

Apache

  • The old way: Modules
    • Kept process monolithic
    • No need for IPC

apache3.png

Apache

  • The old way: Modules
    • Kept process monolithic
    • No need for IPC
    • "prefork" mode

apache4.png

Apache

  • The new way: proxying
    • nginx popularized this
    • IPC became better
    • Separates web server + application server
    • "worker" mode

Apache

  • The new way: proxying
    • nginx popularized this
    • IPC became better
    • Separates web server + application server
    • "worker" mode

apache5.png

Apache

  • The new way: proxying
    • nginx popularized this
    • IPC became better
    • Separates web server + application server
    • "worker" mode

apache6.png

Apache Configuration

Apache Configuration

  • Set at compile time
  • May be overridden at run time

Apache Configuration

  • Two major layouts in use
    • Debian (Ubuntu)
    • Others (like CentOS)

Apache Configuration

  • CentOS (Fedora Core, RHEL)
ServerRoot              ::      /etc/httpd
Primary Config Fle      ::      /etc/httpd/conf/httpd.conf
Other Config Files      ::      /etc/httpd/conf.d
Module Locations        ::      /usr/lib/httpd/modules
DocumentRoot            ::      /var/www/html
ErrorLog                ::      /var/log/httpd/error_log
AccessLog               ::      /var/log/httpd/access_log
cgi-bin                 ::      /var/www/cgi-bin
                                (empty and disabled by default)
binary                  ::      /usr/sbin/httpd
runtime directory       ::      /etc/httpd/run
start/stop              ::      /sbin/service httpd {start|stop|...}

Apache Configuration

  • Debian/Ubuntu
ServerRoot              ::      /etc/apache2
DocumentRoot            ::      /var/www
Apache Config Files     ::      /etc/apache2/apache2.conf
                        ::      /etc/apache2/ports.conf
Default VHost Config    ::      /etc/apache2/sites-available/default
                        ::      /etc/apache2/sites-enabled/000-default
Module Locations        ::      /etc/apache2/mods-available
                        ::      /etc/apache2/mods-enabled
ErrorLog                ::      /var/log/apache2/error.log
AccessLog               ::      /var/log/apache2/access.log
cgi-bin                 ::      /usr/lib/cgi-bin
binaries (apachectl)    ::      /usr/sbin
start/stop              ::      /etc/init.d/apache2 {start|stop|...}

Apache Configuration

  • Debian/Ubuntu
    • a2ensite and a2dissite
    • a2enmod and a2dismod
    • Manipulate links
a2ensite/a2dissite:
  /etc/apache2/sites-available
  /etc/apache2/sites-enabled

a2enmod/a2dismod:
  /etc/apache2/modules-available
  /etc/apache2/modules-enabled

MySQL

  • Big
  • Gnarly ("nonstandard")
  • Lots of layers
    • Clustering
    • Pluggable backends

MySQL Stuff To Know

  • SQL Injection Attacks
SELECT id FROM users WHERE password=PASSWORD("$password")
  and username="$username";

http://login.com/?username='bob" or 1=1'
SELECT id FROM users WHERE password=PASSWORD("MypaSS3cret")
  and username="bob";

http://login.com/?username='bob" or 1=1'
SELECT id FROM users WHERE password=PASSWORD("MypaSS3cret")
  and username="bob" or 1=1;
  • Prepared queries + variable binding solves this
    • (i.e. no username named 'bob" or 1=1')
  • Lots of libraries fake this – especially in PHP.
  • Very hard to make escaping work

MySQL Stuff to Know

  • ORMs hide SQL details
    • Handy in some ways
    • Deadly in others

PHP

PHP, The New Hotness

  • HHVM
  • JIT, same idea as JVM, V8, etc.
  • Fast, 4x-10x speedup for pure code paths
  • Great for end-game performance optimization
  • Terrible choice to "speed things up"
  • Not exactly PHP
  • Incompatible with a few things

Shell

Shell

  • Not really anything like CMD.EXE
  • Many levels of power use

Unix Shells Through Time

  • Bourne shell
  • C Shell
  • KSH
  • Bash
  • ZSH

ZSH prompt

  • Where you are
  • Various Status items

Completion in ZSH

  • Files
    • Type the first part, hit tab.

Completion in ZSH

  • File search
    • Type any part, hit tab

Completion in ZSH

  • User/host completion

Completion in ZSH

  • Command completion
    • AWS
    • Git (including branch finding)
    • urltools (urlencode/decode)
    • couple hundred more

Oh My ZSH

TCP Ports

TCP Ports

  • 16bit: 0-65536
  • Privileged ports < 1024
  • Every connection takes two ports:
    • Local
    • Remote

TCP Ports

  • 80 and 443 chosen < 1024
  • Also 22
  • MySQL 3306
  • IANA controls these assignments
  • /etc/services has a list

TCP Ports

  • Back-end ports
  • 3000, 8000, 8888
  • Pretty random
  • Conflicts with little-used but registered IANA ports
  • Local significance
  • 8080 is official (http alt)

TCP Ports

  • Every TCP connection has 4 identifers
    • Local host, remote host
    • Local port, remote port
  • Can have multiple connections on single port
    • As long as not all 4 identifiers are the same

TCP Ports

  • Every TCP connection has 4 identifers
  • But not every OS is intelligent about it