Tag Archives: Linux How to

Unix Similar multi-user operating systems based on the Linux kernel and essentially on GNU software. Like CentOS, Debian, Ubuntu Fedora.

Monitorix Network Diagrams Debian

Monitorix for powerful monitoring with system and network diagrams and graphs on Debian Linux. The open source lightweight tool regularly collects system and network data and displays the statistics in charts via its own web server in a browser web UI.

Monitorix enables monitoring of overall system performance and also helps detect bottlenecks, failures, unwanted delayed response times and other unusual activities.

Monitorix contains two programs: a collector as the program Monitorix, a Perl daemon that starts automatically as system service, and a CGI script called Monitorix.cgi.

Network diagrams with Monitorix in Debian

Monitorix is Open Soure and written in the Perl language and licensed under the GNU (General Public License) as published by the FSP (Free Software Foundation). The diagrams are created with the RRDtool and then displayed in a web UI.

The development of Monitorix is currently in an active state and new features are constantly being added. New charts and updates with bug fixes are offered for powerful monitoring for Debian and Linux system/network administration.

Monitorix Features

  • Average system load, active processes, kernel usage per processor, global kernel usage and memory allocation.
  • Monitors the temperatures and health of the hard drives.
  • File system usage and file system I/O activity.
  • Use of network traffic by up to 10 network devices.
  • System services include SSH, FTP, VSFTPd, ProFTP, SMTP, POP3, IMAP, POP3, ClamAV and SpamAssassin.
  • MTA mail statistics including incoming and outgoing connections.
  • Network port traffic including TCP, UDP, etc.
  • FTP statistics with log data from FTP servers.
  • Apache statistics from local or remote servers.
  • MySQL statistics from local or remote servers.
  • Squid proxy web cache statistics.
  • Fail2ban statistics in Monitorix network diagrams.
  • Monitoring remote servers (multihost).
  • Ability to view statistics in charts or in plain text tables by day, week, month or year.
  • Ability to define the number of charts per line.
  • Integrated HTTP server, Apache or Nginx is not mandatory.
  • Running on Debian GNU/Linux, Ubuntu, Red Hat, Fedora, Rocky Linux, AlmaLinux, Arch Linux and many more.

Monitorix Installation

To install the latest version of Monitorix for Network Diagrams, the package is provided from the Debian repository.

$ sudo apt install monitorix

After successful installation, the service can be started immediately. The system services to be monitored can be configured in the/etc/monitorix/monitorix.conffile to enable or disable and adding additional settings or charts.

For access control, a user with a password is created using htpasswd. If there is no Apache Web Server on the system, the “apache2-utils” package can be installed.

$ sudo apt install apache2-utils

After the package is deployed, htpasswd can be executed.

$ sudo htpasswd -d -c /var/lib/monitorix/htpasswd monitorix
New password:
Re-type new password:
Adding password for user monitorix

Now add the Monitorix service to the system startup and start the service with the following commands. For persistent set up Monitorix and network graphs on Debian Server.

$ sudo systemctl start monitorix.service
$ sudo systemctl enable monitorix.service

Checking for the status of the Monitorix service is as follows.

$ sudo systemctl status monitorix.service

Debian Linux Firewall for Monitorix

Monitorix is listeing on port 8080, which the kernel firewall controls with iptables or ufw. The iptables command to open TCP port 8080 inbound is as follows.

$ sudo iptables -A IN_public_allow -p tcp --dport 8080 -m state --state NEW,UNTRACKED -j ACCEPT

If ufw (Uncomplicated Firewall) is used, ran this command.

$ sudo ufw allow 8080/tcp

A different port can also be defined, for example because TCP 8080 is already in use, or you want to take the system out of the focus of curious network scanners that are targeting established services.

After Monitorix is started, the tool begins collecting system information for creating network diagrams according to the configuration specified in the /etc/monitorix/monitorix.conf file. After a few minutes, the diagrams will appear in the browser.

http://Server-IP:8080/monitorix/

Monitorix Landingpage

Monitorix System and Network Diagrams

After individual or all graphs have been selected, the Monitorix system and network diagrams appear after clicking OK.

Monitorix Network Diagrams Debian

Monitorix on several servers using as Multihost

If you want to use Monitorix on multiple servers, the network remote statistics diagrams can be viewed centrally, this is called Multihost feature.

Let’s say we want to collect the statistics of two servers with Monitorix. I’ll call these server1 from which we want to view both server diagrams, the second server is server2, which delivers the statistics data to server1.

The configuration on server1 in themonitorix.conffile in<httpd_builtin>section is as follows.

<httpd_builtin>
        enabled = y
        host =
        port = 8080
        user = nobody
        group = nobody
        log_file = /var/log/monitorix-httpd
        hosts_deny = all
        hosts_allow = 127.0.0.1, 203.3.113.0/24, 10.10.10.10
        <auth>
                enabled = y
                msg = Monitorix: Restricted access
                htpasswd = /var/lib/monitorix/htpasswd
        </auth>
</httpd_builtin>

Server1: /etc/monitorix/monitorix.conf

The configuration on server2 is as follows.

<httpd_builtin>
        enabled = y
        host =
        port = 8080
        user = nobody
        group = nobody
        log_file = /var/log/monitorix-httpd
        hosts_deny = all
        hosts_allow = 127.0.0.1, 203.3.113.0/24, 10.10.10.10
        <auth>
                enabled = n
                msg = Monitorix: Restricted access
                htpasswd = /var/lib/monitorix/htpasswd
        </auth>
</httpd_builtin>

Server2: /etc/monitorix/monitorix.conf

As we can see, the only difference from server1 to server2 is the option enabled n or y in the<auth>section. This will allow us to log in to server1 and view the diagrams from server2 as well.

Next set the configuration of server1 in the<multihost>section.

<multihost>
        enabled = y
        footer_url = y
        graphs_per_row = 2
        remotehost_list = server2.foo.org, server3.example.com
        <remotehost_desc>
                0 = http://server2.foo.org:8080,/monitorix
                1 = http://203.3.113.3:8080,/monitorix
        </remotehost_desc>
        groups = y
        remotegroup_list = Host Group
        <remotegroup_desc>
                0 = server2.foo.org, server3.example.com
        </remotegroup_desc>
</multihost>

The Multihost feature is set to yes withenabled = y

Each servers in the subnet 203.3.113.0/24 are authorized to transmit data, and 10.10.10.10 is the client from which the statistics graphs can be viewed in the browser. Additional servers can also be added, like here server3.example.com [203.3.113.3] in the same subnet.

Now the remote server can be selected with the dropdown Hostname menu to view the Monitorix network diagrams from another Debian or any other Linux server.

Source Link: Monitorix

Conclusion

Monitorix is a powerful system and network resource monitoring system with graphs for Debian and most Linux distributions. Monitorix was originally designed for monitoring Red Hat, Fedora and CentOS Linux, but today it runs on different GNU/Linux distributions. The open source tool regularly collects system and network data and displays the information in diagrams via its own web server in a web UI. The lightweight program is also suitable for use on single-board computers such as Raspberry Pi.

Multiple PHP-FPM versions with Apache on Debian 12

The Apache web server provide virtual hosts to support multiple domains on a single instance, and PHP-FPM manage multiple PHP versions on a Debian server.

Together, with Apache and PHP-FPM to hosting multiple PHP web-applications, each using a different version of PHP, all on the same server, and all at the same time. This because different applications may require different versions of PHP, but some server stacks, like a regularly configured LAMP stack, can only manage one. Using Apache with PHP-FPM FastCGI Process Manager is also a more cost-efficient solution than hosting each application on its own instance.

In this tutorial you’ll learn how to deploy two PHP sites on a single instance. Each site will use its own domain, and each domain use its own version of PHP. The first, site1.mydomain will use PHP 8.2. The second, site2.mydomain use PHP 7.4.

Step 1 – Installing PHP Version 8.2 with PHP-FPM

After the requirements are met, install PHP versions 7.4 and 8.2 as well as PHP-FPM and several additional extensions. To achieve this, the Sury PHP repository must first be added to the system.

The installation on Debian is done here as root by using “su -“.
First of all, required service packages are installed.

$ apt install lsb-release apt-transport-https ca-certificates wget gnupg -y

Add the Sury Repository for latest PHP version on the system.

$ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

Update the package lists as follows.

$ apt update

Install the Apache web server it is not already done.

$ apt install apache2 -y

Now install PHP 8.2 and PHP-FPM together with the most important PHP modules.

$ apt install php8.2 php8.2-fpm php8.2-{cli,mysql,imap,intl,apcu,cgi,bz2,zip,mbstring,gd,curl,xml,common,opcache,imagick} -y

Next install Apache module for PHP-FPM FastCGI Process Manager.

$ apt install libapache2-mod-fcgid -y

Step 2 – Installing PHP Version 7.4 with PHP-FPM

Next step repeat the process for PHP version 7.4 with PHP-FPM.

$ apt install php7.4 php7.4-fpm php7.4-{cli,mysql,imap,intl,apcu,cgi,bz2,zip,mbstring,gd,curl,xml,common,opcache,imagick} -y

  Note. the libapache2-mod-fcgid package is already installed in step 1.

Update the packages as follows.

$ apt update && apt upgrade -y
$ [ -f /run/reboot-required ] && reboot -f

With installing two PHP versions, start the php8.2-fpm service.

$ systemctl start php8.2-fpm

Repeating this process, now start the php7.4-fpm service.

$ systemctl start php7.4-fpm

Now check the status of the php-fpm services.

$ systemctl status php*

Step 3 – Configure Apache for Multiple PHP-FPM versions

Finaly, enable several modules using the Apache helper command so that your Apache2 service work with multiple PHP versions.

$ a2enmod actions fcgid alias proxy_fcgi setenvif

Now restart the Apache service to apply your changes.

$ systemctl restart apache2

With this steps you have installed two PHP versions on your server. Next, you’ll create a docroot for each website you want to deploy.

Step 4 – Creating Docroot for 2 Apache Websites

In this step, you will create a document root directory and an index page for each of your two websites.

First, create document root directories for site1.mydomain and site2.mydomain. This you can do with perform the following for loop command in the bash

$ for i in {1..2}; do mkdir /var/www/site"$i".mydomain ;done

By default, the Apache webserver runs as a www-data user and www-data group. To ensure that you have the correct ownership and permissions of your website root directories, execute the following commands.

$ chown -R www-data:www-data /var/www/site1.mydomain
$ chown -R www-data:www-data /var/www/site2.mydomain
$ chmod -R 755 /var/www/site1.mydomain
$ chmod -R 755 /var/www/site2.mydomain

Next you’ll create an phpinfo.php file inside each website document root. This will display each website’s PHP version information. Now let’s begin with site1.

Create the phpinfo.php file with the following code into it.

<?php phpinfo(); ?>

This you can do with perform the following command for both in a loop.

$ for i in {1..2}; do echo -e "<?php phpinfo(); ?>" > /var/www/site"$i".mydomain/phpinfo.php ;done

The web server should now have the document root directories that each site requires to serve data to visitors. Next, you will configure the Apache web server to work with two different PHP versions.

Step 5 – Configuring Apache for Both Websites

In this step, you’ll create two Apache virtual host configuration files. This will enable your two websites to work simultaneously with two different PHP versions.

In order for Apache to serve this content, it is necessary to create a virtual host file that contains the needed directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf, you’ll create two new ones inside the directory /etc/apache2/sites-available/.

First create a new Apache virtual host configuration file for the website site1.mydomain. Here you will direct Apache to render content using php8.2.

$ vi /etc/apache2/sites-available/site1.mydomain.conf

Use the editor of your choice, maybe it’s nano, it’s possible for old dudes who can’t replace the heavy rock with anything!

Add the following content. Make sure the website DocumentRoot path, ServerName, and PHP version match your setup.

<VirtualHost *:80>
     ServerAdmin admin@site1.mydomain
     ServerName site1.mydomain
     DocumentRoot /var/www/site1.mydomain
     DirectoryIndex phpinfo.php

     <Directory /var/www/site1.mydomain>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
     </Directory>

    <FilesMatch \.php$>
      # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
      SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
    </FilesMatch>

     ErrorLog ${APACHE_LOG_DIR}/site1.mydomain_error.log
     CustomLog ${APACHE_LOG_DIR}/site1.mydomain_access.log combined
</VirtualHost>

In this file you updated the DocumentRoot to your new directory and ServerAdmin to an email that the mydomain site administrator can access. You’ve also updated ServerName, which establishes the base domain for this virtual host configuration, and you’ve added a SetHandler directive to run PHP as a FastCGI Process Manager.

Save and close the file.

Next, create a new virtual host configuration file for the website site2.mydomain. You will specify this subdomain to deploy php7.4.

$ vi /etc/apache2/sites-available/site2.mydomain.conf

Add the following content. Again, make sure the website directory path, ServerName, and PHP version match your unique information.

<VirtualHost *:80>
     ServerAdmin admin@site2.mydomain
     ServerName site2.mydomain
     DocumentRoot /var/www/site2.mydomain
     DirectoryIndex phpinfo.php

     <Directory /var/www/site2.mydomain>
        Options Indexes FollowSymLinks MultiViews
        Require all granted
     </Directory>

    <FilesMatch \.php$>
      # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
      SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

     ErrorLog ${APACHE_LOG_DIR}/site2.mydomain_error.log
     CustomLog ${APACHE_LOG_DIR}/site2.mydomain_access.log combined
</VirtualHost>

Save and close the file when you are finished. Then check the Apache configuration file for any syntax errors.

$ apachectl configtest

You’ll see the following output.

Syntax OK

Next, enable both virtual host configuration files.

$ a2ensite site1.mydomain
$ a2ensite site2.mydomain

Now disable the default site, since you won’t need it.

$ a2dissite 000-default.conf

Finally, restart the Apache service to implement your changes.

$ systemctl restart apache2

Now that you have configured Apache to serve each site, you will test them to make sure the proper PHP versions are running.

Step 6 – Testing Websites using Apache with PHP-FPM versions

At this step, you have configured two Apache websites to run two different versions of PHP.

Testing PHP-FPM version using phpinfo()

Open your web browser and visit the sites http://site1.mydomain and http://site2.mydomain. You will see pages look like this.

phpinfo Version 8.2.14 FPM/FastCGI

Note. The page indicates that site1.mydomain deployed PHP version 8.2.

PHP settings using FPM/FastCGI you can find the php.ini file under the path /etc/php/{version}/fpm/php.ini like /etc/php/8.2/fpm/php.ini.

To enable FastCGI – PHP-FPM you can also use these commands.

$ a2enmod proxy_fcgi setenvif
$ a2enconf php8.2-fpm
$ systemctl restart apache2

The default configuration works for most of the installation, however it could be improved in various ways. To re-enable it’s recommended to enable access to the files only in specific virtual host or directory.

Find further examples at https://wiki.apache.org/httpd/PHP-FPM

Step 7 – Finally, clean up no needed files

Now that you’ve tested your sites, remove the phpinfo.php files. Because they contain sensitive information about your server and are accessible to unauthorized users, they pose a security threat. To remove both files and directory perform the following command.

$ for i in {1..2}; do rm -rf /var/www/site"$i".mydomain ;done

You now learn how to deploy a single Debian 12 server handling two websites with two different PHP versions. PHP-FPM, however, is not limited to two PHP versions only.

Conclusion

You have now combined Apache virtual hosts and PHP-FPM to serve multiple websites and multiple versions of PHP on a single server. The only practical limit on the number of PHP sites and PHP versions that your Apache service can handle is the processing power of your instance.

From here you might consider exploring PHP-FPM’s more advanced FastCGI Process Manager features, like its adaptive spawning process or how it can log sdtout and stderr. Alternatively, you could now secure your websites.