CentOS / RHEL: View Vnstat Graphs Using PHP Web Interface Frontend

How do Install view vnstat – a network console output using my web-browser? How do I install vnstat php frontend on CentOS / RHEL / Fedora Linux based system?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
RequirementsApache 2.x+ / PHP 5.x+
CentOS/ SL / Fedora/ RHEL
TimeN/A
You can use a PHP fronted for vnStat called “vnStat php frontend”. This script was created as vnstat is console mode only and the author wanted to make a nice report of the data collected by vnStat. You need to install the following software(s) on your server:

ADVERTISEMENTS

[a] Apache

[b] PHP 5

[c] php-gd extension

You can install all of the above softwares using the yum command:
# yum install httpd php php-gd
Configure httpd service as per your requirements:
# vi /etc/httpd/conf/httpd.conf
Turn on the httpd service:
# chkconfig httpd on
# service httpd start
# netstat -tulpn | grep :80

Download vnStat php frontend

Visit this url and grab the latest version using the wget command:
$ cd /tmp
$ wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz

Untar or extract the tarball (tar file) called vnstat_php_frontend-1.5.1.tar.gz, type:
$ tar xvf vnstat_php_frontend-1.5.1.tar.gz

Install vnStat php frontend

You need to install this frontend at the following location:
/var/www/html/vnstat/
Make a directory called /var/www/html/vnstat/ using mkdir command:
# mkdir -p /var/www/html/vnstat/
Copy files from /tmp/vnstat_php_frontend-1.5.1 to /var/www/html/vnstat using cp command, enter:
# cp -av /tmp/vnstat_php_frontend-1.5.1/* /var/www/html/vnstat
If you are using SELinux, restore file(s) default SELinux security contexts using restorecon command:
# restorecon -Rv /var/www/html/vnstat/

Configure vnStat php frontend

You need to edit /var/www/html/vnstat/config.php, enter:
# vi /var/www/html/vnstat/config.php
You need to edit this file to reflect your particular situation. First, set language to en:

$language = 'en';

I am monitoring eth0 and eth1. So list of network interfaces monitored by vnStat should be set using the following:

$iface_list = array('eth0', 'eth1');

You can set names for interfaces:

$iface_title['eth0'] = 'Internal';
$iface_title['eth1'] = 'External';

Save and close the file.

How do I view graphs?

Fire a web browser and type the url:

http://your-server-ip-address-here/vnstat/
http://localhost/vnstat/
http://server1.cyberciti.biz/vnstat/
http://192.168.1.100/vnstat/

Sample outputs:

Fig.01: vnstat network summary graph

Fig.01: vnstat network summary graph

Fig.02: vnstart daily traffic graphs

Fig.02: vnstart daily traffic graphs

Fig.03: vnstat monthly network traffic log

Fig.03: vnstat monthly network traffic log

Check out related media

This tutorial is also available in a video format:



(Video.01: Demo: Setup and use vnStat )

This entry is 2 of 5 in the vnStat Monitor and Log Network Traffic Tutorial series. Keep reading the rest of the series:
  1. How to install vnstat on a CentOS/RHEL/Fedora Linux
  2. View Vnstat Graphs Using PHP Web Interface Frontend
  3. How to install vnstat on FreeBSD Unix server
  4. Fedora Linux install vnstat network traffic monitor
  5. Ubuntu install vnstat console network traffic monitor
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
6 comments… add one
  • Jalal Hajigholamali Nov 21, 2012 @ 4:53

    Hi,

    Thanks….
    very nice article…

  • Andres Nov 24, 2012 @ 13:44

    Nice tool for customers meetings :-)

  • Shashank Wagh Dec 1, 2012 @ 11:56

    This blog has great essence of technical knowledge. This is awesome. Thanx for penning down your experience. Thanx once again. I’ve been reading many web hosting blogs, web development blogs, but I believe this one stands tall.

  • galihrezah Jul 15, 2013 @ 4:49

    i will try on my vps.. and i will share
    thanks for inspiration

  • dkraft Jan 30, 2014 @ 13:50

    This works flawlessly. Thank you for your excellence.

  • foobrew May 27, 2014 @ 23:56

    Might want to make sure you have your date.timezone set correctly in /etc/php.ini

    http://us3.php.net/manual/en/datetime.configuration.php#ini.date.timezone

    For example,

    date.timezone = “America/Los_Angeles”

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.