How to Install Nagios 4 in Ubuntu and Debian

In this topic we’ll learn how to install and configure the latest official version of Nagios Core from sources in Debian and Ubuntu servers.

Nagios Core is a free Open Source network monitoring application designed for monitoring network applications, devices and their related services and in a network.

Nagios can remotely monitor specific operating system parameters via agents deployed on nodes and send alerts via mail or SMS in order to notify administrators in case critical services in a network, such as SMTP, HTTP, SSH, FTP and other fails.


  1. Debian 9 Minimal Installation
  2. Ubuntu 16.04 Minimal Installation

Step 1: Install Pre-requirements for Nagios

1. Before installing Nagios Core from sources in Ubuntu or Debian, first install the following LAMP stack components in your system, without MySQL RDBMS database component, by issuing the below command.

# apt install apache2 libapache2-mod-php7.0 php7.0

2. On the next step, install the following system dependencies and utilities required to compile and install Nagios Core from sources, by issuing the follwoing command.

# apt install wget unzip zip autoconf gcc libc6 make apache2-utils libgd-dev

Step 2: Install Nagios 4 Core in Ubuntu and Debian

3. On the first step, create nagios system user and group and add nagios account to the Apache www-data user, by issuing the below commands.

# useradd nagios
# usermod -a -G nagios www-data

4. After all dependencies, packages and system requirements for compiling Nagios from sources are present in your system, go to Nagios webpage and grab the latest version of Nagios Core stable source archive by issuing the following command.

# wget

5. Next, extract Nagios tarball and enter the extracted nagios directory, with the following commands. Issue ls command to list nagios directory content.

# tar xzf nagios-4.3.4.tar.gz # cd nagios-4.3.4/
# ls

List Nagios Content

6. Now, start to compile Nagios from sources by issuing the below commands. Make sure you configure Nagios with Apache sites-enabled directory configuration by issuing the below command.

# ./configure --with-httpd-conf=/etc/apache2/sites-enabled

7. In the next step, build Nagios files by issuing the following command.

# make all

8. Now, install Nagios binary files, CGI scripts and HTML files by issuing the following command.

# make install

9. Next, install Nagios daemon init and external command mode configuration files and make sure you enable nagios daemon system-wide by issuing the following commands.

# make install-init
# make install-commandmode
# systemctl enable nagios.service

10. Next, run the following command in order to install some Nagios sample configuration files needed by Nagios to run properly by issuing the below command.

# make install-config

11. Also, install Nagios configuration file for Apacahe web server, which can be fount in /etc/apacahe2/sites-enabled/ directory, by executing the below command.

# make install-webconf

12. Next, create nagiosadmin account and a password for this account necessary by Apache server to log in to Nagios web panel by issuing the following command.

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

13. To allow Apache HTTP server to execute Nagios cgi scripts and to access Nagios admin panel via HTTP, first enable cgi module in Apache and then restart Apache service and start and enable Nagios daemon system-wide by issuing the following commands.

# a2enmod cgi
# systemctl restart apache2
# systemctl start nagios
# systemctl enable nagios

14. Finally, log in to Nagios Web Interface by pointing a browser to your server’s IP address or domain name at the following URL address via HTTP protocol. Log in to Nagios with nagiosadmin user the password setup with htpasswd script.


Nagios Admin Login

Nagios Core Dashboard

15. To view your hosts status, navigate to Current Status -> Hosts menu where you will notice that some errors are displayed for localhost host, as illustrated in the below screenshot. The error appears because Nagios has no plugins installed to check hosts and services status.

Check Host Status

Step 3: Install Nagios Plugins in Ubuntu and Debian

16. To compile and install Nagios Plugins from sources in Debian or Ubuntu, at the first stage, install the following dependencies in your system, by issuing the below command.

# apt install libmcrypt-dev make libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext libldap2-dev smbclient fping libmysqlclient-dev qmail-tools libpqxx3-dev libdbi-dev 

17. Next, visit Nagios Plugins repositories page and download the latest source code tarball by issuing the following command.

# wget 

18. Go ahead and extract the Nagios Plugins source code tarball and change path to the extracted nagios-plugins directory by executing the following commands.

# tar xfz release-2.2.1.tar.gz # cd nagios-plugins-release-2.2.1/

19. Now, start to compile and install Nagios Plugins from sources, by executing the following series of commands in your server console.

# ./tools/setup # ./configure # make
# make install

20. The compiled and installed Nagios plugins can be located in /usr/local/nagios/libexec/ directory. List this directory to view all available plugins in your system.

# ls /usr/local/nagios/libexec/

Nagios Plugins Directory

21. Finally, restart Nagios daemon in order to apply the installed plugins, by issuing the below command.

# systemctl restart nagios.service

22. Next, log in to Nagios web panel and go to Current Status -> Services menu and you should notice all hosts services are checked now by Nagios plugins.

From the color code you should see the current services status: green color is for OK status, yellow for Warning and red for Critical status.

Check Host Services

23. Finally, to access Nagios admin web interface via HTTPS protocol, issue the following commands to enable Apache SSL configurations and restart the Apache daemon to reflect changes.

# a2enmod ssl # a2ensite default-ssl.conf
# systemctl restart apache2

24. After you’ve enabled Apache SSL configurations, open /etc/apache2/sites-enabled/000-default.conf file for editing and add the following block of code after DocumentRoot statement as shown in the below excerpt.

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/$1

Configure Apache for Nagios

25. You need to restart Apache daemon to apply the configured rules, by issuing the below command.

# systemctl restart apache2.service 

26. Finally, refresh the browser in order to be redirected to Nagios admin panel via HTTPS protocol. Accept the wanting message that gets displayed in the browser and log in to Nagios again with the your credentials.

Nagios HTTPS Dashboard

Congratulations! You have successfully install and configured Nagios Core monitoring system from sources in Ubuntu server or Debian 9.

Spread the love

Posted by News Monkey