11

I was just wondering how I use Ant to build my web applications that I have written in PHP? I've googled around a bit and I have seen that it is possible but there are not any examples of the basic idea or any advanced use for them. Can any of you help me out?

Thanks!

Charles
  • 50,943
  • 13
  • 104
  • 142
cskwrd
  • 2,803
  • 8
  • 38
  • 51
  • 1
    It would be helpful to know exactly which build tasks you need to perform. – Dana the Sane Jul 20 '09 at 17:13
  • I plan on use the scripts to get everything ready to move from my test site to my live site. By this I mean making sure that the necessary file paths are correct in order to access the live site's database etc. – cskwrd Jul 20 '09 at 18:41
  • I should clarify that I am looking to make any necessary changes to the databases by use of ant scripts, too. (i.e. adding fields and updating existing info) – cskwrd Jul 21 '09 at 14:16
  • I've updated my answer to reflect clarifications made by your latest comments. – ChssPly76 Jul 21 '09 at 16:23

4 Answers4

9

This is definitely possible. If you are looking for a pure php solution phing might be what you want. Also note that there's usually no reasons to build PHP scripts. They should 'just work'.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • 1
    I realize they should "just work," but I am working as a php developer this summer and I am pretty sure that my employer use ant scripts to prepare an update for the live site so I was just wondering how they did it. – cskwrd Jul 20 '09 at 18:47
  • 1
    PHP is not used just for sites. If you have a whole unit-tested web application, with different configurations for different environments like developing, testing, and production, you should definitely use Phing or another build system. If there were no reason, Phing wouldn't exist... :) – ViniciusPires Sep 24 '13 at 14:42
  • Not counting on concatenating and minimizing css and javascript files, that is really a good use... – ViniciusPires Sep 24 '13 at 14:49
8

While Ant itself is written in java, you can use it to build any kind of applications you want. Here's a basic tutorial and a full manual. Beyond that, you need to clarify what is it you want to do to get a more precise answer here.

Update (based on question clarifications):

Copying / moving files / folders is easy via Ant. Look through the "Hello World" tutorial I've linked above and Familiarize yourself with FileSet concept and Copy, Mkdir and Move tasks to get started. Here's another tutorial that shows how to set up a basic build (ignore java-specific stuff like javac/war).

Making changes to the database is an entirely different subject. If you have 'alter' scripts ready, you can use Ant's Exec task to invoke your DB's command-line client to run those scripts (though I probably wouldn't do it in production). If you want to use Ant to track those changes, then you're looking at the wrong tool. Liquibase can be used to do that and it seems to be getting a lot of traction lately. It's quite like Ant in the sense that it's written in Java but can be used in any environment. I'm no PHP expert so I wouldn't know if there's something more PHP-geared available.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
ChssPly76
  • 99,456
  • 24
  • 206
  • 195
2

We use ant to 'build' php apps. At it's most basic, the ant script just copies the file into the folder on the testing webserver (localhost in my case).

Why do this? well there's not a great deal of point to it, but it is a handy way to avoid putting .svn files into the webserver. If you want to change the location of the webserver you can just build to the new location. You can also do different things according to whether you're on Linux or Windows for example, but I've never used that side of it.

Steve
  • 29
  • 1
  • 1
    You can also run unit tests and style checks (like phpcheckstyle and PHP Mess Detector) which I think is one of the interesting things to do. – Daniel Lo Nigro Aug 25 '11 at 22:16
1

Having tried Phing, Ant and Gradle, I would strongly recommend gradle. Here is a bit of description Choosing tools for PHP application automation

Jin Chen
  • 31
  • 2