Skip to end of metadata
Go to start of metadata

Redirection Notice

This page will redirect to in about 2 seconds.


Many teams are using Phing to build and/or deploy their applications. Phing is a build system that uses XML to describe a build process using "tasks": running tests, generating documentation, copying files to a remote server and many more are available. In this tutorial, we'll cover how PhpStorm can help us when working with Phing.

Enabling Phing Support in a PhpStorm Project

Before we can use the tooling PhpStorm provides for working with Phing, we have to specify the path to the Phing runner. We can do this through the Project Settings | Phing. When Phing is already available on our system, we can provide the path to it. If not, we can download it from the settings.

Once the path to Phing is provided, PhpStorm will enable the Phing features.

Working with the Phing Tool Window

Let's use the following example:

The above Phing project (or buildfile) contains two targets (hello and world), both writing text to the standard output. The project defines the world target is the default.

PhpStorm's Phing tools are located under the View | Tool Windows | Phing Build menu. After clicking it, the IDE will open a new tool window. In the screenshot below, we can see the PhpStorm project contains two Phing buildfiles (build.xml and the above helloworld.xml). Targets are recognized, and the default target is shown in bold.

From the Phing tool window, we can perform various tasks with the Phing buildfile and with the individual targets. All actions are available from the context menu. Some have a keyboard shortcut assigned (for example, Jump to Source will open the buildfile at the target's location by pressing F4).

Running Phing Targets

There are various ways of running Phing targets: we can run the default target or a specific one from the Phing tool window, as well as run a target right before a Run/Debug configuration.

Running Phing Targets Manually

From the Phing tool window, we can run targets manually. To do this, we must select the Phing buildfile or the target(s) and click the Run button from the toolbar (or context menu).

This will open the Phing Build output tool window, in which we can see the messages and results that our Phing buildfile writes to output.

Running Phing Targets Before a Run/Debug Configuration

It can be handy to run a Phing buildfile (or just a single task) before starting a Run/Debug configuration in PhpStorm. For example, we may want to run database migrations using the DbDeploy task to apply database updates to our local development database whenever we start a debugging session.

Running a Phing target before a Run/Debug configuration can be done from the Phing tool window, by using the Before Run/Debug... context menu. This will open a dialog in which we can select the Run/Debug configurations we want the Phing target to run with.

We can achieve the same by editing our Run/Debug configuration and clicking Add | Run Phing target in the Before launch section of the configuration.

After we click it, we can select the target to run.

Editing a Phing Project XML File

We can work on a Phing project XML (buildfile) in the editor. PhpStorm will provide code completion for the various elements in the Phing buildfile file, as well as the targets that have been defined.

Navigating to a target is possible by hovering over it and holding the Ctrl key, and then clicking it. The same can be done by placing the cursor on the target name and pressing Ctrl+B (CMD+B on Mac OS X).

Inspections are available too. The editor will warn us when we're using a task that has not been defined or imported into the Phing buildfile.

While editing, we can use the quick fixes (Alt+Enter) to quickly create targets when they haven't been created yet.

Working with Properties

In our Phing buildfiles, we can use properties to provide "variable" data into our build. For example, we may want to pass in a version number, or a target environment (e.g. "staging" or "production"). These might be set in the buildfile by calling the property or proprtyprompt tasks, or when running Phing from the command line.

Let's use the following Phing buildfile:

In the hello target, we will print the ${name} to output. We could hard-code the property value in our build file (<property name="name" value="Maarten" />) or just provide it when running the target from PhpStorm. Use the Settings context menu in the Phing tool window and specify the property name and value.

Using this approach, we can have PhpStorm provide our buildfile with property values that are meaningful on our own machine, and provide them using a properties file or from the command line when running them elsewhere.

  • No labels