(Last Updated On: October 10, 2018)

Welcome to our guide on how to install Zabbix Server 4.0 on Ubuntu 18.04 & Ubuntu 16.04 LTS. Our previous guide was on the installation of Zabbix 3.4 on Ubuntu 18.04 server, so this guide is fit for you if doing an upgrade.

Zabbix is an enterprise-grade open source monitoring tool used for monitoring applications, systems, Network devices, IOT devices, e.t.c. Zabbix server backend is written in C and Java, and the frontend interface written in PHP.

Zabbix Architecture

Zabbix works in a Client/Server model. The server communicates to the native software agents available for various Operating systems like Linux, NIX, and Windows. For systems without an agent, generic monitoring protocols such as Simple Network Management Protocol (SNMP) or Intelligent Platform Management Interface (IPMI) can be used.

Install Zabbix Server 4.0 on Ubuntu 18.04 & Ubuntu 16.04 LTS

Here we will cover the steps to install Zabbix 4.0 on both Ubuntu 18.04 and Ubuntu 16.04 LTS. Follow them in order to avoid any issues that often result from missing something.

Zabbix Server depends on the following software applications:

  • Apache web server
  • PHP with required extensions
  • MySQL/ MariaDB database server

MySQL or MariaDB can be a remote server, but php and httpd need to be installed on the Zabbix server. It is possible to run Apache web server in reverse proxy mode.

Step 1: Install Apache httpd server

Update your system then install the apache2 package by running the following commands:

sudo apt update
sudo apt -y upgrade
sudo apt install -y apache2

After installing Apache, configure basic security by allowing Prod ServerTokens only on /etc/apache2/conf-enabled/security.conf

sudo sed -i "s/^ServerTokens OS$/ServerTokens Prod/" /etc/apache2/conf-enabled/security.conf
sudo sed -i "s/^ServerSignature On$/ServerSignature Off/" /etc/apache2/conf-enabled/security.conf

The directiveServerTokens configures what is returned as the Server HTTP response. Valid options are Full | OS | Minimal | Minor | Major | Prod.

Set ServerName:

# grep ServerName /etc/apache2/apache2.conf
ServerName zabbix.example.com

Set Server Admin to receive an email in case of issues.

# grep ServerAdmin /etc/apache2/apache2.conf
ServerAdmin [email protected]

Restart apache web service after making the changes

sudo systemctl restart apache2

If  you have UFW firewall installed and enabled, allow access to port 443 and 80

sudo ufw allow proto tcp from any to any port 80,443

To enable UFW firewall on Ubuntu, use

sudo ufw enable

Don’t forget to enable ssh service

sudo ufw allow ssh

Step 2: Install php for Apache

Install PHP on your Ubuntu server and extensions required by Zabbix:

sudo apt-get -y install php php-pear php-cgi php-common libapache2-mod-php php-mbstring php-net-socket php-gd php-xml-util php-mysql php-gettext php-bcmath

Configure Apache and PHP on Ubuntu 18.04

Check PHP installed version:

# php -v
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Enable PHP CGI module

$ sudo  a2enconf php7.2-cgi 
Enabling conf php7.2-cgi.

To activate the new configuration, you need to run:

sudo systemctl reload apache2

Set PHP timezone

sudo sed -i "s/^;date.timezone =$/date.timezone = \"Africa\/Nairobi\"/" /etc/php/7.2/apache2/php.ini

Restart apache2 after this change:

sudo systemctl restart apache2

Configure Apache and PHP on Ubuntu 16.04

Check PHP installed version:

# php -v
PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.32-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

Enable PHP CGI module

$ sudo  a2enconf php7.0-cgi 
Enabling conf php7.0-cgi.

To activate the new configuration, you need to run:

sudo systemctl reload apache2

Set PHP timezone

sed -i "s/^;date.timezone =$/date.timezone = \"Africa\/Nairobi\"/" /etc/php/7.0/apache2/php.ini

Restart apache2 after this change:

sudo systemctl restart apache2

Step 3: Install MariaDB Database server

Install MariaDB database server on Ubuntu 18.04 / Ubuntu 16.04 LTS using our guide, the link is shared below:

How to Install MariaDB 10.3 on Ubuntu 18.04 and CentOS 7

How to install MariaDB 10.3 on Ubuntu 16.04 (Xenial Xerus) LTS

Once Database server installation is done, you need to create a database for Zabbix user:

export db_pass="StrongPassword"
mysql -uroot -p <<MYSQL_SCRIPT
    create database zabbix;
    grant all privileges on zabbix.* to [email protected]'localhost' identified by '${db_pass}';
    FLUSH PRIVILEGES;
MYSQL_SCRIPT

Replace “StrongPassword” with your desired password for the database.

Step 4: Install Zabbix 4.0 Server on Ubuntu 18.04 / Ubuntu 16.04 Server

Now that we have required dependencies installed and working, we can finalize our installation by deploying Zabbix 4.0 server.

Add Zabbix 4.0 repository on Ubuntu 18.04 (Bionic Beaver) LTS:

wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+bionic_all.deb
sudo dpkg -i zabbix-release_4.0*
sudo apt update

Add Zabbix 4.0 repository on Ubuntu 16.04 (Xenial Xerus) LTS:

wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+xenial_all.deb
sudo dpkg -i zabbix-release_4.0*

Now install Zabbix 4.0 Server and frontend with MySQL support:

sudo apt update
sudo apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-agent

Substitute ‘mysql’ in the commands with ‘pgsql‘ to use PostgreSQL, or with ‘sqlite3‘ to use SQLite3 (proxy only).

Import Zabbix Server database schema

For Zabbix server and Zabbix proxy daemons, a database is required. It is not needed to run Zabbix agent. If Zabbix server and proxy are installed on the same host, their databases must be created with different names!

Import initial schema and data for the server with MySQL:

zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

Enter your Zabbix database user password when prompted.

With PostgreSQL:

zcat /usr/share/doc/zabbix-server-pgsql/create.sql.gz | sudo -u <username> psql zabbix

Step 5: Configure and start Zabbix server

Edit your Zabbix configuration file  /etc/zabbix/zabbix_server.conf and set database connection settings.

DBName=zabbix
DBUser=zabbix
DBPassword=StrongPassword

Restart Zabbix server after modifying this file:

sudo systemctl restart zabbix-server
sudo systemctl enable zabbix-server

Zabbix Frontend configuration

Apache configuration file for Zabbix frontend is located in /etc/apache2/conf-enabled/zabbix.conf. Some PHP settings are already configured. But it’s necessary to uncomment the “date.timezone” setting and set the right timezone for you.

php_value date.timezone Africa/Nairobi

Complete settings should be like this:

php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Africa/Nairobi

Configure Zabbix agent to monitor Zabbix server itself.

$ sudo vim /etc/zabbix/zabbix_agentd.conf

Hostname=zabbix.example.com

Configure Firewall

If you have ufw firewall installed and running on your system, ensure you allow port 5000 and port 5001

sudo ufw allow proto tcp from any to any port 10050,10051

Restart apache2 and start frontend installation

sudo systemctl restart apache2

Step 6: Perform Zabbix initial setup

Access “http://(Zabbix server’s hostname or IP address)/zabbix/”  to begin Zabbix initial setup.

Step 1 is a welcome page, click “Next step” to proceed.

Confirm that all pre-requisites are satisfied.

Configure DB settings

Confirm Hostname and Port number for Zabbix server. It is okay to use localhost in place of a name.

Verify all settings and click Next step to finish the initial setup. If all goes well, you should get congratulations page. Click the Finish button to end installation.

You’ll then get the login page. Default logins are:

Username: "admin"
Password: "zabbix"

Dashboard for Zabbix server 4.0 looks like below

Step 6: Change Admin Password

Login to Zabbix admin dashboard with admin user and password zabbix. You need to change the password for admin user after the first login for security reasons.

Navigate to Administration > Users > Admin > Password > Change Password

Configure Monitoring Target host

Now that we have our Zabbix server ready for monitoring, you can start configuring first monitoring target host. By default, Zabbix server is added to monitoring.

To add other host devices, login to Zabbix admin dashboard with the username admin and click on Configuration > Hosts. 

After a few minutes, monitoring data will start flowing in, to check host graphs go to Monitoring > Screens > Server name. My next article will cover installation of Zabbix agent 4.0 on Ubuntu 18.04 and Ubuntu 16.04 LTS servers.