PART ONE: How to Install Zabbix on an Ubuntu 18.04 VPS or Dedicated Server

Introduction

Zabbix is one of the best monitoring tool developed to monitor server availability, network devices, server performance, and other critical network components. It is a reliable open-source application that features a backend written in C and Java, and a frontend developed in PHP.

This tutorial will help you install Zabbix on your Ubuntu 18.04 server to keep track of the status of your system, applications, and network devices.

Ready? Let's get started!

Before You Begin

To install the Zabbix server on Ubuntu 18.04 successfully, the following dependencies must be installed first:

Step 1 - Installing Apache

First, update your Ubuntu 18.04 server:

$ sudo apt update
$ sudo apt upgrade

Next, issue the command below to install Apache2

$ sudo apt install apache2

Once, Apache2 is installed, run the command below to open the file /etc/apache2/conf-enabled/security.conf and adjust the settings to configure the basic security.

$ sudo nano /etc/apache2/conf-enabled/security.conf

Find the line ServerTokens OS and change it to ServerTokens Prod. the ServerTokens directive determines what is returned as the response for server HTTP and has only six valid options namely: OS, Full, Minor, Minimal, Prod, and Major.

Next, run the command below to open the /etc/apache2/apache2.conf file:

 $ sudo nano /etc/apache2/apache2.conf

Find ServerName and set it to Zabbix.example.com and the ServerAdmin to admin@example.com.

Note: Remember to replace example.com with your Fully Qualified Domain Name (FQDN).

Once everything is done, save the changes and exit the nano editor. For these changes to take effect, restart your Apache web service:

$ sudo systemctl restart apache2

Next, execute the command below to enable the firewall and then allow HTTP and HTTPs:

$ sudo ufw enable
$ sudo ufw allow http
$ sudo ufw allow https

Step 2 - Installing PHP And The Required Modules

After installing Apache, you should install PHP and the modules required to enable Apache service to utilize PHP scripts. Issue the command below:

$ 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

You can execute the following command to confirm the PHP version:

$ sudo php -v

This will give you an output similar to the one below:

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018ThePHPGroup
ZendEnginev3.2.0, Copyright (c) 1998-2018ZendTechnologies
withZendOPcachev7.2.5-0ubuntu0.18.04.1, Copyright (c) 1999-2018, byZendTechnologies

Next, execute the command below to enable conf php7.2-cgi:

$ sudo  a2enconf php7.2-cgi

You will be prompted to issue the command below to activate the new configuration:

$ sudo systemctl reload apache2

Once you reload Apache2, open the /etc/php/7.2/apache2/php.ini to set your correct timezone:

$ sudo /etc/php/7.2/apache2/php.ini

Find the line date.timezone and set it to your timezone. The timezones are set by location, and it's easy to select one. For instance,

Date.timezone = "America/Toronto"

Then run the command below to restart Apache:

$ sudo systemctl restart apache2

Step 3 - Setting Up MariaDB

In this tutorial, we’ll use MariaDB as our database server. Follow the steps below to create the Database for a Zabbix user.

Execute the command below to log in to the MariaDB command line:

$ sudo mysql -u root -p

Enter your root credentials and hit ENTER to access the MariaDB shell. Once you are on that command line, issue the command below to create the Zabbix user database:

MariaDB [(none)]>

createdatabase zabbix;

Then, execute the following command to grant the new user all privileges:

MariaDB [(none)]>

grant all privilegeson zabbix.* to zabbix@'localhost'identifiedby'password'

Note: Remember to replace the value 'password' with your preferred password.

Next, flush the privileges:

MariaDB [(none)]>

flushprivileges;

Then, execute the command below to exit the database command line:

MariaDB [(none)]>

exit

Step 4 - Installing The Zabbix Server

To install the Zabbix server , first, execute the command below to add the Zabbix repository:

$ sudo wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+bionic_all.deb

Then download the Zabbix installation files

$ sudo dpkg -i zabbix-release_3.4-1+bionic_all.deb

Now, update your system and install the Zabbix server modules:

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

You can now run the command below to confirm the status of Zabbix server:

$ sudo systemctl status zabbix-server

This will give you the following output:

● zabbix-server.service - Zabbix Server
   Loaded: loaded (/lib/systemd/system/zabbix-server.service; disabled; vendor preset: enabled)
   Active::active (running) since Wed 2018-10-2410:21:15 UTC; 2h 44min ago
  Process:23567 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
  ...

Step 5 - Configuring The Zabbix Server

Now, open the file /etc/zabbix/zabbix_server.conf:

$ sudo /etc/zabbix/zabbix_server.conf

And confirm the following values are correctly configured:

DBName=zabbix
DBUser=zabbix
DBPassword=password

If everything is okay, run the command below to restart the Zabbix server:

$ sudo systemctl restart zabbix-server

Next, run the command below:

$ sudo nano /usr/share/zabbix/include/classes/setup/CFrontendSetup.php

Find the directive always_populate_raw_post_data and set it to off. Besides, locate the lines:

publicfunctioncheckPhpAlwaysPopulateRawPostData() {
$current = ini_get('always_populate_raw_post_data');

Add the value ‘$current = -1‘ immediately after the line above to have the following result:

publicfunctioncheckPhpAlwaysPopulateRawPostData() {
    $current = ini_get('always_populate_raw_post_data');
    $current = -1;

Save the changes and exit the nano editor.

Run the command below to open the file /etc/php/7.2/apache2/php.ini:

$ sudo nano /etc/php/7.2/apache2/php.ini

Once the file opens, locate and set the PHP requirements as follows:

max_execution_time = 300
max_input_time = 300
post_max_size = 16M

Next, open the file /etc/zabbix/zabbix_agentd.conf and adjust the settings to enable Zabbix agent tocontrol the Zabbix server.

$ sudo nano /etc/zabbix/zabbix_agentd.conf

Set the following:

Hostname=zabbix.server.example.com

Replace example.com with your valid domain name.

Now, start and enable the Zabbix server:

$ sudo systemctl start zabbix-server
$ sudo systemctl enable zabbix-server

The last thing is to allow ports 5000 and 5001

$ sudo ufw allow proto tcp fromany to any port 10050,10051

Conclusion

That is It! You have successfully installed Zabbix on your Ubuntu 18.04 VPS or Dedicated server. Part two of this article will show you how to complete the server settings for your Zabbix web interface.

Check out these top 3 Linux hosting services

Was this article helpful?