Have you encountered an HTTP error 500 on the Zabbix frontend when trying to open the Hosts or Latest Data view? Or perhaps you’ve checked the HTTPD log file (/var/log/httpd/error_log) and discovered the ‘PHP Fatal error: Allowed memory size exhausted,’ which looks like this:
[Sat Sep 02 22:42:21.712989 2023] [proxy_fcgi:error] [pid 1071899:tid 1071942] [client 185.240.17.53:35755] AH01071: Got error 'PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /usr/share/zabbix/include/db.inc .php on line 733', referer: http://10.11.11.11/zabbix/zabbix.php?action=dashboard.view
Don’t worry; this error is an easy fix! We just need to edit two configuration files and restart the web server.
Increasing ‘memory_limit’ in Httpd configuration
Open the ‘php.ini’ configuration file:
nano /etc/php.ini
and increase the memory by changing the ‘memory_limit‘ parameter:
memory_limit = 1024M
In my case, I will change it from the default 128M to 1024M.
If you cannot find the ‘php.ini’ file, search for it with: sudo grep –include=*.ini -irl / -e “memory_limit”
Increasing ‘memory_limit’ in Zabbix PHP configuration
Most people forget that Zabbix will overwrite the ‘memory_limit’ with its own configuration file, so we also need to change that. Open the ‘zabbix.conf’ configuration file:
nano /etc/php-fpm.d/zabbix.conf
and update the ‘php_value[memory_limit]’ parameter to match the memory limit set in the ‘php.ini’ file.
[zabbix] user = apache group = apache listen = /run/php-fpm/zabbix.sock listen.acl_users = apache,nginx listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 200 php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session php_value[max_execution_time] = 300 php_value[memory_limit] = 1024M php_value[post_max_size] = 256M php_value[upload_max_filesize] = 64M php_value[max_input_time] = 300 php_value[max_input_vars] = 10000
If you cannot find the ‘zabbix.conf’ file, search for it with: sudo grep –include=*.conf -irl / -e “\[zabbix\]”
Restart Httpd and PHP service
We have increased the PHP memory limit, but it is not applied. To apply the new configuration, you need to restart the Httpd web server and the php-fpm servicee
systemctl restart httpd php-fpm
That’s all there is to it! Piece of cake! Until the next error – farewell!