Tuesday, April 15, 2014

Install phantomjs on Linux

Install phantomjs on Ubuntu / Debian

Download phantomjs package from here

If you have 32 bit Linux distribution, download 32 bit file package or if you are using 64 bit Linux distribution, download the 64 bit package.

Extract the zip file and open the directory. Now you will find the phantomjs file inside bin directory.

Copy the file and paste into /usr/bin, /usr/local/bin & /usr/local/share.

Create a file hello.js and put following code into it.


console.log('Hello, world!');
phantom.exit();
Now run the phantomjs from the terminal.
# phantomjs /path/of/hello.js or # /usr/bin/phantomjs /path/of/hello.js

Install phantomjs on CentOS / RHEL

Download phantomjs package from here

If you have 32 bit Linux distribution, download 32 bit file package or if you are using 64 bit Linux distribution, download the 64 bit package.

Extract the zip file and open the directory. Now you will find the phantomjs file inside bin directory.

Copy the file and paste into /usr/bin, /usr/local/bin & /usr/local/share.

Create a file hello.js and put following code into it.
console.log('Hello, world!'); phantom.exit();
Now run the phantomjs from the terminal.
# phantomjs /path/of/hello.js or # /usr/bin/phantomjs /path/of/hello.js
If you get the error
phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory

 
To remove this error.

# sudo yum install freetype

Now run hello.js again but if you get another error
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

 
To remove this error.

# sudo yum install fontconfig
 If you are still facing the error, Run
# sudo yum install fontconfig freetype libfreetype.so.6 libfontconfig.so.1 libstdc++.so.6
Now run again, it should work.

# phantomjs hello.js Hello, world!
Note : 
Execute or Run phantomjs on browser
you can't directly reference a phantomjs script in your browser, but you can communicate with a PhantomJS instance using HTTP GET/POST with Web Server module

No comments:

Post a Comment