Tool Up Your LAMP Stack
About Me • Lorna Mitchell • Web Development Consultant • Speaker and Author • Website: http://lornajane.net • Twitter: @lo...
LAMP       3
LAMP • Linux • Apache • MySQL • PHP (or Perl, or Python)                              4
Technology and Agile
Technology is not the     problem                        6
Technology is not the     solution                        7
Technology • We need good tools                        8
Technology • We need good tools • They enable our workflow                             8
Technology • We need good tools • They enable our workflow • They facilitate our achievements                              ...
Technology • We need good tools • They enable our workflow • They facilitate our achievements • They allow us to meet our d...
Technology • We need good tools • They enable our workflow • They facilitate our achievements • They allow us to meet our d...
Iterative Development            develop     deploy                                 9
The Main IngredientsPreparation time: some yearsIngredients:   • Source control   • Development platforms   • Task trackin...
Source Control
Source Control: Key Ingredient  • Central, canonical version  • Collaboration point  • Historical information      • what ...
Source Control Tools  • Subversion http://subversion.apache.org/  • Git http://git-scm.com/  • Mercurial http://mercurial....
Branching StrategiesCommon patterns:  • Feature branches  • Version branches  • Live/integration branches                 ...
Traditional Centralised Source Control                       repo    checkout         checkout            checkout        ...
Distributed Source Control                     repo                            repo              repo                     ...
Database Version ControlNo silver bullet to keep code and database schema in syncStrategies:   • All db changes done via s...
Development Platforms
Development PlatformsRequirements:  • Safe area "sandpit" for developers to work  • All software as-live  • Isolated      ...
Task Tracking
Task TrackingOnce called ’bug tracking’.We can track what status everything is in.                                        ...
Task TrackingOnce called ’bug tracking’.We can track what status everything is in.Developers understand bug trackers, bug ...
Workflow          Backlog    Sprint                     Active          Blocked    Verify                    Complete      ...
Task Tracking Tools  • Pivotal Tracker http://www.pivotaltracker.com/  • GreenHopper   http://www.atlassian.com/software/g...
Automated Testing
How do you test a website           ?                            25
How do you test a website       repeatedly           ?                            26
Automated TestingGives repeatable resultsTDD Test-Driven DevelopmentBDD Behaviour-Driven Development                      ...
Automated Testing Tools • Selenium: browser-based record and play of tests     • Selenium IDE http://seleniumhq.org/projec...
My First Unit Testrequire_once ../src/models/MathUtilModel.php;class MathUtilModelTest extends PHPUnit_Framework_TestCase ...
Running One TestTo run our tests, from the tests directory do:phpunit models/MathUtilModelOutput:PHPUnit 3.5.13 by Sebasti...
Testable Code • Testable code is clean and modular • Need to be able to separate elements to test • Each function does one...
Dependency InjectionPassing things in or looking them up.function getData() {    $db = new MyDatabaseObject();    // sql a...
Code CoverageWhat percentage of your code is tested?  • Summary view  • Drill in to see which lines are run by tests  • Be...
Code Coverage                34
Code Coverage                35
Static Analysis
Static AnalysisEvaluating code without running itAllows us to check for quality, commenting, coding standards             ...
Static Analysis Tools  • PHP Code Sniffer: checks for coding standards      • http://pear.php.net/PHP_CodeSniffer  • PHP M...
phploc Sample Output (joind.in)Directories:                                 32Files:                                      ...
API DocumentationAnother form of static analysis is to generate documentation  • Commented documentation in each file, clas...
API Documentation                    41
PHPCS ExamplesInstall:pear install PHP_CodeSnifferRun:phpcs --standard=PEAR example.phpExamples taken from http://bit.ly/k...
PHPCS ExamplesSource code:class recipe{    protected $_id;    public $name;    public $prep_time;    function getIngredien...
PHPCS ExamplesSniffer output:FILE: /home/lorna/phpcs/recipe.class.php-----------------------------------------------------...
Automated Deployment
Automated Deployment • How many times do you deploy an agile project?                                                    46
Automated Deployment • How many times do you deploy an agile project? • Fast • Hardened • Painless • Repeatable           ...
Automated Deployment Tools • Phing/Ant: easy automated build scripts     • http://phing.info/     • http://ant.apache.org/...
Automating Deployment: Why • Minimise mistakes • Save time on each deploy • Better than documentation • Reliable process -...
Automating Deployment: What • Application code     • minimal downtime or time in an inconsistent state     • easy rollback...
Code Deployment • Get a clean copy of code • Place in new directory on server • Perform any other preparation tasks • Chan...
Config Deployment • Exactly like code deployment • Application needs to be designed with this in mind     • Default to live...
Phing Example<?xml version="1.0" encoding="UTF-8"?><project name="example" basedir="." default="deploy">        <property ...
Phing Example Cont’d        <target name="clean">                <delete dir="${builddir}" />        </target>        <tar...
Continuous Integration
Continuous IntegrationThe glue that holds everything together!   • Source control commit triggers:       • Static analysis...
Continuous Integration Tools  • Jenkins (née Hudson)      • http://jenkins-ci.org/  • PHPUnderControl (PHP-specific CruiseC...
Tool Up Your LAMP Stack
The Main Ingredients for LAMPPreparation time: some yearsIngredients:   • Source control   • Development platforms   • Tas...
Questions?
Thanks • Website: http://lornajane.net • Twitter: @lornajane                                   60
Image Credits • LAMP http://www.flickr.com/photos/sewpixie/2059308961 • Sandpit   http://www.flickr.com/photos/giltastic/3...
Upcoming SlideShare
Loading in...5
×

Tool Up Your LAMP Stack

4,862

Published on

Presentation from Agile on the Beach covering some tools to use with your lamp stack to Get Things Done!

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,862
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
34
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Tool Up Your LAMP Stack

  1. 1. Tool Up Your LAMP Stack
  2. 2. About Me • Lorna Mitchell • Web Development Consultant • Speaker and Author • Website: http://lornajane.net • Twitter: @lornajane 2
  3. 3. LAMP 3
  4. 4. LAMP • Linux • Apache • MySQL • PHP (or Perl, or Python) 4
  5. 5. Technology and Agile
  6. 6. Technology is not the problem 6
  7. 7. Technology is not the solution 7
  8. 8. Technology • We need good tools 8
  9. 9. Technology • We need good tools • They enable our workflow 8
  10. 10. Technology • We need good tools • They enable our workflow • They facilitate our achievements 8
  11. 11. Technology • We need good tools • They enable our workflow • They facilitate our achievements • They allow us to meet our deadlines 8
  12. 12. Technology • We need good tools • They enable our workflow • They facilitate our achievements • They allow us to meet our deadlines • They are not the silver bullet (sorry) 8
  13. 13. Iterative Development develop deploy 9
  14. 14. The Main IngredientsPreparation time: some yearsIngredients: • Source control • Development platforms • Task tracking • Automated testing • Static analysis • Automated deployment • Continuous integration 10
  15. 15. Source Control
  16. 16. Source Control: Key Ingredient • Central, canonical version • Collaboration point • Historical information • what changed • when • by whom • Can include its own config 12
  17. 17. Source Control Tools • Subversion http://subversion.apache.org/ • Git http://git-scm.com/ • Mercurial http://mercurial.selenic.com/ 13
  18. 18. Branching StrategiesCommon patterns: • Feature branches • Version branches • Live/integration branches 14
  19. 19. Traditional Centralised Source Control repo checkout checkout checkout 15
  20. 20. Distributed Source Control repo repo repo repo repo 16
  21. 21. Database Version ControlNo silver bullet to keep code and database schema in syncStrategies: • All db changes done via script • Scripts are numbered • Database knows what numbers it already hasTools: • homespun scripts • DbDeploy http://dbdeploy.com/ • Liquibase http://www.liquibase.org/ 17
  22. 22. Development Platforms
  23. 23. Development PlatformsRequirements: • Safe area "sandpit" for developers to work • All software as-live • Isolated 19
  24. 24. Task Tracking
  25. 25. Task TrackingOnce called ’bug tracking’.We can track what status everything is in. 21
  26. 26. Task TrackingOnce called ’bug tracking’.We can track what status everything is in.Developers understand bug trackers, bug trackers understand yourworkflow. 21
  27. 27. Workflow Backlog Sprint Active Blocked Verify Complete 22
  28. 28. Task Tracking Tools • Pivotal Tracker http://www.pivotaltracker.com/ • GreenHopper http://www.atlassian.com/software/greenhopper/ • Trac http://trac.edgewall.org/ 23
  29. 29. Automated Testing
  30. 30. How do you test a website ? 25
  31. 31. How do you test a website repeatedly ? 26
  32. 32. Automated TestingGives repeatable resultsTDD Test-Driven DevelopmentBDD Behaviour-Driven Development 27
  33. 33. Automated Testing Tools • Selenium: browser-based record and play of tests • Selenium IDE http://seleniumhq.org/projects/ide/ • Selenium RC http://seleniumhq.org/projects/remote-control/ • PHPUnit: unit testing and automation • http://phpunit.de • Also generates code coverage graphs 28
  34. 34. My First Unit Testrequire_once ../src/models/MathUtilModel.php;class MathUtilModelTest extends PHPUnit_Framework_TestCase { public function testAddNumbersWithNumbers() { $util = new MathUtilModel(); $result = $util->addNumbers(3,5); $this->assertEquals(8, $result); }} 29
  35. 35. Running One TestTo run our tests, from the tests directory do:phpunit models/MathUtilModelOutput:PHPUnit 3.5.13 by Sebastian Bergmann..Time: 0 seconds, Memory: 3.00MbOK (1 test, 1 assertion) 30
  36. 36. Testable Code • Testable code is clean and modular • Need to be able to separate elements to test • Each function does one thing • Not too many paths through the code • Dependencies are dangerous 31
  37. 37. Dependency InjectionPassing things in or looking them up.function getData() { $db = new MyDatabaseObject(); // sql and query}function getData($db) { // sql and query} 32
  38. 38. Code CoverageWhat percentage of your code is tested? • Summary view • Drill in to see which lines are run by tests • Beware: 100% code coverage does not mean fully testedUse phpunit -coverage-html and specify where PHPUnit shouldwrite the report filesExamples from http://jenkins.joind.in 33
  39. 39. Code Coverage 34
  40. 40. Code Coverage 35
  41. 41. Static Analysis
  42. 42. Static AnalysisEvaluating code without running itAllows us to check for quality, commenting, coding standards 37
  43. 43. Static Analysis Tools • PHP Code Sniffer: checks for coding standards • http://pear.php.net/PHP_CodeSniffer • PHP Mess Detector: detects ’bad smells’ • http://phpmd.org/ • PHP Lines of Code: project size, class count • https://github.com/sebastianbergmann/phploc 38
  44. 44. phploc Sample Output (joind.in)Directories: 32Files: 213Lines of Code (LOC): 21339 Cyclomatic Complexity / Lines of Code: 0.10Comment Lines of Code (CLOC): 4908Non-Comment Lines of Code (NCLOC): 16431Namespaces: 0Interfaces: 0Classes: 87 Abstract: 1 (1.15%) Concrete: 86 (98.85%) Average Class Length (NCLOC): 116Methods: 532 Scope: Non-Static: 532 (100.00%) Static: 0 (0.00%) Visibility: Public: 501 (94.17%) Non-Public: 31 (5.83%) Average Method Length (NCLOC): 18 39
  45. 45. API DocumentationAnother form of static analysis is to generate documentation • Commented documentation in each file, class, function • Automatically generate into readable documents • Tools: • PHPDocumentor http://www.phpdoc.org/ • DocBlox http://www.docblox-project.org/ 40
  46. 46. API Documentation 41
  47. 47. PHPCS ExamplesInstall:pear install PHP_CodeSnifferRun:phpcs --standard=PEAR example.phpExamples taken from http://bit.ly/kedQrU 42
  48. 48. PHPCS ExamplesSource code:class recipe{ protected $_id; public $name; public $prep_time; function getIngredients() { $ingredients = Ingredients::fetchAllById($this->_id); return $ingredients; }} 43
  49. 49. PHPCS ExamplesSniffer output:FILE: /home/lorna/phpcs/recipe.class.php----------------------------------------------------------------------FOUND 8 ERROR(S) AND 0 WARNING(S) AFFECTING 5 LINE(S)---------------------------------------------------------------------- 2 | ERROR | Missing file doc comment 3 | ERROR | Class name must begin with a capital letter 3 | ERROR | Missing class doc comment 6 | ERROR | Protected member variable "_id" must not be prefixed wit | | underscore 12 | ERROR | Missing function doc comment 12 | ERROR | Opening brace should be on a new line 13 | ERROR | Line indented incorrectly; expected at least 8 spaces, f 13 | ERROR | Spaces must be used to indent lines; tabs are not allowe---------------------------------------------------------------------- 44
  50. 50. Automated Deployment
  51. 51. Automated Deployment • How many times do you deploy an agile project? 46
  52. 52. Automated Deployment • How many times do you deploy an agile project? • Fast • Hardened • Painless • Repeatable 46
  53. 53. Automated Deployment Tools • Phing/Ant: easy automated build scripts • http://phing.info/ • http://ant.apache.org/ • Capistrano (or Webistrano): scripted releases (with web interface) • https://github.com/capistrano/capistrano 47
  54. 54. Automating Deployment: Why • Minimise mistakes • Save time on each deploy • Better than documentation • Reliable process - use for different platforms • Scope for rollback 48
  55. 55. Automating Deployment: What • Application code • minimal downtime or time in an inconsistent state • easy rollback • additional setup steps (upload files, etc) also automated • Database • apply database patches • include rollback patches • Config changes • useful for large or complex sites • config deploys separately, can update quickly and easily 49
  56. 56. Code Deployment • Get a clean copy of code • Place in new directory on server • Perform any other preparation tasks • Change symlink in web directory to point to new version • Tools: shell script or ant/phing 50
  57. 57. Config Deployment • Exactly like code deployment • Application needs to be designed with this in mind • Default to live config • Environment variables set in vhost 51
  58. 58. Phing Example<?xml version="1.0" encoding="UTF-8"?><project name="example" basedir="." default="deploy"> <property name="builddir" value="./build" /> <property name="appdir" value="./build/code" /> <tstamp><format property="date" pattern="%Y%m%d-%H%M" /></tsta <target name="deploy" depends="clean, prepare, export, putlive <target name="export"> <exec command="svn export ${repo} ${appdir}/${date}" /> </target> <target name="putlive"> <exec command="scp -r ${appdir}/${date} ${destination} > ${builddir}/logs/scp.log" /> </target> 52
  59. 59. Phing Example Cont’d <target name="clean"> <delete dir="${builddir}" /> </target> <target name="prepare"> <mkdir dir="${builddir}" /> <mkdir dir="${builddir}/logs" /> </target></project>Phing can also handle upload directories, database versioning, otherdeployment recipe steps and post deploy tasks 53
  60. 60. Continuous Integration
  61. 61. Continuous IntegrationThe glue that holds everything together! • Source control commit triggers: • Static analysis tools • Automated tests • Document generation • CI system centralises: • Deployment (to various platforms) • Other tasks, cron jobs • Centralised dashboard and reporting 55
  62. 62. Continuous Integration Tools • Jenkins (née Hudson) • http://jenkins-ci.org/ • PHPUnderControl (PHP-specific CruiseControl project) • http://phpundercontrol.org/ 56
  63. 63. Tool Up Your LAMP Stack
  64. 64. The Main Ingredients for LAMPPreparation time: some yearsIngredients: • Source control • Development platforms • Task tracking • Automated testing • Static analysis • Automated deployment • Continuous integration 58
  65. 65. Questions?
  66. 66. Thanks • Website: http://lornajane.net • Twitter: @lornajane 60
  67. 67. Image Credits • LAMP http://www.flickr.com/photos/sewpixie/2059308961 • Sandpit http://www.flickr.com/photos/giltastic/3159081924 61
  1. A particular slide catching your eye?

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

×