handle php logrotate

This commit is contained in:
Ludovic Cartier
2025-09-24 15:37:04 +02:00
parent e9dae1dd0b
commit 140610f8ee
4 changed files with 47 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ This Ansible role installs and configures PHP with support for multiple versions
- Create and manage PHP-FPM pools with custom configurations
- Support for multiple pools across different PHP versions
- Automatic log directory creation with proper ownership
- Automatic logrotate configuration for PHP-FPM logs
- Support for PHP-FPM
- Automatic repository setup (Sury repository for latest PHP versions)
@@ -74,6 +75,9 @@ php_pools:
# Remove default www pool
php_remove_default_pool: false
# Logrotate configuration for PHP-FPM logs
php_logrotate_enabled: true
```
## Example Playbooks
@@ -184,6 +188,8 @@ The role will manage PHP-FPM services for each installed version:
- Log directories are automatically created with proper ownership
- Pool sockets are created with specific naming: `php{version}-fpm-{pool_name}.sock`
- You can create multiple pools for the same PHP version with different configurations
- Logrotate configuration is automatically created if logrotate is installed on the system
- PHP-FPM logs are rotated daily with 31 days retention and bzip2 compression
## License

View File

@@ -34,3 +34,6 @@ php_pools:
admin_value_post_max_size: "16M"
php_remove_default_pool: false
# Logrotate configuration for PHP logs
php_logrotate_enabled: true

View File

@@ -33,3 +33,19 @@
- php_remove_default_pool | bool
notify:
- restart php-fpm services
- name: php | check if logrotate is installed
package_facts:
manager: "auto"
- name: php | create logrotate configuration for php-fpm logs
template:
src: php-fpm.logrotate.j2
dest: "/etc/logrotate.d/php-fpm"
owner: root
group: root
mode: '0644'
when:
- php_logrotate_enabled | default(true) | bool
- "'logrotate' in ansible_facts.packages"
- php_pools is defined and php_pools | length > 0

View File

@@ -0,0 +1,22 @@
daily
rotate 31
compress
compresscmd /bin/bzip2
uncompresscmd /bin/bunzip2
compressoptions -9
compressext .bz2
missingok
dateext
dateformat -%Y%m%d-%s
dateyesterday
notifempty
sharedscripts
su root adm
/var/log/php/*/*/php-slow.log
/var/log/php/*/*/php-errors.log
{
postrotate
if [ -d /run/systemd/system ]; then systemctl kill -s HUP rsyslog.service; else invoke-rc.d rsyslog rotate > /dev/null; fi
endscript
}