@@ -39,6 +39,45 @@ check_root() {
3939 fi
4040}
4141
42+ # Detect installed PHP-FPM service
43+ detect_php_fpm () {
44+ local php_fpm_service=" "
45+
46+ # Check for installed PHP-FPM services (newest to oldest)
47+ for php_version in 8.5 8.4 8.3 8.2 8.1 8.0 7.4; do
48+ if systemctl list-units --all | grep -q " php${php_version} -fpm.service" ; then
49+ php_fpm_service=" php${php_version} -fpm"
50+ break
51+ fi
52+ done
53+
54+ # Fallback to generic php-fpm
55+ if [ -z " $php_fpm_service " ] && systemctl list-units --all | grep -q " php-fpm.service" ; then
56+ php_fpm_service=" php-fpm"
57+ fi
58+
59+ echo " $php_fpm_service "
60+ }
61+
62+ # Get PHP-FPM socket path
63+ get_php_fpm_socket () {
64+ local php_fpm_service=" $1 "
65+ local socket_path=" "
66+
67+ if [ -n " $php_fpm_service " ]; then
68+ # Extract version from service name (e.g., php8.3-fpm -> 8.3)
69+ local version=$( echo " $php_fpm_service " | grep -oP ' \d+\.\d+' )
70+
71+ if [ -n " $version " ]; then
72+ socket_path=" /run/php/php${version} -fpm.sock"
73+ else
74+ socket_path=" /run/php/php-fpm.sock"
75+ fi
76+ fi
77+
78+ echo " $socket_path "
79+ }
80+
4281# Install Zabbix Server
4382install_zabbix_server () {
4483 echo ' =========================================='
@@ -353,10 +392,25 @@ EOF
353392 if [ " $WEB_SERVER " = " nginx" ]; then
354393 print_info " Configuring Nginx..."
355394
395+ # Detect PHP-FPM version first
396+ PHP_FPM_SERVICE=$( detect_php_fpm)
397+
398+ if [ -n " $PHP_FPM_SERVICE " ]; then
399+ PHP_FPM_SOCKET=$( get_php_fpm_socket " $PHP_FPM_SERVICE " )
400+ print_info " Using PHP-FPM socket: ${PHP_FPM_SOCKET} "
401+ else
402+ print_error " PHP-FPM not detected, using default socket"
403+ PHP_FPM_SOCKET=" /run/php/php-fpm.sock"
404+ fi
405+
356406 # Update Nginx config for Zabbix
357407 sed -i ' s/# listen 8080;/listen 80;/' /etc/zabbix/nginx.conf
358408 sed -i ' s/# server_name example.com;/server_name _;/' /etc/zabbix/nginx.conf
359409
410+ # Update PHP-FPM socket in Nginx config (handle different possible formats)
411+ sed -i " s|fastcgi_pass unix:/run/php/php[0-9.]*-fpm.sock;|fastcgi_pass unix:${PHP_FPM_SOCKET} ;|g" /etc/zabbix/nginx.conf
412+ sed -i " s|fastcgi_pass unix:/run/php/php-fpm.sock;|fastcgi_pass unix:${PHP_FPM_SOCKET} ;|g" /etc/zabbix/nginx.conf
413+
360414 # Create symlink if not exists
361415 if [ ! -L /etc/nginx/sites-enabled/zabbix ]; then
362416 ln -sf /etc/zabbix/nginx.conf /etc/nginx/sites-enabled/zabbix
@@ -371,13 +425,17 @@ EOF
371425
372426 # Start and enable services
373427 print_info " Starting Zabbix services..."
374- systemctl restart zabbix-server zabbix-agent php8.4-fpm nginx 2> /dev/null || \
375- systemctl restart zabbix-server zabbix-agent php8.3-fpm nginx 2> /dev/null || \
376- systemctl restart zabbix-server zabbix-agent php8.1-fpm nginx 2> /dev/null || \
377- systemctl restart zabbix-server zabbix-agent php-fpm nginx
378428
379- systemctl enable zabbix-server zabbix-agent nginx
380- print_success " Zabbix services started and enabled (Nginx)"
429+ if [ -n " $PHP_FPM_SERVICE " ]; then
430+ systemctl restart zabbix-server zabbix-agent " $PHP_FPM_SERVICE " nginx
431+ systemctl enable zabbix-server zabbix-agent " $PHP_FPM_SERVICE " nginx
432+ print_success " Zabbix services started and enabled (Nginx with ${PHP_FPM_SERVICE} )"
433+ else
434+ print_error " PHP-FPM not found, starting without it"
435+ systemctl restart zabbix-server zabbix-agent nginx
436+ systemctl enable zabbix-server zabbix-agent nginx
437+ print_success " Zabbix services started and enabled (Nginx, PHP-FPM may need manual setup)"
438+ fi
381439 else
382440 print_info " Configuring Apache..."
383441
0 commit comments