This Ansible role installs and configures PHP on Debian-based systems. It manages PHP repository setup, installs PHP and extensions, configures INI files for different SAPIs (cli & fpm),and ensures required dependencies and configuration files are present.
- Ansible 2.13+
- Python 3.9+ (for Molecule + testinfra)
- Tested on Ubuntu 22.04+
These variables can be overridden in your inventory, playbooks, or group_vars.
php_version: The PHP version to install (e.g.,8.1).php_base_packages: List of base PHP packages to install.php_extensions: List of PHP extensions to install.php_ini_sapi_configs: List of SAPI-specific PHP INI configuration options.
php_ppa_dependencies: List of packages required to add the PHP PPA.php_repo: The PPA repository to use (default:ondrej/php).php_source_list_file: Path to the PHP PPA source list file.php_phing_file: Destination path for the phing file.
This role has no external dependencies.
To include this role in your project using a requirements.yml file:
roles:
- name: okb.php
src: https://github.com/1000bulbs/ansible-role-php.git
scm: git
version: masterThen install it with:
ansible-galaxy role install -r requirements.ymlIncluding an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- name: My Playbook
hosts: all
become: true
roles:
- role: okb.phpThis role uses Python and Node.js for linting and formatting, Molecule with pytest-testinfra for integration testing, and Act for local GitHub Actions testing — all orchestrated through a Makefile for ease of use and convenience.
Install all dependencies and setup environment
make setupRun lint and format checks
make checkRun integration tests
make testRun github actions tests locally
make ciThis project includes pre-commit integration via Git hooks to automatically run formatting and linting checks before each commit.
These hooks help catch errors early and keep the codebase consistent across contributors.
Before installing the hooks, make sure your system has:
- Python 3.9+ with
pipinstalled - Node.js and
npm(required formarkdownlint-cli2)
You can check your versions with:
python3 --version
pip --version
node --version
npm --versionmake install-hooksThis will:
- Install pre-commit (if not already installed)
- Register a Git hook in .git/hooks/pre-commit
- Automatically run checks like:
- Code formatting with black and isort
- Linting with ruff, yamllint, and ansible-lint
make test-hooksThis will run the pre-commit hooks on all files, the same as when you run git commit.
make uninstall-hooksThis removes the Git pre-commit hook and disables automatic checks.
💡 Even with hooks uninstalled, you can still run the same checks manually with make test-hooks.
Why Use Git Hooks?
- Ensures consistency across contributors
- Catches syntax and style issues before they hit CI
- Prevents accidental commits of broken or misformatted files
- Integrates seamlessly with your local workflow