Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Deploying PHP applications with Phing




                                       Michiel Rook

                   PHPNW11 ...
About me


Freelance PHP/Java consultant

Phing project lead

http://www.linkedin.com/in/michieltcs

@michieltcs




     ...
About Phing


PHing Is Not GNU make; it’s a PHP project build system or build tool based on
Apache Ant.

Originally develo...
Features


Scripting using XML build files

Mostly cross-platform

Interface to various popular (PHP) tools




           ...
Features




Deploying PHP applications with Phing – 5 / 37
Installation


PEAR installation

$ pear channel-discover pear.phing.info
$ pear install [--alldeps] phing/phing

Optional...
Why Use A Build Tool?




                        Deploying PHP applications with Phing – 7 / 37
Why Use A Build Tool


Repetitive tasks

     Version control
     (Unit) Testing
     Configuring
     Packaging
     Uplo...
Why Use A Build Tool


For developers and administrators

Automate!

     Easier handover to new team members
     Improve...
Why Use Phing


Rich set of tasks

Integration with PHP specific tools

Allows you to stay in the PHP infrastructure

Easy ...
Why Use Phing


Rich set of tasks

Integration with PHP specific tools

Allows you to stay in the PHP infrastructure

Easy ...
The Basics




             Deploying PHP applications with Phing – 11 / 37
Build Files


Phing uses XML build files

Contain standard elements

     Task: code that performs a specific function (svn ...
Example Build File


<project name="Example" default="world">
    <target name="hello">
        <echo>Hello</echo>
    </t...
Properties


 Simple key-value files (.ini)

## build.properties
version=1.0

 Can be expanded by using ${key} in the build...
File Sets


 Constructs a group of files to process

 Supported by most tasks

<fileset dir="./application" includes="**"/>...
File Sets


 Selectors allow fine-grained matching on certain attributes

 contains, date, file name & size, ...

<fileset d...
Mappers and Filters


Transform files during copy/move/...

Mappers

      Change filename

Filters

      Strip comments, w...
Mappers and Filters


<copy todir="${build}">
    <fileset refid="files"/>
    <mapper type="glob" from="*.txt" to="*.new....
Practical Examples




                     Deploying PHP applications with Phing – 19 / 37
Testing


Built-in support for PHPUnit / SimpleTest

Code coverage through XDebug

Various output formats




            ...
PHPUnit


<target name="test">
    <coverage-setup database="reports/coverage.db">
        <fileset dir="src">
           ...
DocBlox


<target name="docs">
    <docblox title="Phing API Documentation"
        output="docs" quiet="true">
        <f...
Database Migration


DbDeploy

Set of delta files (SQL)

Tracks current version in changelog table

Generates do & undo scr...
Database Migration


 Numbered delta file (1-create-post.sql)

 Apply & undo statements

--//

CREATE TABLE ‘post‘ (
    ‘t...
Database Migration


<target name="migrate">
    <dbdeploy
        url="sqlite:test.db"
        dir="deltas"
        outpu...
Packaging


 Create complete PEAR packages

<pearpkg name="demo" dir=".">
    <fileset refid="files"/>

   <option   name=...
Packaging


 Then build a TAR

<tar compression="gzip" destFile="package.tgz"
    basedir="build"/>

 ... or ZIP

<zip des...
Deployment


 SSH

<scp username="john" password="smith"
    host="webserver" todir="/www/htdocs/project/">
    <fileset d...
Extending Phing




                  Deploying PHP applications with Phing – 29 / 37
Extending Phing


Numerous extension points

    Tasks
    Types
    Selectors
    Filters
    Mappers
    Loggers
    ......
Sample Task


<?

class SampleTask extends Task
{
    private $var;

     public function setVar($v)
     {
         $this...
Sample Task


<project name="Example" default="default">
    <taskdef name="sample"
        classpath="/dev/src"
        c...
Ad Hoc Extension


 Define a task within your build file

<target name="main">
    <adhoc-task name="foo"><![CDATA[
    clas...
Demo




       Deploying PHP applications with Phing – 34 / 37
More Uses For Phing


Installations and upgrades

Bootstrapping development environments

Code analysis

Version control (...
More Uses For Phing


Installations and upgrades

Bootstrapping development environments

Code analysis

Version control (...
The Future


Improvements

     Better performance
     Increased test coverage
     Cross-platform compatibility
     Pai...
Questions?




http://www.phing.info

http://joind.in/3590

   #phing (freenode)

     @phingofficial

      Thank you!



...
Upcoming SlideShare
Loading in …5
×

of

Deploying PHP applications with Phing Slide 1 Deploying PHP applications with Phing Slide 2 Deploying PHP applications with Phing Slide 3 Deploying PHP applications with Phing Slide 4 Deploying PHP applications with Phing Slide 5 Deploying PHP applications with Phing Slide 6 Deploying PHP applications with Phing Slide 7 Deploying PHP applications with Phing Slide 8 Deploying PHP applications with Phing Slide 9 Deploying PHP applications with Phing Slide 10 Deploying PHP applications with Phing Slide 11 Deploying PHP applications with Phing Slide 12 Deploying PHP applications with Phing Slide 13 Deploying PHP applications with Phing Slide 14 Deploying PHP applications with Phing Slide 15 Deploying PHP applications with Phing Slide 16 Deploying PHP applications with Phing Slide 17 Deploying PHP applications with Phing Slide 18 Deploying PHP applications with Phing Slide 19 Deploying PHP applications with Phing Slide 20 Deploying PHP applications with Phing Slide 21 Deploying PHP applications with Phing Slide 22 Deploying PHP applications with Phing Slide 23 Deploying PHP applications with Phing Slide 24 Deploying PHP applications with Phing Slide 25 Deploying PHP applications with Phing Slide 26 Deploying PHP applications with Phing Slide 27 Deploying PHP applications with Phing Slide 28 Deploying PHP applications with Phing Slide 29 Deploying PHP applications with Phing Slide 30 Deploying PHP applications with Phing Slide 31 Deploying PHP applications with Phing Slide 32 Deploying PHP applications with Phing Slide 33 Deploying PHP applications with Phing Slide 34 Deploying PHP applications with Phing Slide 35 Deploying PHP applications with Phing Slide 36 Deploying PHP applications with Phing Slide 37 Deploying PHP applications with Phing Slide 38 Deploying PHP applications with Phing Slide 39
Upcoming SlideShare
Building and deploying PHP applications with Phing
Next
Download to read offline and view in fullscreen.

17 Likes

Share

Download to read offline

Deploying PHP applications with Phing

Download to read offline

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.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Deploying PHP applications with Phing

  1. 1. Deploying PHP applications with Phing Michiel Rook PHPNW11 - October 8th, 2011 Deploying PHP applications with Phing – 1 / 37
  2. 2. About me Freelance PHP/Java consultant Phing project lead http://www.linkedin.com/in/michieltcs @michieltcs Deploying PHP applications with Phing – 2 / 37
  3. 3. About Phing PHing Is Not GNU make; it’s a PHP project build system or build tool based on Apache Ant. Originally developed by Binarycloud Ported to PHP5 by Hans Lellelid I joined in 2005 Deploying PHP applications with Phing – 3 / 37
  4. 4. Features Scripting using XML build files Mostly cross-platform Interface to various popular (PHP) tools Deploying PHP applications with Phing – 4 / 37
  5. 5. Features Deploying PHP applications with Phing – 5 / 37
  6. 6. Installation PEAR installation $ pear channel-discover pear.phing.info $ pear install [--alldeps] phing/phing Optionally, install the documentation package $ pear install phing/phingdocs Deploying PHP applications with Phing – 6 / 37
  7. 7. Why Use A Build Tool? Deploying PHP applications with Phing – 7 / 37
  8. 8. Why Use A Build Tool Repetitive tasks Version control (Unit) Testing Configuring Packaging Uploading DB changes ... Deploying PHP applications with Phing – 8 / 37
  9. 9. Why Use A Build Tool For developers and administrators Automate! Easier handover to new team members Improves quality Reduces errors Saves time Deploying PHP applications with Phing – 9 / 37
  10. 10. Why Use Phing Rich set of tasks Integration with PHP specific tools Allows you to stay in the PHP infrastructure Easy to extend Embed PHP code directly in the build file Deploying PHP applications with Phing – 10 / 37
  11. 11. Why Use Phing Rich set of tasks Integration with PHP specific tools Allows you to stay in the PHP infrastructure Easy to extend Embed PHP code directly in the build file ... in the end, the choice is yours Deploying PHP applications with Phing – 10 / 37
  12. 12. The Basics Deploying PHP applications with Phing – 11 / 37
  13. 13. Build Files Phing uses XML build files Contain 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
  14. 14. 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
  15. 15. Properties Simple key-value files (.ini) ## build.properties version=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
  16. 16. 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
  17. 17. 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
  18. 18. Mappers and Filters Transform files during copy/move/... Mappers Change filename Filters Strip comments, white space Replace values Perform XSLT transformation Translation (i18n) Deploying PHP applications with Phing – 17 / 37
  19. 19. 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
  20. 20. Practical Examples Deploying PHP applications with Phing – 19 / 37
  21. 21. Testing Built-in support for PHPUnit / SimpleTest Code coverage through XDebug Various output formats Deploying PHP applications with Phing – 20 / 37
  22. 22. 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
  23. 23. 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
  24. 24. Database Migration DbDeploy Set of delta files (SQL) Tracks current version in changelog table Generates do & undo scripts Deploying PHP applications with Phing – 23 / 37
  25. 25. Database Migration Numbered delta file (1-create-post.sql) Apply & undo statements --// CREATE TABLE ‘post‘ ( ‘title‘ VARCHAR(255), ‘time_created‘ DATETIME, ‘content‘ MEDIUMTEXT ); --//@UNDO DROP TABLE ‘post‘; --// Deploying PHP applications with Phing – 24 / 37
  26. 26. 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
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. Extending Phing Deploying PHP applications with Phing – 29 / 37
  31. 31. Extending Phing Numerous extension points Tasks Types Selectors Filters Mappers Loggers ... Deploying PHP applications with Phing – 30 / 37
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. Demo Deploying PHP applications with Phing – 34 / 37
  36. 36. More Uses For Phing Installations and upgrades Bootstrapping development environments Code analysis Version control (SVN / GIT) Code encryption / encoding Deploying PHP applications with Phing – 35 / 37
  37. 37. More Uses For Phing Installations and upgrades Bootstrapping development environments Code analysis Version control (SVN / GIT) Code encryption / encoding Check the documentation! Deploying PHP applications with Phing – 35 / 37
  38. 38. The Future Improvements Better performance Increased test coverage Cross-platform compatibility Pain-free installation of dependencies (PHAR?) More documentation IDE support Moving to GitHub We would love (more) contributions! Deploying PHP applications with Phing – 36 / 37
  39. 39. Questions? http://www.phing.info http://joind.in/3590 #phing (freenode) @phingofficial Thank you! Deploying PHP applications with Phing – 37 / 37
  • yusufkambaagunduz

    Jul. 29, 2016
  • RaviShankarOjha1

    Dec. 11, 2015
  • kiathaw

    May. 10, 2015
  • sathishkumarduraiswa

    Jun. 13, 2014
  • sinologic

    Apr. 4, 2014
  • sbarrax

    Nov. 7, 2013
  • number0

    Oct. 9, 2013
  • seccamp

    Oct. 6, 2013
  • HumbertoDosReisRodrigues

    Mar. 24, 2013
  • FredrickSykes

    Jan. 26, 2013
  • andreysinitsyn

    Dec. 25, 2012
  • marceloferracioli

    Oct. 10, 2012
  • MariusMilcher

    Jul. 15, 2012
  • corleycloud

    Jun. 26, 2012
  • miziomon

    Jun. 10, 2012
  • duodraco

    Jan. 5, 2012
  • etng

    Oct. 29, 2011

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.

Views

Total views

21,818

On Slideshare

0

From embeds

0

Number of embeds

904

Actions

Downloads

185

Shares

0

Comments

0

Likes

17

×