Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install LibreNMS with Apache on Ubuntu 24.04

How to Install LibreNMS with Apache on Ubuntu 24.04

Setting up LibreNMS with Apache on Ubuntu 24.04 provides a powerful, open-source network monitoring solution that helps administrators keep track of their network devices, servers, and services in real-time. This guide walks you through the entire installation process, ensuring your monitoring setup is both secure and reliable. Before you begin, ensure your server is up to date and has a fresh Ubuntu 24.04 installation. You will also need root or sudo privileges to install and configure the necessary components.

What You’ll Need

  • Ubuntu 24.04 Server installed and updated
  • Root or sudo access
  • Basic familiarity with Linux command line
  • Domain name or static IP address (optional but recommended)
  • SSL certificate (optional for HTTPS setup)

Step-by-Step

  1. Update your system: Begin by updating your package list and upgrading installed packages to ensure compatibility.
    sudo apt update && sudo apt upgrade -y
  2. Install required dependencies: LibreNMS requires several packages including PHP, MySQL, and other utilities.
    sudo apt install software-properties-common curl git unzip -y
  3. Install and Configure MariaDB (MySQL): LibreNMS uses MariaDB as its database.
    sudo apt install mariadb-server -y
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    
    # Secure MariaDB installation
    sudo mysql_secure_installation
    # Follow the prompts to set root password and secure installation
    
  4. Create LibreNMS Database and User: Log into MariaDB and set up the database.
    sudo mysql -u root -p
    CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'your_secure_password';
    GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  5. Install PHP and necessary PHP modules: LibreNMS relies heavily on PHP.
    sudo add-apt-repository ppa:ondrej/php -y
    sudo apt update
    sudo apt install php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-gd php8.2-mbstring php8.2-xml php8.2-bcmath php8.2-curl php8.2-intl php8.2-zip -y
  6. Configure PHP for LibreNMS: Adjust PHP settings for optimal performance.
    sudo nano /etc/php/8.2/fpm/php.ini
    # Set the following values:
    max_execution_time = 300
    memory_limit = 512M
    upload_max_filesize = 64M
    post_max_size = 64M
    date.timezone = Your/Timezone
    # Save and exit
    
    # Restart PHP-FPM
    sudo systemctl restart php8.2-fpm
  7. Download and install LibreNMS: Clone the LibreNMS repository and set permissions.
    sudo useradd -r -M -d /opt/librenms -s /bin/bash librenms
    sudo mkdir -p /opt/librenms
    sudo chown -R librenms: /opt/librenms
    sudo chmod 775 /opt/librenms
    
    # Clone the repository
    sudo -u librenms git clone https://github.com/librenms/librenms.git /opt/librenms
    
  8. Configure the database connection: Copy example config and edit.
    sudo cp /opt/librenms/config.php.default /opt/librenms/config.php
    sudo nano /opt/librenms/config.php
    # Enter your database details:
    $config['db_host'] = 'localhost';
    $config['db_name'] = 'librenms';
    $config['db_user'] = 'librenms';
    $config['db_pass'] = 'your_secure_password';
    # Save and exit
    
  9. Install Composer dependencies: LibreNMS uses Composer for PHP package management.
    cd /opt/librenms
    sudo -u librenms composer install --no-dev
  10. Configure Apache: Set up a new site configuration.
    sudo nano /etc/apache2/sites-available/librenms.conf
    # Add the following configuration:
    
        ServerName your.domain.com
        DocumentRoot /opt/librenms/html
        
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        
        ErrorLog ${APACHE_LOG_DIR}/librenms_error.log
        CustomLog ${APACHE_LOG_DIR}/librenms_access.log combined
    
    
    # Enable site and rewrite module
    sudo a2ensite librenms.conf
    sudo a2enmod rewrite
    sudo systemctl restart apache2
  11. Set permissions for web server: Ensure Apache can access LibreNMS files.
    sudo chown -R www-data:www-data /opt/librenms
  12. Complete the web installer: Navigate to http://your.domain.com in your browser.
    – Follow the on-screen instructions to complete configuration.
    – Enter database details and create an admin user.
    – Set up SNMP and alert preferences as needed.
  13. Configure Cron jobs: Enable regular polling and discovery.
    sudo -u librenms bash -c 'crontab -e'
    # Add the following lines:
    * * * * * /opt/librenms/poller-wrapper.py 1
    * * * * * /opt/librenms/discovery-wrapper.py
    * * * * * /opt/librenms/alerts.php
    # Save and exit
  14. Secure your installation: Set up SSL for HTTPS access.
    – Obtain a certificate via Let’s Encrypt or other CA.
    – Configure Apache to use SSL.
    – Redirect HTTP to HTTPS for security.

Common Mistakes

  • Failing to set correct permissions: Ensure LibreNMS files are owned by the web server user (www-data) and have proper permissions to avoid access issues.
  • Incorrect database credentials: Double-check your config.php entries to prevent connection errors.
  • Missing dependencies: Install all PHP modules and dependencies before proceeding; missing packages can cause installation failures.
  • Not enabling required Apache modules: Rewrite and headers modules are essential for proper operation.
  • Skipping security steps: Always secure your MariaDB and enable SSL for production environments.

Tips

  • Use a domain name instead of IP for easier SSL setup and cleaner access.
  • Regularly update LibreNMS to benefit from security patches and new features.
  • Configure alerts and notifications early to monitor your network effectively.
  • Back up your database and configuration files regularly, especially before upgrades.
  • Enable HTTPS with a valid SSL certificate to encrypt traffic and protect sensitive data.

Troubleshooting

If LibreNMS does not load properly or encounters errors:

  • Check Apache error logs: Review /var/log/apache2/error.log for clues.
  • Verify database connection: Test connection using MySQL client with the credentials in config.php.
  • Ensure PHP modules are enabled: Confirm all required PHP modules are installed and active.
  • Check permissions: Make sure files and directories are accessible by the web server.
  • Run the web installer again: Sometimes, reloading the setup page helps if configurations have changed.
  • Clear browser cache or try incognito mode: To avoid loading cached errors.

When issues persist, consult the LibreNMS community forums or documentation for specific error messages.

Frequently Asked Questions

1. Can I run LibreNMS with Nginx instead of Apache?

Yes, LibreNMS supports Nginx. However, this guide covers Apache installation. Nginx setup involves different configuration steps, particularly for PHP-FPM and URL rewriting.

2. Is SSL mandatory for LibreNMS?

While not strictly required, enabling SSL is highly recommended to secure your network monitoring data, especially if accessible over the internet.

3. How often should I run polling and discovery?

Polling typically runs every minute, and discovery every 5-10 minutes, but you can customize these intervals based on your network size and needs.

4. Can I install LibreNMS on a virtual machine?

Absolutely. LibreNMS runs well on VM environments, provided the VM has enough resources and network connectivity.

5. How do I upgrade LibreNMS later?

Upgrade by pulling the latest code from the repository and updating dependencies with Composer, then running database migrations as needed.

6. What are best practices for securing LibreNMS?

Secure your database, use HTTPS, restrict access via firewalls, keep software updated, and regularly back up your data.

Related

How to Install LibreNMS with Apache on Ubuntu 24.04
Scroll to top