SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
Flask for cs students
Flask for cs studentsFlask for cs students
Flask for cs students
 
Operator Framework Overview
Operator Framework OverviewOperator Framework Overview
Operator Framework Overview
 
Kubernetes ist so viel mehr als ein Container Orchestrierer
Kubernetes ist so viel mehr als ein Container OrchestriererKubernetes ist so viel mehr als ein Container Orchestrierer
Kubernetes ist so viel mehr als ein Container Orchestrierer
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
CI/CD with Github Actions
CI/CD with Github ActionsCI/CD with Github Actions
CI/CD with Github Actions
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 
Introduction to Helm
Introduction to HelmIntroduction to Helm
Introduction to Helm
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Hands-on Helm
Hands-on Helm Hands-on Helm
Hands-on Helm
 
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar SeriesContinuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
 
카카오 광고 플랫폼 MSA 적용 사례 및 API Gateway와 인증 구현에 대한 소개
카카오 광고 플랫폼 MSA 적용 사례 및 API Gateway와 인증 구현에 대한 소개카카오 광고 플랫폼 MSA 적용 사례 및 API Gateway와 인증 구현에 대한 소개
카카오 광고 플랫폼 MSA 적용 사례 및 API Gateway와 인증 구현에 대한 소개
 
TypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptxTypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptx
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
도메인 주도 설계의 본질
도메인 주도 설계의 본질도메인 주도 설계의 본질
도메인 주도 설계의 본질
 
Spring Cloud Config
Spring Cloud ConfigSpring Cloud Config
Spring Cloud Config
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 

Destacado

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
 

Destacado (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
 

Similar a Deploying PHP applications with Phing

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

Similar a 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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

"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 ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

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