Installing Phing Globally with Phar

phing

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:

{codecitation}$ php phing-latest.phar{/codecitation}

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:

{codecitation}$ curl -O http://www.phing.info/get/phing-latest.phar{/codecitation}

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.

{codecitation}$ sudo mv ~/Downloads/phing-latest.phar /usr/local/opt{/codecitation}

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:

/Users/youruser/.composer/vendor/bin/:/Users/youruser/bin:/usr/local/bin:/usr/bin

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.

{codecitation}$ sudo chmod +x /usr/local/opt/phing-latest.phar{/codecitation}

Now, create a symlink for it inside the /usr/local/bin folder:

{codecitation}$ sudo ln -s /usr/local/opt/phing-latest.phar /usr/local/bin/phing{/codecitation}

Done! Now you should be able to run “phing” in any location to run your phing scripts:

{codecitation}$ phing{/codecitation}

Instructor

0 0 votes
Blog Rating
Subscribe
Notify of
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Walt

would love to see these commands for windows

Fotis Evangelou

Doesn’t work I’m afraid (at least for me) on macOS Sierra. Phing responds with a Nginx 301 moved message (probably from Phing’s site?). However this solution (using MAMP and bundled PEAR) does work: [url=http://www.torkiljohnsen.com/2009/04/06/installing-phing-on-mamp-mac-osx/]http://www.torkiljohnsen.co…[/url]

Tony Partridge

It does work, you just need to get the latest phar package from phing’s website.

nantcb

Just tried it – executing phing at the end does nothing

nantcb

Problem is with the curl line as it returns an empty file. Best to download the file directly.

Marco Saluzzo

Works great. The only thing I needed to change was to make the download link https

6
0
Would love your thoughts, please comment.x
()
x