The initial step is to get access to Power virtual machine for free at Minicloud. Then, once the VM is up and running, install the required dependencies:
sudo apt-get update -qq sudo apt-get upgrade -y -qq sudo apt-get install -qq build-essential libicu-dev libssl-dev gperf bison ruby flex
Once installed, clone the phantomjs repository:
git clone https://github.com/ariya/phantomjs.git
With, you are all set to build phantomjs:
cd ./phanthomjs ./build.py -c -r
When the build completes, your phantomjs will be available in the /bin folder.