Using Apache ANT to deploy web applications? - php

I was just able to get Apache ANT running on my computer. The ant -version commando outputs the version number , verifying that the installation went well.
I have read that ANT is well suited to handle deployment of web applications including PHP projects and have spent some time to get it working, but I just can't get my head around how to set it up to sync my files to my web server.
How can I make ANT sync folderA with folderB ?
Thanks

Last time I checked (long ago) there was no remote sync task in Ant (only local). You would have to write a shell script that calls rsync and execute this from Ant instead. There is a number of remote tasks though. And you could check out your code from your VCS instead of syncing it to the server.
On a sidenote, you might want to consider Phing over Ant. It's a port of Ant to PHP. It has a FileSync Task. You can also add your own Tasks (written in PHP) and is commonly used in Continuous Integration servers for PHP.
Also see What is your preferred Deployment Strategy for PHP and a couple others.

Read the manual: http://ant.apache.org/manual/index.html
Look at the <copy> task.

I was looking to do the same and just came across this article on how to deploy using ant, maybe it'll give you a different way of going about it: Deploying using Ant

Related

Jenkins Ant deploy/release on multiple remote server at same time

i try to solve the case where i need to make a PHP release on multiple remote Server nodes at the same time.
We got a Jenkins server wich does the following steps in his build (ant) script:
Git Checkout
PHP QA Tools Check (like PHPUnit, phpmd etc.)
Do some other tests
After everything is OK i want to deploy the sources to 3(later maybe more) remote Servers.
After everything is pushed to the Webnodes i want to execute a symlink change on all 3 nodes at the same time.
Sounds kind of impossible to me, but i hoped that i get a solution somewhere here, but i didn't found anything that helps.
So hopefully someone here got a good idea or some experience to share.
Cheers,
Dennis
You should look at this link because PHP deployments are a bit different from Java/.Net related deployments. However, if you feel that using Phing along with Jenkins OR using Phing independently is not what you want, and would like to simply have some plugin which copies your content to few remote servers, then you should try using Publish Over SSH plugin. After the steps in ant script mentioned above completes, you can add the task of deploying the sources to remote servers in Post-build Actions section. Once you've installed the plugin, you will find Send build artifacts over SSH option in the drop-down menu of Post-build Actions. Here you will find options to select multiple servers and you also have option to run command over those machines once the sources have been copied using Exec command that i have highlighted in the snapshot below. Also don't forget to check the Advanced... options and the help (?) section for each option.

What tools can I use to deploy PHP code to production server?

So far I only know about Capifony, but it's mostly for Symfony.
All I need is a script to run tests, check version, package some files, send them to a server, and run some commands there.
I have heard about continuous integrations, but it looks complicated and I'm not sure that's what I need.
Any advice will be appreciated.
You can try Capistrano
Despite the fact that this tool for Ruby projects, it can be used for projects in PHP.
You should look at r-sync, this is what we use in my company.
You can look here fo some description : http://en.wikipedia.org/wiki/Rsync
If you have shell access on the server, scp in batch mode might be helpful.
For just deploying, (not running tests) you could use a source control system. At my company, we simply check all tested and working code into a prod branch, then log in to our production account and sv update that application. (We're currently using subversion for source control)

Do I use phing locale or remote?

I have a question related to phing. Do I use it on my local development machine to deploy an application or do I call it via ssh from production machine? I'm not sure where to do the steps from Eran Galperin (What is your preferred PHP deployment strategy). I'm a beginner with deployment scripts. So be forgiving :)
Marco
You'll usually have two deploy scripts - One that you run locally, which ssh's in to the remote server and then kicks off the remote script.
Your local script might do an svn export, zip the contents and push them (scp) to the remote server first. The remote script would do stuff like migrating, restarting services etc.
The basic strategy is that you create a build (well, basically a copy of your web application that you can put online) on your local machine, and then deploy it on the server.
You run it on your local machine and the PHPing will connect to production server and deploy the website. :)
Phing can be applied in many ways.
If you don't have directives on how to deploy, the best way is usually first to generate a "test build" from your local copy, check out if it is working as intended and then generate the productive build.
In some cases where you have to follow certain rules in your development enviroment you can easily adapt Phing to meet those demands.
I developed a phing deploy script and I've used it in both of the ways you've described. As long as the phing library and dependencies are installed locally or on the remote machine you can do it in both ways, and it's actually a benefit to be able to run it from any of your environments.
Let me elaborate on my experience, but keep in mind that every person lives within the microcosm of the needs and requirements of their own projects/studios so it's possible that what works for me, may not work for other people.
I think deployment is usually so important for a business that it needs to happen in the exact same way every time. When there's a multitude of people doing the deployments, then it's easy for bad habits or procedures to diverge and that's when mistakes can happen. Automated deployments with phng are handy because if everyone is using the same procedure, then there's much lower potential for mistakes. Phing makes it easy to follow strict procedures because all the developers have to do is to run a simple command like "phing deploy" or "phing build" or what have you.
Now going back to your original question, it's also helpful for these procedures to be adhered to on local development machines as well as on staging, testing, production servers because just like people, machines can have small ideosyncracies that differ from machine to machine. With phing, you can develop a script that will have the same results on any of your enterprise machines (depending on the strength and intent of your code but phing lives in a format that makes it easy to meet that ideal). So if you run your phing build from your development box, ideally it has the same effect if you run it from your testing box or your production server. If you can run the deployment the same way on any machine, you can feel confident that any problems that arise after deployment were not a result of your deploy procedures (as they will not differ from when you deployed to your testing or local dev box).
It's really nice to be able to deploy my code to my local machine with the exact same procedure that I use to deploy it to production.
As far as what is the best to do, I say, why not all of the above? If you can run it locally, then you can run it remotely. If the deploy procedures are strong, then the result will be the same.
You can do it both ways. You can run the tool locally as you develop to run tests and just generally ensure that your code is in good condition. The server automation (if you choose to do that) can also run tests, generate documentation, and deploy changes to test or production setups.
Doing it locally reduces the chance that the process will get stalled on the server setup, while the CI works on a regular basis to ensure nothing has been broken via mistake.

What's the best process / app for automated deployment of PHP apps?

There's another post on SO relating to .NET -- not us. Pure PHP. Trying to find the best way/process to deploy stable version of our PHP app. I've seen an article on Capistrano, but am curious what else is out there. Aside from the obvious reasons, I'm also looking to add some scripting so that the SVN rev number gets added in there as well.
Much thanks.
I've used a home-grown script for quite some time. It will (based on an application configuration file):
Run svn export on the repository based on a tag.
Package the export into a tar or zip file, which includes the tag in the name.
Use scp to copy the package to the appropriate server (QA or release).
Connect to the server with ssh to install the package and run post-install scripts.
The application configuration file is part of the project. It can tell the script (at step 2) to strip paths and otherwise process specified files. It also specifies server names and how to handle externals.
I've recently migrated the script to support Git as well as Subversion. I'm also probably going to migrate it to PHP since we're now running in a mixed (Linux and Windows) set up, with Linux now in the minority.
I have plans to automatically call the script with post-commit hooks, but haven't had the need to implement that just yet.
Coincidentally, I was just reading about an Apache Ant/gnu make like build tool called Phing. What I like about it is the ability to write custom extensions in PHP!
I don't know if it works for deploying an app live, but phpUnderControl is a continuous integration suite (which I'm just now starting to look into). If it doesn't support doing deployments natively, it can probably be extended to do them.
Chris Hartjes has a nice view on this: Deployment is not a 4 letter word
We're using Webistrano, which is a web frontend for Capistrano, to deploy a few dozen projects. It's built as a Ruby on Rails app, and provides a nice, centralized and consistent user interface for Capistrano deployments.
Instead of having cap recipes in every project, and running command-line tools, Webistrano stores the recipes in its database, and allows you to attach the recipes to multiple projects and stages. This reduces duplication of scripts.
Also nice is that all deployment logs are stored so there's an auditing trail. Who deployed which revision to the live server, that sort of thing.
As you requested, the Revision number is stored in the deployed project as well.
All in all, we're very pleased with it.

Deploying to multiple servers

I have to deploy my php/html/css/etc code to multiple servers and i am looking at my options for software that allows easy and secure deployment to multiple servers.
Also helps if it could be tied into my SVN.
Any suggestions?
Capistrano is pretty handy for that. There's a few people using it (1, 2, 3) for deploying PHP code as evidenced by doing a quick search.
Setting up password-less publickey authentication with ssh would allow you to scp your files to any of your servers very quickly (or be automated by a shell script).
Here's a simple tutorial: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html
If you're running on Redhat or Debian, consider packaging up your code into RPM's or Debs. Then build a yum or dpkg repository and put your packages there. You can then use your system's package management to do upgrades/rollbacks, etc. You can even use puppet to automate the process.
If you want to tie it into subversion, you can create a branch for each new version. Use the commit scripts to build the RPM's when a new branch shows up in a directory.
I'll second Capistrano. It's incredibly powerful and flexible. Our current project uses Capistrano for deploying to different servers as well as multiple servers. We pass two arguments to the cap command:
1) the name of the set of machine specific config options to run and
2) the name of the action to run
ends up looking like this:
cap -f deploy.rb live deploy
or
cap -f deploy.rb dev deploy
Of course the default use case - deploy to lots of machines at once - is a doddle with Capistrano AND you don't need to have Capistrano on the machines you are deploying to. All in all, tasty technology.
I've used Automated Build Studio before for a similar task. It gives you a lot of flexibility in what you can do.
I concur -- set your svn tree up, and use rsync over ssh to copy the tree out to the remote locations. rsync will make it fast and efficient, only copying changes rather than full files.
You want to export your svn tree to some directory, then rsync from there to the remote host's directory tree.
I also forgot to mention that if you use rsync, you can set up rsync to use ssh, so you will only transfer the files that have changed, saving on time and bandwidth.
You can also use kwateeSDCM which is free and allows remote installation via ssh. It also enables you to manage server-specific configuration from a central location and make upgrades seemless.
I had marked a post on how to deploy your websites using Subversion : http://blog.lavablast.com/post/2008/02/I2c-for-one2c-welcome-our-new-revision-control-overlords!.aspx
I found capistrano to be very easy to use once it's setup. The configuration file can be a bit confusing at first for more complicated environments but it soon becomes worthwhile. I deploy to 14 servers on production. I also use multiple environments for deployment to a staging server. One quirk, there's a bug in Ruby that breaks parallel deployment but serially isn't too bad with svn exports.
Capistrano setup is just too complicated. We found that KwateeSDCM was very straightforward to use with a simple web interface and no scripting. We've got our deployment configuration done in no time for Dev and QA configuration on windows and linux servers.

Categories