Operations 21 min read

Step-by-Step Guide: Compile and Install Zabbix with Nginx, MySQL, and PHP on Linux

This tutorial walks you through preparing a Linux environment, compiling and installing Nginx, MySQL, and PHP‑FPM, then building Zabbix server and web interface, configuring a database, adding agents, and setting up email notifications for comprehensive server monitoring.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step-by-Step Guide: Compile and Install Zabbix with Nginx, MySQL, and PHP on Linux

1. Introduction

This article describes the compilation and installation process of Zabbix, including the prerequisite LNMP environment (although Zabbix officially recommends LAMP), and shows how to create simple monitoring tasks that can send notification emails when problems are detected.

2. System Environment

Install the required package groups:

yum groupinstall "Development Tools" "Server Platform Development"

3. Build Web Service

Add nginx user

Compile and install Nginx from source (nginx‑1.10.3):

tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
make
make install

Create symlink to nginx ln -s /usr/local/nginx-1.10.3 /usr/local/nginx Add nginx executable to PATH

Place the nginx binary directory in the system PATH for convenient use.

Change ownership of nginx directory chown -R nginx.nginx /usr/local/nginx-1.10.3 Verify web service

Start nginx and ensure it serves pages correctly.

Enable nginx autostart

Add the nginx executable to rc.local so it starts on boot.

4. Build MySQL Service

Add mysql user useradd -s /sbin/nologin -M mysql Extract MySQL binary package

tar xf mysql-5.5.53-linux2.6-x86_64.tar.gz -C /usr/local

Create symlink to MySQL

ln -s /usr/local/mysql-5.5.53-linux2.6-x86_64 /usr/local/mysql

Change ownership of MySQL directory chown -R mysql.mysql /usr/local/mysql Initialize MySQL database

Run mysql_install_db as the mysql user, which creates the data directory at /usr/local/mysql/data.

Enable MySQL autostart

cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

Provide MySQL configuration file cp support-files/my-small.cnf /etc/my.cnf Start MySQL service

service mysqld start
lsof -i :3306   # verify MySQL is running

Set MySQL root password

mysqladmin -uroot -p<password>

5. Build PHP‑FPM Environment

Configure PHP

tar -zxvf php-5.5.38.tar.gz
cd php-5.5.38
./configure --with-config-file-path=/usr/local/php-5.5.38/etc
make test   # optional, may show warnings
make install

Create symlink to PHP ln -s /usr/local/php-5.5.38 /usr/local/php Add PHP binary to PATH

Place the PHP executable directory in the system PATH.

Provide php.ini

Edit /usr/local/php/etc/php.ini to meet Zabbix requirements (e.g., enable required extensions, set appropriate limits).

Provide php‑fpm configuration

The php-fpm configuration is installed during make install; rename it as needed.

Start php‑fpm service php-fpm start Enable php‑fpm autostart

Copy ./sapi/fpm/init.d.php-fpm to /etc/init.d/ and rename appropriately, then add to startup.

6. Build Zabbix Server

Create zabbix user useradd -s /sbin/nologin -M zabbix Configure Zabbix

Extract zabbix-3.2.4.tar.gz, enter the directory, and run:

./configure --with-net-snmp --with-libcurl --with-libxml2
make install   # no separate make step needed

7. Create Database for Zabbix

Create a MySQL database named zabbix and a dedicated user, then import the initialization SQL scripts located in zabbix-3.2.4/database/mysql.

Modify Zabbix server configuration

/usr/local/zabbix/etc/zabbix_server.conf
DBPassword=<password>

Modify Zabbix agent configuration

Adjust the same parameters in zabbix_agentd.conf.

Enable Zabbix server and agent autostart

Copy the init scripts from misc/init.d (choose the appropriate distribution, e.g., Fedora) to /etc/init.d/, edit paths as needed, and add them to startup.

Start Zabbix services

service zabbix_server start
service zabbix_agentd start

8. Install Zabbix Web Interface

Create a web directory for Zabbix, copy the contents of frontends/php into it, and access http://<server_ip>/zabbix in a browser.

PHP environment check

The installer verifies required PHP parameters; all must show OK.

Configure database connection

Enter the MySQL Zabbix database name, user, and password.

Complete installation

The installer generates zabbix.conf.php; if permission issues prevent automatic placement, download it and copy manually to the Zabbix site directory.

9. Install Zabbix Agent on Monitored Host

Compile the agent from source, using appropriate configure options, then run make install, create symlinks, add the binary to PATH, edit zabbix_agentd.conf, and enable autostart.

10. Configure Monitoring Items on Zabbix Server

In the Zabbix web UI, add the monitored host (e.g., server3) under Configuration → Hosts → Create host, assign it to a host group, specify its IP, and apply a suitable template such as Template App HTTP Service. After the host appears green, Zabbix is successfully communicating with the agent.

11. Configure Email Notifications

Create a custom Media Type

Define a Media Type named “user mail” that uses a script.

Write the notification script

Place the script (e.g., mail.sh) in /usr/local/zabbix/share/zabbix/alertscripts or adjust AlertScriptsPath in zabbix_server.conf.

Associate the script with a user

In Administration → Users → Admin → Media, add the “user mail” Media Type and provide the recipient’s email address.

Define an Action

Create an Action that triggers on Problem events (e.g., HTTP service down) and sends the email via the custom Media Type to the Zabbix administrators group. Also define a recovery action.

Configure SMTP client

Since the server lacks a valid SMTP service, configure /etc/mail.rc to use an external SMTP server (e.g., 163.com) and ensure the mail command is available.

12. Summary

This guide demonstrates how to set up Zabbix for monitoring a Linux server, from building the LNMP stack to configuring Zabbix server, web interface, agents, and email alerts. It covers the essential steps for a functional monitoring solution.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlPHP
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.