As we’ve been releasing more code via Alledia, we’ve found ourselves relying more and more on Phing.
Phing is a build system that allows you to use one command to perform a whole group of actions. For example, with one command you could run code and unit tests, and if the tests pass, automatically upload the new code to your servers and make any neccessary database changes.
Without a tool like Phing, your workflow will be repetitive and time-consuming because you’ll need to go through each step manually.
The official Phing installation guide explains how to install it using PEAR, Composer or downloading a Phar archive. If you want to install Phing globally, but want to avoid PEAR or Composer, the Phar archive is the way to go.
Here you will learn an easy way to install the Phar file globally. Install this script globally means we will be able to run it in any project, directory or path without copying it everywhere.
This type of extension is just a packaged PHP application, and you can execute it as any PHP script:
$ php phing-latest.phar
But typing this whole command every time you want to build your project is tedious and unnecessary. Some simple commands can make your life easier. Phing is a cross-platform script, but we will be covering only *nix systems like Linux and OS X.
Installing Phing Globally
First, you need to download the latest version of Phing. Feel free to download using the browser.
If you prefer, you can use the command line:
$ curl -O http://www.phing.info/get/phing-latest.phar
Move it to a definitive location
If you downloaded the script using the browser it may be on your downloads folder: ~/Downloads. If your script is there, or in any other temporary location, you need to move it to a definitive location. I would recommend to move it into the /usr/local/opt location. Feel free to store it in any other path.
If you want to move it using the command line, use the next command, replacing ~/Downloads/phing-latest.phar with the current path and the /usr/local/opt with the destination.
$ sudo mv ~/Downloads/phing-latest.phar /usr/local/opt
Make it executable globally
Moving the script to that location doesn’t make it available everywhere or even executable. So, what make an script globally available? *nix systems have an environment variable named PATH. This variable contains a list of locations (separated by the colon char) like:
Every time you call a command or executable script, your OS will look for it in one of those locations. If found, it will execute it. So, to make our script available as a global script we have two options: add the script location to the PATH environment variable or move/symlink it into an already listed location.
Let’s see how to do it using symlinks, without touching the PATH variable.
First, make sure to add the permissions to execute that script.
$ sudo chmod +x /usr/local/opt/phing-latest.phar
Now, create a symlink for it inside the /usr/local/bin folder:
$ sudo ln -s /usr/local/opt/phing-latest.phar /usr/local/bin/phing
Done! Now you should be able to run “phing” in any location to run your phing scripts: