There was a problem for me after publishing the vnStat PHP article, it’s vnStat console could not update its database automatically. The result was vnStat PHP cannot update the data automatically as well. The cause is probably because I accidentally ran vnstat update as root. But apparently the solution is easy. Just make the user of vnstatd daemon the owner of the database directory.
See The User
Actually, when vnStat console being installed, it creates a new user named vnstat in our system. This is the user that runs our vnstatd daemon and updates the database. You can see it by command below. See the most left column, that’s the username: “vnstat”.
$ ps aux | grep vnstat
The problem is whether the database directory is owned by vnstat user or not. When it’s not, of course vnstat console cannot update the traffic data unless we force it manually with sudo (or by root).
Do chown to /var/lib/vnstat/ directory (where databases are stored) so it and its files re-owned by vnstat user.
$ sudo chmod -v -R vnstat:vnstat /var/lib/vnstat/
You should see that the vnstat/ directory itself, and all files inside it, are owned by same user “vnstat”. See them by command below.
$ ls alR /var/lib/vnstat/