Compiling phantomJS 2.0 for AWS EC2 linux image

Posted by Matt Bryson on 17-Apr-2015 11:30:08
Find me on:

Back in Feb I wrote about how to compile phantomJS 2.0.0 for linux, using centOS as the build machine. However, the resulting bin files are not portable across all linux distros, hence why the official binaries aren't out yet.

If you need to run phantomJS on one of the AWS machine images, here is how we compiled it on AWS.

First, you need to launch a new EC2 instance from the AWS console. Choose your linux distro, and make sure the box has enough memory to run the build process. 4 gig is enough. So we used a t2.medium.

Once the box has been created, you simply need to ssh into it, install git, checkout out the phantomJS repo, install the build dependencies, and run the build script as a background task.

The last bit is key - if you run the build script direct over ssh, it takes so long the ssh connection will more than likely timeout, and this kills the build process.

SSH into the ec2 instance.

ssh -i ~/path/to/cert.pem ec2-user@{server ip}

install git and other dependencies for phantom (yum or apt-get depending on your distro)

sudo yum -y update
sudo yum -y install git 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
[/code]
Patch the 2.0 release with a bug fix
[code language="bash" title=""]
curl -O https://patch-diff.githubusercontent.com/raw/ariya/phantomjs/pull/12899.patch
git apply 12899.patch

And finally run the build script as a background task.

nohup ./build.sh --confirm > build.out 2> build.err < /dev/null &

The nohup command will run the build as a background task, and write the stdout to build.out and writes any errors to build.err.

To follow the build progress, simply tail the `build.out` file.

tail -f build.out

You can now close the ssh connection and come back later to check on it.

Once its done, you can copy the bin file to your local machine with scp (change the paths as appropriate)

scp -i ~/path/to/cert.pem ec2-user@{server ip}:/home/ec2-user/phantomjs/bin/phantomjs /Users/path/to/local/destination

 

All in one go to make copying easier..

sudo yum -y update
sudo yum -y install git gcc gcc-c++ make flex bison gperf ruby openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel libpng-devel libjpeg-devel
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0.0
curl -O https://patch-diff.githubusercontent.com/raw/ariya/phantomjs/pull/12899.patch
git apply 12899.patch
nohup ./build.sh --confirm > build.out 2> build.err < /dev/null &
tail -f build.out

m

Topics: PhantomJS, EC2, AWS, CentOS, Linux, Bash

About the author

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

Free eBook Download

The 5 big eDetailing issues you should be aware of. Click below to download the eBook.

Download now

Subscribe to Email Updates