How to setup LibreNMS on Ubuntu 17.04

This is going to explain how to setup LibreNMS on an Ubuntu 17.04 server. For a production server you should stick with Ubuntu 16.04 as that seems to be what LibreNMS supports. We are going to setup LibreNMS on a server with the following:
Server Version: 17.04 (Zesty Zapus)
Apache Version: Apache/2.4.25 (Ubuntu)
MariaDB Version: 15.1 Distrib 10.1.22-MariaDB
PHP Version: 7.0.18

root@stupiderror:~# apt install apache2 fping git graphviz imagemagick libapache2-mod-fcgid libsnmp-dev mariadb-server mariadb-client mtr-tiny nmap php-cli php-curl php-fpm php-gd php-json php-mcrypt php-mysql php-pear php-snmp python-mysqldb php-net-ipv6 rrdcached rrdtool snmp snmpd whois
root@stupiderror:~# pear install Net_IPV4

LibreNMS needs php-net-ipv4 but this isn’t in the Zesty repositories. Instead we use pear to install it.
Next we will enable the apache modules and then create a database for LibreNMS.

root@stupiderror:~# a2enmod rewrite expires proxy_fcgi setenvif
root@stupiderror:~# a2enconf php7.0-fpm
root@stupiderror:~# phpenmod mcrypt
root@stupiderror:~# systemctl reload apache2.service
root@stupiderror:~# mysql -u root -p
Enter password:  (if you just installed hit enter to continue, no password has been set yet)
MariaDB [(none)]> create database librenms character set utf8 collate utf8_unicode_ci;
MariaDB [(none)]> create user 'librenms'@'localhost' identified by 'uniquepass';
MariaDB [(none)]> grant all privileges on librenms.* to 'librenms'@'localhost';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit

Edit /etc/mysql/mariadb.conf.d/50-server.cnf and add the following lines in bold under the [mysqld] section.

# this is only for the mysqld standalone daemon


# * Basic Settings

Create a librenms user, create folder structure and clone the git repository to install LibreNMS.

root@stupiderror:~# useradd librenms -d /opt/librenms -M -r
root@stupiderror:~# usermod -a -G librenms www-data
root@stupiderror:~# cd /opt
root@stupiderror:/opt# git clone librenms
root@stupiderror:/opt# cd librenms/
root@stupiderror:/opt/librenms# mkdir rrd logs
root@stupiderror:/opt/librenms# chmod 755 rrd

Create an apache site configuration file for Librenms

root@stupiderror:/opt/librenms# vi /etc/apache2/sites-available/librenms.conf

  DocumentRoot /opt/librenms/html
  CustomLog /opt/librenms/logs/access_log combined
  ErrorLog /opt/librenms/logs/error_log
  AllowEncodedSlashes NoDecode
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

Setup SNMP v3 authentication

root@stupiderror:/opt/librenms# systemctl stop snmpd.service 
root@stupiderror:/opt/librenms# net-snmp-config --create-snmpv3-user -ro -a authPass -x privPass -X AES -A SHA librenms
root@stupiderror:/opt/librenms# curl -o /usr/bin/distro
root@stupiderror:/opt/librenms# chmod +x /usr/bin/distro

Edit /etc/snmp/snmpd.conf and comment out the two lines with the default public string. Then scroll down to find the extend entries and comment out the tests and add the line with distro.

# rocommunity public  default    -V systemonly
# rocommunity6 public  default   -V systemonly

# extend    test1   /bin/echo  Hello, world!
# extend-sh test2   echo Hello, world! ; echo Hi there ; exit 35
#extend-sh test3   /bin/sh /tmp/shtest
extend distro /usr/bin/distro

Restart SNMPD, enable LibreNMS site, disable default site, setup maintenance tasks, and chown the LibreNMS files to librenms user and group.

root@stupiderror:/opt/librenms# systemctl start snmpd.service
root@stupiderror:/opt/librenms# a2ensite librenms.conf
root@stupiderror:/opt/librenms# a2dissite 000-default.conf
root@stupiderror:/opt/librenms# systemctl reload apache2.service
root@stupiderror:/opt/librenms# cp librenms.nonroot.cron /etc/cron.d/librenms
root@stupiderror:/opt/librenms# cp misc/librenms.logrotate /etc/logrotate.d/librenms
root@stupiderror:/opt/librenms# chown -R librenms:librenms /opt/librenms

Now open your browser and go to install.php at your site, in my example I go to
All your PHP modules should be installed so you can click Next Stage
Fill in the password for the database you created for LibreNMS and click Next Stage.
Now you should see a status page, mine went to Step #96 and then updated the schema which went to 195. On the last line it says — Done. Click on Goto Add User
Create a user by filling in the info you want to use and click Add User.
Click Generate Config
Copy the config and save it to /opt/librenms/config.php and click Finish Install

Edit /opt/librenms/html/.htaccess and change the last RewriteRule which should like
RewriteRule ^(.*)$ index.php/$1/
change it to:
RewriteRule ^(.*)$ index.php

To enable RRDCached edit /opt/librenms/config.php and uncomment the following line:
$config[‘rrdcached’] = “unix:/var/run/rrdcached.sock”;

Edit /etc/default/rrdcached and modify the following lines like so:


root@stupiderror:/opt/librenms# systemctl restart rrdcached.service

Lets finish up with adding the LibreNMS server as a device to be monitored.
Log in to your LibreNMS web portal. Go to Device > Add Device
Fill in the following:
SNMP Version: v3
Port: 161

(Previously we used the net-snmp-config to add a user and credentials, I’m going to use the same values as I did above but hopefully you created your own credentials)
Auth Level: authPriv
Auth User Name: librenms
Auth Password: authPass
Auth Algorithm: SHA
Crypto Password: privPass
Crypto Algorithm: AES

Click Add Device