How to Install PhantomJS On CentOS 7
What is PhantomJS?
In this article, we will be discussing PhantomJS. PhantomJS is, in the simplest of terms, is a headless browser (headless, meaning without a GUI) that utilizes a javascript API. This function makes the browser very useful when used for:
- Page automation - Accessing web pages and extracting information using the standard DOM API, or with usual libraries like jQuery.
- Screen capture - Programmatically capturing web content, including SVG and Canvas. Create website screenshots with a thumbnail preview.
- Headless website testing - Running functional tests with the Jasmine, QUnit, Mocha, and WebDriver frameworks.
- Network monitoring - Monitoring page load times and exporting that info as standard HAR files. It also automates performance analysis using YSlow and Jenkins.
phantomjs.org
Prerequisites
To ensure PhantomJS installs and operates correctly, we need to verify the following packages are installed and up to date on our system:
- glibc
- fontconfig
- fontconfig-devel
- freetype
- freetype-devel
- wget
- bzip2
The best way to verify if all required packages are installed is by utilizing the “YUM list installed packages" command. We can check this using the following command:
[root@host ~]# yum list installed
This command lists all installed packages in alphabetical order.
Because the installed packages list can be pretty long, using the “more” or “less” commands piped after the list command will allow you to scroll through the list quickly.
[root@host ~]# yum list installed | more
[root@host ~]# yum list installed | less
Additionally, we can grep for specific packages in the prerequisites list:
[root@host ~]# yum list installed | grep "package name"
If any of the packages are missing, we can use this command to install them (choose some or all of the packages to install):
[root@host ~]# sudo yum install glibc fontconfig freetype freetype-devel fontconfig-devel wget bzip2
Download and Install PhantomJS
PhantomJS does not require installation in the traditional sense. All we have to do is to download the latest release from the official website, then extract the archive to the desired system location.
Moving forward, we can use wget to download the file:
[root@host ~]# wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
Once the download has completed, we will need to extract the files:
[root@host ~]# tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/
After the files have been extracted, we will need to create a soft (or “symbolic”) link between the PhantomJS binary file and the systems bin directory.
[root@host ~]# ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin
Verify the PhantomJS Install
First, let’s check the software version. We can accomplish this by typing:
[root@host ~]# phantomjs --version
2.1.1
We can also check the version using the PhantomJS prompt. To open the PhantomJS prompt, type:
[root@host ~]# phantomjs
At the new prompt, type the “phantom.version” command. The output should look like this:
[root@host ~]# phantomjs
phantomjs> phantom.version
{
"major": 2,
"Minor": 1,
"patch": 1
}
Test PhantomJS
To ensure that everything is working as intended, we will create a short .js script. Create a new text file that contains the following lines:
console.log('Hello, world!');
phantom.exit();
Save it as helloworld.js and then run:
[root@host ~]# phantomjs helloworld.js
If everything is working correctly, the output should look like this:
[root@host ~]# phantomjs helloworld.js
Hello, world!
As a side note, the Ubuntu installation is nearly the same except we would use apt-get instead of yum.
Check The Convenient Coupon Below For Awesome Savings!
Utilizing PhantomJS is an excellent software-based method to accomplish multiple tasks on your dedicated server. Leveraging one of our Virtual dedicated servers would be the perfect fit for this use,
Related Articles:
- ChatGPT Integration — How to Create a Plugin for ChatGPT
- Stable Diffusion AI Image Generator (SDXL) — Using the Web UI
- How to Install VMware Tools on Ubuntu: Step-by-Step Guide
- How to Install WordPress on Linux (AlmaLinux)
- What is CentOS? Everything You Need to Know
- Virtual Desktop Environment — Configuring Kasm Workspaces
About the Author: Denis Bosack
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Install WordPress on Linux (AlmaLinux)
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleRedis as Cache: How It Works and Why You Should Use It
Read ArticleRefer-a-Friend Program for Website Hosting: Get $100 for Each Friend!
Read Article