Compiling phantomJs 2.0 binaries on Linux

Posted by Matt Bryson on 08-Feb-2015 16:56:26
Find me on:

We were upgrading our automated screen shot process of our core product, moving it over to phantomJS 2.0 as it uses a much newer QT WebKit engine, that produces far more accurate results.

However, there is currently no download for the linux build, so we decided to build it ourselves. After quite a few failed attempts, (using various bash scripts and trying the deploy vm that is in the repo), this is how we finally got it working If you want to cut to the chase, you can grab the 64bit bin file here...

UPDATE: for compiling for AWS EC2 see here

We used Virtualbox and vagrant on OSX to spin up a 64bit CentOS box, with this vagrant file.

Note the memory allocation, the build will fail unless you have decent amount of ram on the VM
# -*- mode: ruby -*-
# vi: set ft=ruby :
    
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "CentOS_6.5_64"
config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
config.vm.synced_folder ".", "/home/vagrant/phantomjs/bin", owner:"root", group:"root", mount_options:["dmode=777","fmode=777"]
end

config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "4096"]
end
end

Save the above and call it Vagrantfile. Then get your terminal up, and cd to the same dir.

Now spin up that server and ssh into it (the first time will take a while as it downloads the base vm image)...
vagrant up
vagrant ssh
Then update yum and install dependencies...
 sudo yum -y update
sudo yum -y install gcc gcc-c++ make flex bison gperf ruby openssl-devel freetype-devel
fontconfig-devel libicu-devel sqlite-devel libpng-devel libjpeg-devel

Checkout the repo, and switch to the 2.0 release
 git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0.0
Next we had to patch the 2.0 release with a bug fix
 curl -O https://patch-diff.githubusercontent.com/raw/ariya/phantomjs/pull/12899.patch
git apply 12899.patch
And finally run the build script.
 ./build.sh

It takes HOURS to compile, due to all the webkit dependencies. We did try spinning up with more CPU cores, and running the build script with more build jobs, but this always failed on us.

If you just want the bin from this build (64bit) then you can grab it here

m

Topics: PhantomJS, Linux

About the author

Matt Bryson is an experienced systems engineer with over 15 years Development and Systems Operations experience.

NEW - Free eBook

Transforming your eDetail process. Click below to download the eBook.

New Call-to-action

Subscribe to Email Updates

Recent Posts