How to install Zabbix with Nginx on Ubuntu Linux

This tutorial will show you all the steps required to install Zabbix 4 with Nginx and PHP-FPM on Ubuntu Linux.

This tutorial was tested on Ubuntu 18.04.

1. Configure Date and Time using NTP

It is very important to keep your system with the correct date and time.

Set the correct timezone.

# dpkg-reconfigure tzdata

Install the Ntpdate package and set the correct date and time.

# apt-get update
# apt-get install ntpdate
# ntpdate

Disable the Ubuntu default NTP client.

Install the NTP service to keep the computer date and time updated after a reboot.

# timedatectl set-ntp 0
# apt-get install ntp

Make sure the correct date and time have been set on your computer.

# date

2. Install MySQL on Ubuntu Linux

Zabbix requires a database system to store all its configuration.

Use the Ubuntu APT command to install the MySQL server.

# apt-get update
# apt-get install mysql-server mysql-client

Use the following command to access the MySQL service console.

# mysql -u root -p

On the MySQL console, you need to perform the following tasks:

• Create a database named zabbix.
• Create a MySQL user account named zabbix.
• Give full control over the zabbix database to the zabbix user.

CREATE USER 'zabbix'@'%' IDENTIFIED BY 'kamisama123';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%';

Download the Zabbix installation package to get the database templates.

# mkdir /downloads
# cd /downloads
# wget

Extract the Zabbix installation package.

Import the Zabbix database templates inside the MySQL database.

When asked, you need to enter the MySQL password for the Zabbix user.

# tar -zxvf zabbix-4.0.3.tar.gz
# cd zabbix-4.0.3/database/mysql/
# mysql -u zabbix -p zabbix < schema.sql
# mysql -u zabbix -p zabbix < images.sql
# mysql -u zabbix -p zabbix < data.sql

The Zabbix database installation was completed.

3. Install Nginx on Ubuntu Linux

Use the Ubuntu APT command to install the Nginx server.

# apt-get update
# apt-get install nginx

Edit the nginx.conf configuration file.

Add client_max_body_size to the HTTP section.

Configure the maximum upload size to 32 Megabytes.

# vi /etc/nginx/nginx.conf

Here is the file with our configuration.

user www-data;
worker_processes auto;
pid /run/;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
http {
client_max_body_size 32M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

Restart the Nginx web server manually.

# service nginx restart
# service nginx status

Verify the Nginx service status.

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-29 04:29:22 UTC; 1h 17min ago
Docs: man:nginx(8)
Process: 2233 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status
Process: 2221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exite
Main PID: 2238 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─2238 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2239 nginx: worker process

The Nginx web server was installed successfully.

4. Add PHP support to Nginx

Nginx needs an external program to add PHP support.

Use the Ubuntu APT command to install the PHP required packages.

# apt-get update
# apt-get install php7.2-fpm

Use the following command to install the required PHP modules.

# apt-get install php7.2-mysql php7.2-mbstring php7.2-xml
# apt-get install php7.2-gd php7.2-curl php7.2-bcmath php7.2-ldap

Find the location of the PHP configuration file on your system.

Edit the php.ini configuration file.

# updatedb
# locate php.ini
# vi /etc/php/7.2/fpm/php.ini

Your PHP version may not be the same as ours.

Your PHP configuration file location may not be the same as ours.

Here is the file with our configuration.

max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 32M
max_input_time = 300
date.timezone = America/Sao_Paulo

Edit the Nginx default website configuration file.

# vi /etc/nginx/sites-available/default

Here is the original file, before our configuration.

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;

Here is the new file with our configuration.

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

Verify if your Nginx configuration file has no error.

# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the PHP service.
Restart the Nginx service.

# service php7.2-fpm restart
# service nginx restart

The Nginx server PHP configuration was completed.

5. Install Zabbix 4 on Ubuntu Linux

After finishing the MySQL and the Nginx configuration, we can start the Zabbix installation.

Create the required a user account to the Zabbix service.

# groupadd zabbix
# useradd -g zabbix -s /bin/bash zabbix

Use the Ubuntu APT command to install the required packages.

# apt-get install build-essential libmysqlclient-dev libssl-dev libsnmp-dev libevent-dev
# apt-get install libopenipmi-dev libcurl4-openssl-dev libxml2-dev libssh2-1-dev libpcre3-dev
# apt-get install libldap2-dev libiksemel-dev libcurl4-openssl-dev libgnutls28-dev

Access the directory where the Zabbix installation package was downloaded.

Compile and install the Zabbix server application.

# cd /downloads/zabbix-4.0.3/
# ./configure --enable-server --enable-agent --with-mysql --with-openssl --with-net-snmp --with-openipmi --with-libcurl --with-libxml2 --with-ssh2 --with-ldap
# make
# make install

Find the location of the Zabbix server configuration file on your system.

Edit the zabbix_server.conf configuration file.

# updatedb
# locate zabbix_server.conf
# vi /usr/local/etc/zabbix_server.conf

Here is the original file, before our configuration.


Here is the new file with our configuration.


Start the Zabbix server using the following command.

# /usr/local/sbin/zabbix_server

Start the Zabbix agent application using the following command.

# /usr/local/sbin/zabbix_agentd

Optional! The Zabbix installation package offers service startup scripts.

Copy the Zabbix startup script.

# cd /downloads/zabbix-4.0.3/
# cp misc/init.d/debian/* /etc/init.d/

You can now use the following commands to start the Zabbix server service.

# /etc/init.d/zabbix-server start

You can now use the following commands to stop the Zabbix server service.

# /etc/init.d/zabbix-server stop

Move the Zabbix frontend files inside your Nginx root drive directory.

Give the www-data user full control over the Zabbix directory and its files.

# cd /downloads/zabbix-4.0.3/frontends
# mv php /var/www/html/zabbix
# chown www-data.www-data /var/www/html/zabbix/* -R

Restart the Nginx service.

# service nginx stop
# service nginx start

6. Configure Zabbix on Ubuntu Linux

Open your browser and enter the IP address your web server plus /zabbix.

In our example, the following URL was entered in the Browser:


The Zabbix installation wizard will be presented.

Zabbix Installation

Verify if all Zabbix requirements were met successfully.

Zabbix install Nginx requirements

Enter the MySQL login information required to connect to the Zabbix database

Zabbix database connetion

Click on the Next button.

Zabbix Agent Connection

Verify the Zabbix installation summary.

Zabbis Installation Summary

Click on the Finish button to access the Zabbix Login screen.

Zabbix installation finished

On the Zabbix logins screen, enter the following information.

• Zabbix default username: Admin
• Zabbix default Password: zabbix

Zabbix Login

After a successful login, The Zabbix dashboard will be displayed.

Zabbix Dashboard

Congratulations, Zabbix is installed on your system.

7. Monitor the Zabbix Server

The Zabbix server must be able to monitor itself.

On the Zabbix dashboard, access the Configuration menu and select the Host option.

Zabbix menu

On the top right of the screen, select the option named: Zabbix servers

Zabbix Server Group

Locate the host named Zabbix server and click on the word DISABLED.

This will enable the Zabbix server to monitor itself.

Zabbix server agent disabled

The Zabbix server status will turn from DISABLED to ENABLED.

The Zabbix server is now monitoring itself.