Monitor Your Devices Using LibreNMS on AlmaLinux 9 and Rocky Linux 9
Step-by-step LibreNMS installation on AlmaLinux 9 or Rocky Linux 9 with Nginx, PHP-FPM, MariaDB, SELinux rules and SNMP.
LibreNMS is an open-source network monitoring system that discovers and polls routers, switches, firewalls and servers over SNMP, draws graphs and sends alerts. This guide installs it on AlmaLinux 9 or Rocky Linux 9 with Nginx, PHP-FPM and MariaDB, following the project's own installation procedure, and ends with the first device added.
Older tutorials on this topic used CentOS 7, which is end-of-life and far too old for current LibreNMS: the project now requires PHP 8.4 as a minimum and recommends PHP 8.5. Its install documentation covers RHEL derivatives in versions 8, 9 and 10, plus Ubuntu 24.04/26.04 and Debian 12/13.
Requirements
- A server running AlmaLinux 9 or Rocky Linux 9 with root or
sudoaccess. The commands below are written for a root shell; start one withsudo -i. - A DNS name pointing to the server. The examples use
librenms.example.com. - Devices that answer SNMP queries from this server.
Step 1: Install the packages
RHEL 9 does not ship a new enough PHP, so the LibreNMS documentation uses the Remi repository for PHP 8.5, together with EPEL:
dnf -y install epel-release
dnf -y install dnf-utils https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf -y module reset php
dnf -y module enable php:remi-8.5
dnf -y install bash-completion cronie fping gcc git mariadb-server mtr net-snmp net-snmp-utils nmap php-fpm php-cli php-common php-curl php-gd php-gmp php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd policycoreutils-python-utils python3 python3-devel python3-PyMySQL python3-redis python3-memcached python3-pip python3-systemd rrdtool unzip
dnf -y install nginx
Step 2: Create the user and download LibreNMS
useradd librenms -d /opt/librenms -M -r -s "$(which bash)"
cd /opt
git clone https://github.com/librenms/librenms.git
Set ownership and the ACLs that let the web server and the poller share the data directories:
chown -R librenms:librenms /opt/librenms
chmod 771 /opt/librenms
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
Install the PHP dependencies as the librenms user, then return to root:
su - librenms
./scripts/composer_wrapper.php install --no-dev
exit
Step 3: Set the time zone
PHP and the system must use the same time zone or graphs are shifted. Open /etc/php.ini, find the date.timezone line, remove the leading semicolon and set your zone, for example:
date.timezone = Etc/UTC
Set the same zone for the system:
timedatectl set-timezone Etc/UTC
Step 4: Configure MariaDB
Edit /etc/my.cnf.d/mariadb-server.cnf and add two lines inside the [mariadb] section:
innodb_file_per_table=1
lower_case_table_names=0
Start the database and open a client:
systemctl enable mariadb
systemctl restart mariadb
mysql -u root
Create the database and user. Replace password with a strong password and keep it for the web installer:
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit
Step 5: Configure PHP-FPM and Nginx
Give LibreNMS its own PHP-FPM pool:
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/librenms.conf
Edit /etc/php-fpm.d/librenms.conf: change the pool name [www] to [librenms] and set these values:
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock
Create /etc/nginx/conf.d/librenms.conf with your own server_name:
server {
listen 80;
server_name librenms.example.com;
root /opt/librenms/html;
index index.php;
charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/run/php-fpm-librenms.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi.conf;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
If LibreNMS is the only site on this server, delete the default server { ... } block from /etc/nginx/nginx.conf. Then start both services:
systemctl enable --now nginx
systemctl enable --now php-fpm
Step 6: SELinux and firewall
SELinux is enforcing by default on the RHEL 9 family. Label the LibreNMS directories and allow the web server what it needs:
semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/html(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/(rrd|storage)(/.*)?'
semanage fcontext -a -t httpd_log_t "/opt/librenms/logs(/.*)?"
semanage fcontext -a -t httpd_cache_t '/opt/librenms/cache(/.*)?'
semanage fcontext -a -t bin_t '/opt/librenms/librenms-service.py'
restorecon -RFvv /opt/librenms
setsebool -P httpd_can_sendmail=1
setsebool -P httpd_execmem 1
setsebool -P httpd_can_network_connect_db 1
chcon -t httpd_sys_rw_content_t /opt/librenms/.env
The web interface also runs fping, which needs a small policy module. Create a file named http_fping.tt in any directory:
module http_fping 1.0;
require {
type node_t;
type httpd_t;
class capability net_raw;
class icmp_socket create;
class rawip_socket { getopt create setopt write read bind node_bind };
}
#============= httpd_t ==============
allow httpd_t node_t:rawip_socket node_bind;
allow httpd_t self:capability net_raw;
allow httpd_t self:icmp_socket create;
allow httpd_t self:rawip_socket { getopt create setopt write read bind };
Compile and load it, then open the firewall for web traffic:
checkmodule -M -m -o http_fping.mod http_fping.tt
semodule_package -o http_fping.pp -m http_fping.mod
semodule -i http_fping.pp
firewall-cmd --zone public --add-service http --add-service https
firewall-cmd --permanent --zone public --add-service http --add-service https
Step 7: SNMP, cron, scheduler and log rotation
Make the lnms command available system-wide with tab completion:
ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
Configure the local SNMP daemon so the server can monitor itself. Copy the sample file, then edit it and replace RANDOMSTRINGGOESHERE with your own community string:
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
vi /etc/snmp/snmpd.conf
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
systemctl enable snmpd
systemctl restart snmpd
Install the cron job that polls devices, the systemd timer for scheduled tasks and the logrotate rule:
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
chmod 644 /etc/cron.d/librenms
cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
systemctl enable librenms-scheduler.timer
systemctl start librenms-scheduler.timer
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
chmod 644 /etc/logrotate.d/librenms
Step 8: Run the web installer
Open http://librenms.example.com/install in a browser and follow the screens: the pre-install checks, the database credentials from step 4, and the first administrator account. If the installer asks you to create config.php by hand, paste the text it shows into /opt/librenms/config.php and fix the owner:
chown librenms:librenms /opt/librenms/config.php
Verify the installation and add a device
Run the built-in validation as the librenms user. It tests the database, permissions, poller and versions, and prints the exact command to fix anything it finds:
su - librenms
./validate.php
If SELinux still blocks something, audit2why < /var/log/audit/audit.log explains the denials. Then log in to the web interface and add localhost as the first device, using the community string from step 7. Other devices are added the same way with their host name or IP address and SNMP details; graphs appear after the first few polling cycles.
Security and maintenance
- This procedure leaves the site on plain HTTP. Configure a TLS certificate in Nginx before the server is reachable from the internet, and restrict who can reach it.
- Back up
/opt/librenms/.env. It contains theAPP_KEYused to encrypt stored credentials; without it, encrypted data in a database backup cannot be recovered. - Back up the
librenmsdatabase and the/opt/librenms/rrddirectory, which holds all graph data. - Prefer SNMPv3 with authentication and encryption over v2c community strings where your devices support it.
The full reference, including the Apache variant and other operating systems, is the LibreNMS installation guide.
Frequently asked questions
Can I use the PHP version that comes with AlmaLinux or Rocky Linux 9?
No. The newest PHP stream in the RHEL 9 AppStream repository is 8.3, below the LibreNMS minimum of 8.4. That is why the official instructions enable PHP from the Remi repository.
Can I use Apache instead of Nginx?
Yes. On RHEL derivatives the LibreNMS documentation covers both; install httpd instead of nginx and use the virtual host from the official guide. The PHP-FPM pool and all other steps stay the same.
How do I move an existing CentOS 7 installation?
Build a new server as described here, then copy the database dump, the rrd directory, config.php and the .env file across. An in-place upgrade from CentOS 7 is not practical because of the PHP requirement.
Why are my graphs empty?
Usually the poller is not running or cannot write. Check that /etc/cron.d/librenms exists, that crond is active, and run ./validate.php, which reports poller and permission problems.