Write PHP, deploy anywhere Tek 11 - Chicago, IL (USA)
m a I’ p e r v e lo D e
I write code
Not a sysadmin http://www.flickr.com/photos/scobleizer/4870003098/
Just want to run code
Deployment types
Live Hacking
Good old days
FTP deploy
Manual FTP deploy
Version control
Code management
Versioning concepts
Symlink switch old path/to/webapp path/to/webapp-1.0.2 -> path/to/webapp path/to/webapp-1.0.3
Symlink switch new path/to/webapp path/to/webapp-1.0.2 path/to/webapp-1.0.3 -> path/to/webapp
Automated deployment
Concept: build • required steps •- to “build” an application validate - test - document - package
PHP provides the tools!
Phing •- build tool written in PHP comparable to ANT - but written in PHP :-) • impressive list of task templates • extensible for missing tasks
Phing HelloWorld! <?xml version="1.0" encoding="UTF-8"?> <project name="demo" default="build"> <target name="build"> <echo msg="Hello World!"/> </target> </project>
Export from SVN <property name="buildpath" value="./build"/> <property name="repopath" value="https://svn.myserver.com/demo/trunk"/> <target name="prepare"> <delete dir="${buildpath}" includeemptydirs="true" quiet="true" verbose="false" failonerror="false" /> <mkdir dir="${buildpath}"/> </target> <target name="getsources" depends="prepare"> <svnexport svnpath="/usr/bin/svn" force="true" nocache="true" repositoryurl="${repopath}" todir="${buildpath}"/> </target>
Deployment targets • scp • rsync • ftp •- VCM deployments cvs - svn - git - …
More info: phing.info
Anywhere deployment
Where to deploy to? • bare metal servers •- virtual servers even cloud instances • any OS (Windows, OSX, Linux, i5, …)
Linux server
Example deploy Linux <target name="deploy-linux"> <exec dir="./build" command="rsync -ruq user@server.com:/srv/www/demo"/> </target>
Windows server
Deploy to windows <target name="deploy-windows" depends="version-bugfix"> <ftpdeploy host="${env.win-prod}" port="21" username="${auth.win-prod.username}" password="${auth.win-prod.password}" dir="/" mode="binary" clearfirst="false"> <fileset dir="."> <exclude=”./library/Zend”/> <exclude=”./library/ZendX”/> </fileset> </ftpdeploy> </target>
Deploy to S3 <target name="deploy-windows" depends="version-bugfix"> <ftpdeploy host="${env.win-prod}" port="21" username="${auth.win-prod.username}" password="${auth.win-prod.password}" dir="/" mode="binary" clearfirst="false"> <fileset dir="."> <exclude=”./library/Zend”/> <exclude=”./library/ZendX”/> </fileset> </ftpdeploy> </target>
Windows Azure
A few remarks •- runs only on windows but still uses phing :-) • takes a considerable time to upload • instances are defined in the config
Setting properties <property name="cmd-cspack" value="c:Program FilesWindows Azure SDKv1.3bin cspack.exe" override="false"/> <property name="cmd-csrun" value="c:Program FilesWindows Azure SDKv1.3bin csrun.exe" override="false"/>
Prepare for Azure <target name="prepare-azure" depends="version-bugfix"> <!-- start building in ./bldtmp --> <mkdir dir="./bldtmp" /> <copy todir="./bldtmp" overwrite="true"> <fileset dir="./deploy/azure"> <include name="**/*.*" /> </fileset> </copy> <copy todir="./bldtmp/PhpOnAzure.Web" overwrite="true"> <fileset dir="."> <include name="**/*"/> <include name="*"/> </fileset> </copy> </target>
Deploy to Azure <target name="deploy-azure" depends="prepare-azure"> <exec command="&quot;${cmd-cspack}&quot; ServiceDefinition.csdef / role:PhpOnAzure.Web;PhpOnAzure.Web /out:PhpAzure.cspkg" dir="./bldtmp" /> <mkdir dir="./release/${phing.project.name}-$ {version.number}/azure-prod" /> <copy todir="./release/${phing.project.name}-$ {version.number}/azure-prod" overwrite="true"> <fileset dir="./bldtmp"> <include name="PhpOnAzure.cspkg"/> <include name="ServiceConfiguration.cscfg"/> </fileset> </copy> </target>
Continuous Integration
Continuous Building
With CI • always “ready to deploy” codebase • feedback on quality • documentation • more …
Considerations
Some reminders •- design your apps to work everywhere use OOP abstraction layers - use plugins - take care of sessions! • investigate “the other platform” - gives you a head start over competetion - teaches you the caveats • “cloud” solutions are in high-demand - see what works best for your customer
automate what you might forget under stress!
Conclusion
1. deployment is simple 2. automate the steps 3. deploy to any platform
Thank you • source code: http://github.com/DragonBe/zftest • your rating: http://joind.in/3438 •- follow me: twitter: @DragonBe - facebook: DragonBe Please use joind.in for feedback

Write php deploy everywhere tek11