sudo -i 

apt install software-properties-common
add-apt-repository universe  "Run If Using Ubuntu"

apt update

apt install rrdtool snmp snmpd whois python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd

apt install acl curl apache2 composer fping git graphviz imagemagick libapache2-mod-fcgid mariadb-client mariadb-server mtr-tiny nmap 

apt install php7.3-cli php7.3-curl php7.3-fpm php7.3-gd php7.3-json php7.3-mbstring php7.3-mysql php7.3-snmp php7.3-xml php7.3-zip

Add User: 

useradd librenms -d /opt/librenms -M -r -s "$(which bash)"

Let's Download LibreNMS Software:

cd /opt
git clone https://github.com/librenms/librenms.git

Setting Permissions:
Do Each Line One At A Time:

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 PHP:
Do Each Line One At A Time:

su - librenms
./scripts/composer_wrapper.php install --no-dev
exit

Let's Set The Time Zone:
Each File Will Need The Time Zone Added:

nano /etc/php/7.3/fpm/php.ini
nano /etc/php/7.3/cli/php.ini

Here’s The Website For Time Zone Information: Click Here

Set System Time Zone:

#timedatectl set-timezone Etc/UTC

Run The Following Command To Edit The File:

nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add The Two Line Below, Under The [mysqld] Section And Save:

innodb_file_per_table=1
lower_case_table_names=0

Let's Enable And Restart The DB:

systemctl enable mariadb
systemctl restart mariadb

Now Login Into Mysql:

mysql -u root

Run Each Line One At A Time:
Replace The Word password In Second Line To You Login Password:

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';
FLUSH PRIVILEGES;
exit

Copy Some Things:

cp /etc/php/7.3/fpm/pool.d/www.conf /etc/php/7.3/fpm/pool.d/librenms.conf

Let's Make A Few Changes In The Following File:

nano /etc/php/7.3/fpm/pool.d/librenms.conf

Change The Following:

Change [www] To [librenms]

Change User And Group:

user = librenms
group = librenms

Change Listen Line To:

listen = /run/php-fpm-librenms.sock

Let's Add A Few Lines In The Following File:

nano /etc/apache2/sites-available/librenms.conf

Paste The Following:

<VirtualHost *:80>
  DocumentRoot /opt/librenms/html/
  ServerName  librenms.example.com  

  AllowEncodedSlashes NoDecode
  <Directory "/opt/librenms/html/">
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>

  # Enable http authorization headers
  <IfModule setenvif_module>
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
  </IfModule>

  <FilesMatch ".+\.php$">
    SetHandler "proxy:unix:/run/php-fpm-librenms.sock|fcgi://localhost"
  </FilesMatch>
</VirtualHost>

Now Let's Run The Following Commands:

a2dissite 000-default
a2enmod proxy_fcgi setenvif rewrite
a2ensite librenms.conf
systemctl restart apache2
systemctl restart php7.3-fpm

Enable LNMS:

ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Configure snmpd:

cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

Let's Edit The Following File:

nano /etc/snmp/snmpd.conf

Replace RANDOMSTRINGGOESHERE With Something Different
Now Run Once Line One At A Time:

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

Setup A Cron Job:

cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms

To Rotate Old Logs:

cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms