How to install PhantomJs on a CentOS server

Uncategorized

I was playing around with using a server to run end to end scenario testing using PhantomJs (new to it, check out some useful books here). I like that PhantomJs has minimal requirements. However, I did have to install a couple of libraries that I didn’t find clear documentation for. So to benefit anyone who might be trying to do this, here are my steps:

Download Phantom

[samh@do ~]$ curl -O https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-i686.tar.bz2
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 13.0M 100 13.0M 0 0 2908k 0 0:00:04 0:00:04 --:--:-- 3402k

Extract directory

[samh@do ~]$ tar xvf phantomjs-1.9.1-linux-i686.tar.bz2

Copy binary to bin folder (note you may need to use sudo if you are not logged in with root priveleges)

[samh@do ~]$ cp phantomjs-1.9.1-linux-i686/bin/phantomjs /usr/local/bin

You will notice that this is not enough to run Phantom and you will encounter this error:

[samh@do ~]$ phantomjs hello.js
phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory

Here is the step to eliminate it:

[samh@do ~]$ sudo yum install freetype

Then you will see another error:

[samh@do ~]$ phantomjs hello.js
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

And here’s how to eliminate it:

[samh@do ~]$ sudo yum install fontconfig

This is it. Everything should work now:

[samh@do ~]$ phantomjs hello.js
Hello, world!

14 thoughts on “How to install PhantomJs on a CentOS server

  1. Im also trying to install on Centos 6.3 but m getting the permission denied and yet im logged in with root.

    [root@MyServer ~]# curl -O https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2

    % Total % Received % Xferd Average Speed Time Time Time Current

    Dload Upload Total Spent Left Speed

    100 12.6M 100 12.6M 0 0 880k 0 0:00:14 0:00:14 –:–:– 1120k

    [root@MyServer ~]# tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2

    phantomjs-1.9.2-linux-x86_64/

    phantomjs-1.9.2-linux-x86_64/bin/

    phantomjs-1.9.2-linux-x86_64/bin/phantomjs

    phantomjs-1.9.2-linux-x86_64/examples/

    phantomjs-1.9.2-linux-x86_64/examples/scandir.js

    phantomjs-1.9.2-linux-x86_64/examples/technews.coffee

    phantomjs-1.9.2-linux-x86_64/examples/tweets.js

    phantomjs-1.9.2-linux-x86_64/examples/rasterize.coffee

    phantomjs-1.9.2-linux-x86_64/examples/pagecallback.js

    phantomjs-1.9.2-linux-x86_64/examples/printheaderfooter.js

    phantomjs-1.9.2-linux-x86_64/examples/follow.js

    phantomjs-1.9.2-linux-x86_64/examples/run-jasmine.coffee

    phantomjs-1.9.2-linux-x86_64/examples/module.js

    phantomjs-1.9.2-linux-x86_64/examples/waitfor.coffee

    phantomjs-1.9.2-linux-x86_64/examples/stdin-stdout-stderr.coffee

    phantomjs-1.9.2-linux-x86_64/examples/pizza.js

    phantomjs-1.9.2-linux-x86_64/examples/seasonfood.coffee

    phantomjs-1.9.2-linux-x86_64/examples/unrandomize.js

    phantomjs-1.9.2-linux-x86_64/examples/modernizr.js

    phantomjs-1.9.2-linux-x86_64/examples/waitfor.js

    phantomjs-1.9.2-linux-x86_64/examples/direction.js

    phantomjs-1.9.2-linux-x86_64/examples/arguments.coffee

    phantomjs-1.9.2-linux-x86_64/examples/render_multi_url.js

    phantomjs-1.9.2-linux-x86_64/examples/run-qunit.js

    phantomjs-1.9.2-linux-x86_64/examples/printheaderfooter.coffee

    phantomjs-1.9.2-linux-x86_64/examples/ipgeocode.js

    phantomjs-1.9.2-linux-x86_64/examples/ipgeocode.coffee

    phantomjs-1.9.2-linux-x86_64/examples/version.js

    phantomjs-1.9.2-linux-x86_64/examples/movies.js

    phantomjs-1.9.2-linux-x86_64/examples/child_process-examples.js

    phantomjs-1.9.2-linux-x86_64/examples/loadurlwithoutcss.coffee

    phantomjs-1.9.2-linux-x86_64/examples/version.coffee

    phantomjs-1.9.2-linux-x86_64/examples/seasonfood.js

    phantomjs-1.9.2-linux-x86_64/examples/server.js

    phantomjs-1.9.2-linux-x86_64/examples/countdown.js

    phantomjs-1.9.2-linux-x86_64/examples/rasterize.js

    phantomjs-1.9.2-linux-x86_64/examples/injectme.js

    phantomjs-1.9.2-linux-x86_64/examples/run-jasmine.js

    phantomjs-1.9.2-linux-x86_64/examples/post.js

    phantomjs-1.9.2-linux-x86_64/examples/imagebin.coffee

    phantomjs-1.9.2-linux-x86_64/examples/pizza.coffee

    phantomjs-1.9.2-linux-x86_64/examples/hello.coffee

    phantomjs-1.9.2-linux-x86_64/examples/features.js

    phantomjs-1.9.2-linux-x86_64/examples/movies.coffee

    phantomjs-1.9.2-linux-x86_64/examples/tweets.coffee

    phantomjs-1.9.2-linux-x86_64/examples/injectme.coffee

    phantomjs-1.9.2-linux-x86_64/examples/features.coffee

    phantomjs-1.9.2-linux-x86_64/examples/colorwheel.coffee

    phantomjs-1.9.2-linux-x86_64/examples/walk_through_frames.js

    phantomjs-1.9.2-linux-x86_64/examples/printmargins.coffee

    phantomjs-1.9.2-linux-x86_64/examples/printmargins.js

    phantomjs-1.9.2-linux-x86_64/examples/scandir.coffee

    phantomjs-1.9.2-linux-x86_64/examples/loadspeed.coffee

    phantomjs-1.9.2-linux-x86_64/examples/printenv.js

    phantomjs-1.9.2-linux-x86_64/examples/serverkeepalive.coffee

    phantomjs-1.9.2-linux-x86_64/examples/fibo.coffee

    phantomjs-1.9.2-linux-x86_64/examples/echoToFile.coffee

    phantomjs-1.9.2-linux-x86_64/examples/netlog.js

    phantomjs-1.9.2-linux-x86_64/examples/useragent.coffee

    phantomjs-1.9.2-linux-x86_64/examples/child_process-examples.coffee

    phantomjs-1.9.2-linux-x86_64/examples/weather.coffee

    phantomjs-1.9.2-linux-x86_64/examples/direction.coffee

    phantomjs-1.9.2-linux-x86_64/examples/module.coffee

    phantomjs-1.9.2-linux-x86_64/examples/printenv.coffee

    phantomjs-1.9.2-linux-x86_64/examples/simpleserver.js

    phantomjs-1.9.2-linux-x86_64/examples/fibo.js

    phantomjs-1.9.2-linux-x86_64/examples/imagebin.js

    phantomjs-1.9.2-linux-x86_64/examples/colorwheel.js

    phantomjs-1.9.2-linux-x86_64/examples/technews.js

    phantomjs-1.9.2-linux-x86_64/examples/hello.js

    phantomjs-1.9.2-linux-x86_64/examples/echoToFile.js

    phantomjs-1.9.2-linux-x86_64/examples/postserver.coffee

    phantomjs-1.9.2-linux-x86_64/examples/page_events.coffee

    phantomjs-1.9.2-linux-x86_64/examples/postserver.js

    phantomjs-1.9.2-linux-x86_64/examples/weather.js

    phantomjs-1.9.2-linux-x86_64/examples/countdown.coffee

    phantomjs-1.9.2-linux-x86_64/examples/netsniff.coffee

    phantomjs-1.9.2-linux-x86_64/examples/detectsniff.js

    phantomjs-1.9.2-linux-x86_64/examples/render_multi_url.coffee

    phantomjs-1.9.2-linux-x86_64/examples/useragent.js

    phantomjs-1.9.2-linux-x86_64/examples/walk_through_frames.coffee

    phantomjs-1.9.2-linux-x86_64/examples/post.coffee

    phantomjs-1.9.2-linux-x86_64/examples/arguments.js

    phantomjs-1.9.2-linux-x86_64/examples/simpleserver.coffee

    phantomjs-1.9.2-linux-x86_64/examples/run-qunit.coffee

    phantomjs-1.9.2-linux-x86_64/examples/outputEncoding.coffee

    phantomjs-1.9.2-linux-x86_64/examples/phantomwebintro.js

    phantomjs-1.9.2-linux-x86_64/examples/follow.coffee

    phantomjs-1.9.2-linux-x86_64/examples/loadspeed.js

    phantomjs-1.9.2-linux-x86_64/examples/page_events.js

    phantomjs-1.9.2-linux-x86_64/examples/loadurlwithoutcss.js

    phantomjs-1.9.2-linux-x86_64/examples/sleepsort.js

    phantomjs-1.9.2-linux-x86_64/examples/sleepsort.coffee

    phantomjs-1.9.2-linux-x86_64/examples/netlog.coffee

    phantomjs-1.9.2-linux-x86_64/examples/outputEncoding.js

    phantomjs-1.9.2-linux-x86_64/examples/serverkeepalive.js

    phantomjs-1.9.2-linux-x86_64/examples/phantomwebintro.coffee

    phantomjs-1.9.2-linux-x86_64/examples/server.coffee

    phantomjs-1.9.2-linux-x86_64/examples/universe.js

    phantomjs-1.9.2-linux-x86_64/examples/pagecallback.coffee

    phantomjs-1.9.2-linux-x86_64/examples/stdin-stdout-stderr.js

    phantomjs-1.9.2-linux-x86_64/examples/detectsniff.coffee

    phantomjs-1.9.2-linux-x86_64/examples/unrandomize.coffee

    phantomjs-1.9.2-linux-x86_64/examples/netsniff.js

    phantomjs-1.9.2-linux-x86_64/ChangeLog

    phantomjs-1.9.2-linux-x86_64/README.md

    phantomjs-1.9.2-linux-x86_64/LICENSE.BSD

    phantomjs-1.9.2-linux-x86_64/third-party.txt

    [root@MyServer ~]# cp phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/local/bin

    cp: overwrite `/usr/local/bin/phantomjs’? y

    [root@MyServer ~]# phantomjs hello.js

    -bash: /usr/local/bin/phantomjs: Permission denied

    [root@MyServer ~]#

  2. phantomjs: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory

  3. Thanks šŸ™‚ I just had to run this, as it said I already have fontconfig and freetype installed:

    sudo yum install fontconfig freetype libfreetype.so.6 libfontconfig.so.1 libstdc++.so.6

  4. Thanks for pointing me to the right thing!

    BTW, for the runtime library try the ldd command:

    ldd /usr/local/bin/phantomjs

    and You will see the missing library if it be, and now You can search it with yum, for example:

    yum provides *libpng*

    The hello.js is in the phantomjs example directory.

  5. Hi, I follow your steps and all it’s ok, phantomjs work, but when I create a simple page and I render the page then phantomjs create an empty image…. why?

    var page = require(‘webpage’).create();

    page.open(‘about:blank’, function() {
    page.content = ‘Hello’;
    page.setContent(page.content,page);
    });

    page.onLoadFinished = function(){
    page.viewportSize = { width: 300, height : 200 };
    page.render(‘example.png’,{format: ‘png’});
    phantom.exit();
    };

Leave a Reply

Your email address will not be published. Required fields are marked *