bbatsche.PHP

Ansible PHP Site Role

This Ansible role installs PHP on your server and sets up a site using Nginx with PHP support. It utilizes Phpenv to manage different PHP versions, from 5.2 to 7.2 (but you may want to avoid 5.2!).

Requirements

You need to have Git installed on your server for Phpenv to work, but most servers already have Git nowadays.

This role uses Linux filesystem ACLs and a "web-admin" group for granting access to certain directories. You can configure this manually or use the bbatsche.Base role.

For Ubuntu Xenial, you need Ansible version 2.2 or newer; Ubuntu Trusty supports Ansible 2.1.

Role Variables

Here are some important settings you can configure:

  • domain: The domain name for your site.
  • dynamic_php: Set to true if you want Nginx to use index.php for all requests. Default is false.
  • max_upload_size: Maximum upload size in MB. Default is 10 MB.
  • timezone: Timezone for PHP. Default is "Etc/UTC".
  • install_mariadb: Install MariaDB libraries instead of MySQL. Default is false.
  • php_version: Specifies which PHP version to install.

FPM Tuning Variables

PHP FPM can be optimized for performance. Here are key settings:

  • fpm_mb_per_child: Average memory usage for each child process. Default is 30 MB.
  • fpm_max_children: Maximum number of child processes allowed. Default is calculated automatically.
  • fpm_start_servers: How many servers to start when the site is created.

Opcache Tuning Variables

These settings can improve the performance of your application:

  • opcache_memory_consumption: Default is 128 MB.
  • opcache_max_accelerated_files: Default is 6000.

Dependencies

This role depends on bbatsche.Nginx, which you must install first:

ansible-galaxy install bbatsche.Nginx

Example Playbook

Here is an example of how to use the role in an Ansible playbook:

- hosts: servers
  roles:
  - role: bbatsche.Phpenv
    domain: my-php-site.test
    php_version: 7.1.12
    composer_packages:
    - name: phpunit/phpunit
      version: ^6.4
    pecl_extensions:
    - name: yaml
      version: 2.0.2
    - name: imagick
      version: 3.4.3

License

MIT

Testing

The role includes tests for each task. You need to have Vagrant and VirtualBox installed. The tests use Serverspec, so Ruby and Bundler are required.

To run the tests:

$ gem install bundler
$ bundle install
$ rake

The tests will check Ubuntu versions: Trusty Tahr (14.04), Xenial Xerus (16.04), and Bionic Beaver (18.04).

To see available tasks (and tests):

$ rake -T

These tests are for ensuring the tasks work correctly, not for checking idempotence. Idempotency is tested separately.

Informazioni sul progetto

Install Phpenv, PHP, and set up a site in Nginx running it with PHP-FPM

Installa
ansible-galaxy install bbatsche.PHP
Licenza
mit
Download
281
Proprietario