How To Install PhantomJS in a VPS

PhantomJS is an open-source scripted browser that can be used to interact with web pages and produce high quality website screenshots. PhantomJS is based on WebKit so you can get results very close to Safari and Google Chrome. It is completely free and distributed under the BSD license.

Using the JavaScript API provided by PhantomJS, you can awesome scripts to interact with your websites and web pages, execute user actions, or even take screenshots. For instance, if you need to make a screenshot service (like the one we use in HostingPilot.com to generate screenshots online), you can do it for free instead of paying for a 3rd. party service.

PhantomJS can be installed on a Linux system like Ubuntu server.

Before installing, make sure you have access to a sudo user. Also, you will need some packages installed on your system (pre-requisites). In Ubuntu, you can install them using the apt-get tool. Make sure to use sudo.

sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y

Then, you will need to download a release of PhantomJS. You can do this using wget and passing the URL where to download the .tar file. Here is an example:


sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

Next, decompress the archive into the desired location.

sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/

You can now create a symlink to the PhantomJS binary file so it can be accessed easily from your system.

sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/

Now, PhantomJS is successfully installed on your system. If you want to check it, you can verify the installed version of PhantomJS running phantomjs --version.