• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Deploying PHP applications with Phing
 

Deploying PHP applications with Phing

on

  • 14,124 views

Deploying an application can be tedious and error-prone. Using Phing’s rich set of tasks, easy extension points and simple XML build files to handle the packaging, deploying and testing of your ...

Deploying an application can be tedious and error-prone. Using Phing’s rich set of tasks, easy extension points and simple XML build files to handle the packaging, deploying and testing of your application can help you save time and increase quality. After this talk you will know how to use Phing and how to tailor it to your specific situation. A number of demonstrations will help illustrate transformation, file synchronization, database migration and other real-world use cases.

Statistics

Views

Total Views
14,124
Views on SlideShare
13,517
Embed Views
607

Actions

Likes
16
Downloads
138
Comments
0

7 Embeds 607

http://www.touchdownconsulting.nl 573
http://protalk.me 21
http://www.php-talks.com 6
http://www.scoop.it 3
http://www.linkedin.com 2
http://us-w1.rockmelt.com 1
https://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Deploying PHP applications with Phing Deploying PHP applications with Phing Presentation Transcript

    • Deploying PHP applications with Phing Michiel Rook PHPNW11 - October 8th, 2011 Deploying PHP applications with Phing – 1 / 37
    • About meFreelance PHP/Java consultantPhing project leadhttp://www.linkedin.com/in/michieltcs@michieltcs Deploying PHP applications with Phing – 2 / 37
    • About PhingPHing Is Not GNU make; it’s a PHP project build system or build tool based onApache Ant.Originally developed by BinarycloudPorted to PHP5 by Hans LellelidI joined in 2005 Deploying PHP applications with Phing – 3 / 37
    • FeaturesScripting using XML build filesMostly cross-platformInterface to various popular (PHP) tools Deploying PHP applications with Phing – 4 / 37
    • FeaturesDeploying PHP applications with Phing – 5 / 37
    • InstallationPEAR installation$ pear channel-discover pear.phing.info$ pear install [--alldeps] phing/phingOptionally, install the documentation package$ pear install phing/phingdocs Deploying PHP applications with Phing – 6 / 37
    • Why Use A Build Tool? Deploying PHP applications with Phing – 7 / 37
    • Why Use A Build ToolRepetitive tasks Version control (Unit) Testing Configuring Packaging Uploading DB changes ... Deploying PHP applications with Phing – 8 / 37
    • Why Use A Build ToolFor developers and administratorsAutomate! Easier handover to new team members Improves quality Reduces errors Saves time Deploying PHP applications with Phing – 9 / 37
    • Why Use PhingRich set of tasksIntegration with PHP specific toolsAllows you to stay in the PHP infrastructureEasy to extendEmbed PHP code directly in the build file Deploying PHP applications with Phing – 10 / 37
    • Why Use PhingRich set of tasksIntegration with PHP specific toolsAllows you to stay in the PHP infrastructureEasy to extendEmbed PHP code directly in the build file... in the end, the choice is yours Deploying PHP applications with Phing – 10 / 37
    • The Basics Deploying PHP applications with Phing – 11 / 37
    • Build FilesPhing uses XML build filesContain standard elements Task: code that performs a specific function (svn checkout, mkdir, etc.) Target: groups of tasks, can optionally depend on other targets Project: root node, contains multiple targets Deploying PHP applications with Phing – 12 / 37
    • Example Build File<project name="Example" default="world"> <target name="hello"> <echo>Hello</echo> </target> <target name="world" depends="hello"> <echo>World!</echo> </target></project> Deploying PHP applications with Phing – 13 / 37
    • Properties Simple key-value files (.ini)## build.propertiesversion=1.0 Can be expanded by using ${key} in the build file$ phing -propertyfile build.properties ...<project name="Example" default="default"> <property file="build.properties" /> <target name="default"> <echo>${version}</echo> </target></project> Deploying PHP applications with Phing – 14 / 37
    • File Sets Constructs a group of files to process Supported by most tasks<fileset dir="./application" includes="**"/><fileset dir="./application"> <include name="**/*.php" /> <exclude name="**/*Test.php" /></fileset> Supports references<fileset dir="./application" includes="**" id="files"/><fileset refid="files"/> Deploying PHP applications with Phing – 15 / 37
    • File Sets Selectors allow fine-grained matching on certain attributes contains, date, file name & size, ...<fileset dir="${dist}"> <and> <filename name="**"/> <date datetime="01/01/2011" when="before"/> </and></fileset> Deploying PHP applications with Phing – 16 / 37
    • Mappers and FiltersTransform files during copy/move/...Mappers Change filenameFilters Strip comments, white space Replace values Perform XSLT transformation Translation (i18n) Deploying PHP applications with Phing – 17 / 37
    • Mappers and Filters<copy todir="${build}"> <fileset refid="files"/> <mapper type="glob" from="*.txt" to="*.new.txt"/> <filterchain> <replaceregexp> <regexp pattern="rn" replace="n"/> <expandproperties/> </replaceregexp> </filterchain></copy> Deploying PHP applications with Phing – 18 / 37
    • Practical Examples Deploying PHP applications with Phing – 19 / 37
    • TestingBuilt-in support for PHPUnit / SimpleTestCode coverage through XDebugVarious output formats Deploying PHP applications with Phing – 20 / 37
    • PHPUnit<target name="test"> <coverage-setup database="reports/coverage.db"> <fileset dir="src"> <include name="**/*.php"/> <exclude name="**/*Test.php"/> </fileset> </coverage-setup> <phpunit codecoverage="true"> <formatter type="xml" todir="reports"/> <batchtest> <fileset dir="src"> <include name="**/*Test.php"/> </fileset> </batchtest> </phpunit> <phpunitreport infile="reports/testsuites.xml" format="frames" todir="reports/tests"/> <coverage-report outfile="reports/coverage.xml"> <report todir="reports/coverage" title="Demo"/> </coverage-report></target> Deploying PHP applications with Phing – 21 / 37
    • DocBlox<target name="docs"> <docblox title="Phing API Documentation" output="docs" quiet="true"> <fileset dir="../../classes"> <include name="**/*.php"/> </fileset> </docblox></target> Deploying PHP applications with Phing – 22 / 37
    • Database MigrationDbDeploySet of delta files (SQL)Tracks current version in changelog tableGenerates do & undo scripts Deploying PHP applications with Phing – 23 / 37
    • Database Migration Numbered delta file (1-create-post.sql) Apply & undo statements--//CREATE TABLE ‘post‘ ( ‘title‘ VARCHAR(255), ‘time_created‘ DATETIME, ‘content‘ MEDIUMTEXT);--//@UNDODROP TABLE ‘post‘;--// Deploying PHP applications with Phing – 24 / 37
    • Database Migration<target name="migrate"> <dbdeploy url="sqlite:test.db" dir="deltas" outputfile="deploy.sql" undooutputfile="undo.sql"/> <pdosqlexec src="deploy.sql" url="sqlite:test.db"/></target> Deploying PHP applications with Phing – 25 / 37
    • Packaging Create complete PEAR packages<pearpkg name="demo" dir="."> <fileset refid="files"/> <option name="outputdirectory" value="./build"/> <option name="description">Test package</option> <option name="version" value="0.1.0"/> <option name="state" value="beta"/> <mapping name="maintainers"> <element> <element key="handle" value="test"/> <element key="name" value="Test"/> <element key="email" value="test@test.nl"/> <element key="role" value="lead"/> </element> </mapping></pearpkg> Deploying PHP applications with Phing – 26 / 37
    • Packaging Then build a TAR<tar compression="gzip" destFile="package.tgz" basedir="build"/> ... or ZIP<zip destfile="htmlfiles.zip"> <fileset dir="."> <include name="**/*.html"/> </fileset></zip> Deploying PHP applications with Phing – 27 / 37
    • Deployment SSH<scp username="john" password="smith" host="webserver" todir="/www/htdocs/project/"> <fileset dir="test"> <include name="*.html"/> </fileset></scp> FTP<ftpdeploy host="server01" username="john" password="smit" dir="/var/www"> <fileset dir="."> <include name="*.html"/> </fileset></ftpdeploy> Deploying PHP applications with Phing – 28 / 37
    • Extending Phing Deploying PHP applications with Phing – 29 / 37
    • Extending PhingNumerous extension points Tasks Types Selectors Filters Mappers Loggers ... Deploying PHP applications with Phing – 30 / 37
    • Sample Task<?class SampleTask extends Task{ private $var; public function setVar($v) { $this->var = $v; } public function main() { $this->log("value: " . $this->var); }} Deploying PHP applications with Phing – 31 / 37
    • Sample Task<project name="Example" default="default"> <taskdef name="sample" classpath="/dev/src" classname="tasks.my.SampleTask" /> <target name="default"> <sample var="Hello World" /> </target></project> Deploying PHP applications with Phing – 32 / 37
    • Ad Hoc Extension Define a task within your build file<target name="main"> <adhoc-task name="foo"><![CDATA[ class FooTest extends Task { private $bar; function setBar($bar) { $this->bar = $bar; } function main() { $this->log("In FooTest: " . $this->bar); } } ]]></adhoc-task> <foo bar="TEST"/></target> Deploying PHP applications with Phing – 33 / 37
    • Demo Deploying PHP applications with Phing – 34 / 37
    • More Uses For PhingInstallations and upgradesBootstrapping development environmentsCode analysisVersion control (SVN / GIT)Code encryption / encoding Deploying PHP applications with Phing – 35 / 37
    • More Uses For PhingInstallations and upgradesBootstrapping development environmentsCode analysisVersion control (SVN / GIT)Code encryption / encodingCheck the documentation! Deploying PHP applications with Phing – 35 / 37
    • The FutureImprovements Better performance Increased test coverage Cross-platform compatibility Pain-free installation of dependencies (PHAR?) More documentation IDE support Moving to GitHubWe would love (more) contributions! Deploying PHP applications with Phing – 36 / 37
    • Questions?http://www.phing.infohttp://joind.in/3590 #phing (freenode) @phingofficial Thank you! Deploying PHP applications with Phing – 37 / 37