I have just spent a few hours setting up Nagios on my FreeBSD VM. It did not go as smoothly as I expected, and the advice as to what is needed is scattered all over the place.
If you are in to yet another layer of software
https://hub.docker.com/r/manios/nagios is a packaged Nagios Core with supported architectures: x86, amd64, arm/v6, arm/v7, arm64. This might be easier. Or might not.
Here is what I installed, with * marking explicit installs, the rest being dependencies. Note the definite need to install mod_php and possibly php gd.
The FreeBSD Nagios port maintainers did not want to make Nagios dependent upon Apache (other CGI supporting web servers may be available) so there are these gotchas.
The bits of the package names after the final "-" and the "php74-" prefixes are a feature of the FreeBSD pkg system.
apr-1.7.0.1.6.1_1
*apache24-2.4.52
libargon2-20190702
pcre2-10.39
giflib-5.2.1
php74-7.4.27
webp-1.2.1
php74-xml-7.4.27
php74-filter-7.4.27
nagios-plugins-2.3.3_2,1
libgd-2.3.1,1
libltdl-2.4.6
*nagios4-4.4.6_1,1
*mod_php74-7.4.27
*php74-gd-7.4.27
Here are the changes to my Apache configuration
[aw1@titus .../local/etc/apache24]$ diff -u httpd.conf.sample httpd.conf
--- httpd.conf.sample 2022-01-02 01:31:45.000000000 +0000
+++ httpd.conf 2022-01-18 08:19:00.218439000 +0000
@@ -163,10 +163,10 @@
#LoadModule asis_module libexec/apache24/mod_asis.so
#LoadModule info_module libexec/apache24/mod_info.so
<IfModule !mpm_prefork_module>
- #LoadModule cgid_module libexec/apache24/mod_cgid.so
+ LoadModule cgid_module libexec/apache24/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
- #LoadModule cgi_module libexec/apache24/mod_cgi.so
+ LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>
#LoadModule dav_fs_module libexec/apache24/mod_dav_fs.so
#LoadModule dav_lock_module libexec/apache24/mod_dav_lock.so
@@ -179,6 +179,7 @@
#LoadModule userdir_module libexec/apache24/mod_userdir.so
LoadModule alias_module libexec/apache24/mod_alias.so
#LoadModule rewrite_module libexec/apache24/mod_rewrite.so
+LoadModule php7_module libexec/apache24/libphp7.so
# Third party modules
IncludeOptional etc/apache24/modules.d/[0-9][0-9][0-9]_*.conf
@@ -214,7 +215,7 @@
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
-ServerAdmin you@example.com
+ServerAdmin aw1
#
# ServerName gives the name and port that the server uses to identify itself.
@@ -281,7 +282,7 @@
# is requested.
#
<IfModule dir_module>
- DirectoryIndex index.html
+ DirectoryIndex index.html index.php
</IfModule>
#
@@ -535,4 +536,41 @@
</IfModule>
Include etc/apache24/Includes/*.conf
+
+# nagios
+<Directory /usr/local/www/nagios>
+#Require ip 127.0.0.1
+php_flag engine on
+php_admin_value open_basedir /usr/local/www/nagios/:/var/spool/nagios/
+Options None
+AllowOverride None
+Order allow,deny
+Allow from all
+AuthName "Nagios Access"
+AuthType Basic
+AuthUSerFile /usr/local/etc/nagios/htpasswd.users
+Require valid-user
+</Directory>
+
+<Directory /usr/local/www/nagios/cgi-bin>
+Options ExecCGI
+AllowOverride None
+Order allow,deny
+Allow from all
+AuthName "Nagios Access"
+AuthType Basic
+AuthUSerFile /usr/local/etc/nagios/htpasswd.users
+Require valid-user
+</Directory>
+
+ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/
+Alias /nagios/ /usr/local/www/nagios/
+
+# PHP
+<FilesMatch "\.php$">
+ SetHandler application/x-httpd-php
+</FilesMatch>
+<FilesMatch "\.phps$">
+ SetHandler application/x-httpd-php-source
+</FilesMatch>
Hope this helps.