Skip to content

PHP-fpm configuration and pool templates

License

Notifications You must be signed in to change notification settings

ojullien/php-fpm

Repository files navigation

PHP-FPM configuration and pool templates

PHP-FPM personnal configuration and pool templates on Debian linux distribution.

Note: I use this package for my own projects, it contains only the features I need.

Table of Contents

Requirements | Configuration | Pools | Documentation | Contributing | License

Requirements

  • Debian linux distribution: ~10.0
  • PHP-FPM: ~8.0

Configuration

I do not modify any PHP configuration files. I just add new configuration files to override the default PHP configuration.

PHP includes a central configuration file /etc/php/8.x/fpm/php.ini and, then, the particular configuration snippets (/etc/php/8.x/fpm/conf.d/*.ini) which manage the modules.

PHP-FPM uses a central configuration file /etc/php/8.x/fpm/php-fpm.ini and configures the pools using conf files located in /etc/php/8.x/fpm/pool.d/

Log directory is /var/log/php/

Files

  • zzz-prod: overrides the main PHP configuration for production server.
  • zzz-dev: overrides the main PHP configuration for development server.

How to setup the PHP personnal configuration

  1. Copy the configuration files into /etc/php/8.x/mods-available/
  2. Edit the named like zzz-***.ini files and make changes as you need.
  3. Enable the configuration you need using phpenmod zzz-***
  4. Review your settings using php -i

Pools

I wrote thoses templates to ease the process of creating named-based PHP-FPM pools.

Each pool runs under is own user/group process (see adduser documentation). The process manager is set to ondemand.

Features

  • fpm/phpdisconf.sh: bash script used to disable a pool configuration.
  • fpm/phpenconf.sh: bash script used to enable a pool configuration.
  • fpm/conf-available/10-php-fpm.conf: overrides the main PHP-FPM configuration (php-fpm.conf)
  • fpm/conf-available/20-domain_01.tld.conf: pool settings for domain_01.tld.
  • fpm/conf-available/20-domain_02.tld.conf: pool settings for domain_02.tld.
  • fpm/conf-available/common.conf: contains common settings used by all pools.
  • fpm/conf-available/www.conf: default PHP FPM pool settings.

How to setup the pools

Note: replace x by the minor version of PHP. Ex: php-fpm8.x --test becomes php-fpm8.0 --test

  1. Copy all the files and directories into /etc/php/8.x/fpm
  2. Move the default pool from /etc/php/8.x/fpm/pool.d/www.conf to /etc/php/8.x/fpm/conf-available/www.conf
  3. Make executable the phpdisconf.sh script file using chmod u+x /etc/php/8.x/fpm/phpdisconf.sh
  4. Make executable the phpenconf.sh script file using chmod u+x /etc/php/8.x/fpm/phpenconf.sh
  5. Edit the FPM configuration file (/etc/php/8.x/fpm/conf-available/10-php-fpm.conf) and make changes as you need.
  6. Enable yours FPM settings using ./phpenconf.sh 10-php-fpm
  7. Edit the named like /etc/php/8.x/fpm/conf-available/20-***.conf files and make changes as you need.
  8. Enable the pools using ./phpenconf.sh 20-domain_01.tld 20-domain_02.tld
  9. Test the validity of your php-fpm configuration syntax using php-fpm8.0 --test
  10. Restart the PHP-FPM using systemctl restart php8.x-fpm.service

Documentation

I wrote and I use this package for my own projects. And, unfortunately, I do not provide exhaustive documentation. Please read the code and the comments ;)

For instructions on how to use, best practices, templates and other usage information, please visit the PHP documentation.

Contributing

Thanks you for taking the time to contribute. Please fork the repository and make changes as you'd like.

As I use these configuration and templates for my own projects, it contains only the features I need. But If you have any ideas, just open an issue and tell me what you think. Pull requests are also warmly welcome.

If you encounter any bugs in the configuration or templates, please open an issue.

Be sure to include a title and clear description,as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.

License

php-fpm configuration and templates are open-source and are licensed under the MIT License.