SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
Deploying PHP applications with Phing




                                       Michiel Rook

                   PHPNW11 - October 8th, 2011




               Deploying PHP applications with Phing – 1 / 37
About me


Freelance PHP/Java consultant

Phing project lead

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

@michieltcs




                                    Deploying PHP applications with Phing – 2 / 37
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
Features


Scripting using XML build files

Mostly cross-platform

Interface to various popular (PHP) tools




                                           Deploying PHP applications with Phing – 4 / 37
Features




Deploying PHP applications with Phing – 5 / 37
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
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
     Uploading
     DB changes
     ...




                       Deploying PHP applications with Phing – 8 / 37
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
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
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
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 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.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
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 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
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
Testing


Built-in support for PHPUnit / SimpleTest

Code coverage through XDebug

Various 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 Migration


DbDeploy

Set of delta files (SQL)

Tracks current version in changelog table

Generates 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
);

--//@UNDO

DROP 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 Phing


Numerous 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 Phing


Installations and upgrades

Bootstrapping development environments

Code analysis

Version control (SVN / GIT)

Code encryption / encoding




                                         Deploying PHP applications with Phing – 35 / 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
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
Questions?




http://www.phing.info

http://joind.in/3590

   #phing (freenode)

     @phingofficial

      Thank you!




                       Deploying PHP applications with Phing – 37 / 37

Weitere ähnliche Inhalte

Was ist angesagt?

WSO2 ESB Integration with REST
WSO2 ESB Integration with RESTWSO2 ESB Integration with REST
WSO2 ESB Integration with REST
WSO2
 

Was ist angesagt? (20)

Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Build Restful Service using ADFBC
Build Restful Service using ADFBCBuild Restful Service using ADFBC
Build Restful Service using ADFBC
 
Linux : Booting and runlevels
Linux : Booting and runlevelsLinux : Booting and runlevels
Linux : Booting and runlevels
 
Ipl자동화방안제안 애플트리랩
Ipl자동화방안제안 애플트리랩Ipl자동화방안제안 애플트리랩
Ipl자동화방안제안 애플트리랩
 
왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
 
UDA-Guia de desarrollo
UDA-Guia de desarrolloUDA-Guia de desarrollo
UDA-Guia de desarrollo
 
WSO2 ESB Integration with REST
WSO2 ESB Integration with RESTWSO2 ESB Integration with REST
WSO2 ESB Integration with REST
 
GIT INTRODUCTION
GIT INTRODUCTIONGIT INTRODUCTION
GIT INTRODUCTION
 
Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
What is Puppet | Puppet Tutorial for Beginners | Puppet Configuration Managem...
What is Puppet | Puppet Tutorial for Beginners | Puppet Configuration Managem...What is Puppet | Puppet Tutorial for Beginners | Puppet Configuration Managem...
What is Puppet | Puppet Tutorial for Beginners | Puppet Configuration Managem...
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
Rich domain model
Rich domain modelRich domain model
Rich domain model
 
git and github
git and githubgit and github
git and github
 
Hibernate
HibernateHibernate
Hibernate
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 

Andere mochten auch

One click deployment with Jenkins - PHP Munich
One click deployment with Jenkins - PHP MunichOne click deployment with Jenkins - PHP Munich
One click deployment with Jenkins - PHP Munich
Mayflower GmbH
 

Andere mochten auch (20)

Phing
PhingPhing
Phing
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Building and Deploying PHP Apps Using phing
Building and Deploying PHP Apps Using phingBuilding and Deploying PHP Apps Using phing
Building and Deploying PHP Apps Using phing
 
One click deployment with Jenkins - PHP Munich
One click deployment with Jenkins - PHP MunichOne click deployment with Jenkins - PHP Munich
One click deployment with Jenkins - PHP Munich
 
Desplegando código con Phing, PHPunit, Coder y Jenkins
Desplegando código con Phing, PHPunit, Coder y JenkinsDesplegando código con Phing, PHPunit, Coder y Jenkins
Desplegando código con Phing, PHPunit, Coder y Jenkins
 
Ant vs Phing
Ant vs PhingAnt vs Phing
Ant vs Phing
 
Smarty Template Engine
Smarty Template EngineSmarty Template Engine
Smarty Template Engine
 
Smarty + PHP
Smarty + PHPSmarty + PHP
Smarty + PHP
 
CIS13: Dealing with Our App-Centric Future
CIS13: Dealing with Our App-Centric FutureCIS13: Dealing with Our App-Centric Future
CIS13: Dealing with Our App-Centric Future
 
jQuery für Anfänger
jQuery für AnfängerjQuery für Anfänger
jQuery für Anfänger
 
CQRS & Event Sourcing in the wild (ScotlandPHP 2016)
CQRS & Event Sourcing in the wild (ScotlandPHP 2016)CQRS & Event Sourcing in the wild (ScotlandPHP 2016)
CQRS & Event Sourcing in the wild (ScotlandPHP 2016)
 
Putting Phing to Work for You
Putting Phing to Work for YouPutting Phing to Work for You
Putting Phing to Work for You
 
Introduction à l'intégration continue en PHP
Introduction à l'intégration continue en PHPIntroduction à l'intégration continue en PHP
Introduction à l'intégration continue en PHP
 
Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
 
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
 
Ain't Nobody Got Time For That: Intro to Automation
Ain't Nobody Got Time For That: Intro to AutomationAin't Nobody Got Time For That: Intro to Automation
Ain't Nobody Got Time For That: Intro to Automation
 
Getting Started With Jenkins And Drupal
Getting Started With Jenkins And DrupalGetting Started With Jenkins And Drupal
Getting Started With Jenkins And Drupal
 
Juc boston2014.pptx
Juc boston2014.pptxJuc boston2014.pptx
Juc boston2014.pptx
 
Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)
 
PHP Cloud Deployment Toolkits
PHP Cloud Deployment ToolkitsPHP Cloud Deployment Toolkits
PHP Cloud Deployment Toolkits
 

Ähnlich wie Deploying PHP applications with Phing

IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11
julien.ponge
 

Ähnlich wie Deploying PHP applications with Phing (20)

Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
John's Top PECL Picks
John's Top PECL PicksJohn's Top PECL Picks
John's Top PECL Picks
 
PHP and PDFLib
PHP and PDFLibPHP and PDFLib
PHP and PDFLib
 
Applying software engineering to configuration management
Applying software engineering to configuration managementApplying software engineering to configuration management
Applying software engineering to configuration management
 
Advanced Malware Analysis Training Session 5 - Reversing Automation
Advanced Malware Analysis Training Session 5 - Reversing AutomationAdvanced Malware Analysis Training Session 5 - Reversing Automation
Advanced Malware Analysis Training Session 5 - Reversing Automation
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Improving qa on php projects
Improving qa on php projectsImproving qa on php projects
Improving qa on php projects
 
Building and Deploying PHP apps with Phing
Building and Deploying PHP apps with PhingBuilding and Deploying PHP apps with Phing
Building and Deploying PHP apps with Phing
 
Php ppt
Php pptPhp ppt
Php ppt
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Build Your First SharePoint Framework Webpart
Build Your First SharePoint Framework WebpartBuild Your First SharePoint Framework Webpart
Build Your First SharePoint Framework Webpart
 
Building com Phing - 7Masters PHP
Building com Phing - 7Masters PHPBuilding com Phing - 7Masters PHP
Building com Phing - 7Masters PHP
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
Taking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced ScriptingTaking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced Scripting
 
Php Development Stack
Php Development StackPhp Development Stack
Php Development Stack
 
Php Development Stack
Php Development StackPhp Development Stack
Php Development Stack
 
IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11
 
Introducing DeploYii 0.5
Introducing DeploYii 0.5Introducing DeploYii 0.5
Introducing DeploYii 0.5
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Deploying PHP applications with Phing

  • 1. Deploying PHP applications with Phing Michiel Rook PHPNW11 - October 8th, 2011 Deploying PHP applications with Phing – 1 / 37
  • 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. 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. Features Scripting using XML build files Mostly cross-platform Interface to various popular (PHP) tools Deploying PHP applications with Phing – 4 / 37
  • 5. Features Deploying PHP applications with Phing – 5 / 37
  • 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. Why Use A Build Tool? Deploying PHP applications with Phing – 7 / 37
  • 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. 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. 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. 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. The Basics Deploying PHP applications with Phing – 11 / 37
  • 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. 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. 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. 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. 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. 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. 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. Practical Examples Deploying PHP applications with Phing – 19 / 37
  • 21. Testing Built-in support for PHPUnit / SimpleTest Code coverage through XDebug Various output formats Deploying PHP applications with Phing – 20 / 37
  • 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. 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. 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. 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. 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. 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. 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. 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. Extending Phing Deploying PHP applications with Phing – 29 / 37
  • 31. Extending Phing Numerous extension points Tasks Types Selectors Filters Mappers Loggers ... Deploying PHP applications with Phing – 30 / 37
  • 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. 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. 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. Demo Deploying PHP applications with Phing – 34 / 37
  • 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. 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. 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. Questions? http://www.phing.info http://joind.in/3590 #phing (freenode) @phingofficial Thank you! Deploying PHP applications with Phing – 37 / 37