├── files └── redis.ini ├── vars ├── Debian.yml └── RedHat.yml ├── .ansible-lint ├── .gitignore ├── .github ├── FUNDING.yml └── workflows │ ├── release.yml │ ├── ci.yml │ └── stale.yml ├── molecule └── default │ ├── requirements.yml │ ├── molecule.yml │ ├── redis-test.php │ └── converge.yml ├── .yamllint ├── defaults └── main.yml ├── meta └── main.yml ├── tasks ├── install-from-source.yml └── main.yml ├── LICENSE └── README.md /files/redis.ini: -------------------------------------------------------------------------------- 1 | extension=redis.so 2 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __php_redis_package: php-redis 3 | -------------------------------------------------------------------------------- /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __php_redis_package: php-pecl-redis5 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /molecule/default/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - src: geerlingguy.repo-epel 3 | - src: geerlingguy.repo-remi 4 | - src: geerlingguy.redis 5 | - src: geerlingguy.php 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 120 7 | level: warning 8 | 9 | ignore: | 10 | .github/workflows/stale.yml 11 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Pass in a comma-separated list of repos to use (e.g. "remi,epel"). 3 | php_enablerepo: epel 4 | 5 | # Whether to install the extension from source or from an apt or yum repo. 6 | php_redis_install_from_source: false 7 | php_redis_source_repo: https://github.com/phpredis/phpredis.git 8 | php_redis_source_version: develop 9 | php_redis_source_clone_dir: ~/phpredis 10 | php_redis_source_configure_command: "./configure" 11 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - geerlingguy.php 4 | 5 | galaxy_info: 6 | role_name: php-redis 7 | author: geerlingguy 8 | description: PhpRedis support for Linux 9 | company: "Midwestern Mac, LLC" 10 | license: "license (BSD, MIT)" 11 | min_ansible_version: 2.10 12 | platforms: 13 | - name: Debian 14 | versions: 15 | - all 16 | - name: Ubuntu 17 | versions: 18 | - all 19 | galaxy_tags: 20 | - database 21 | - web 22 | - php 23 | - redis 24 | - cache 25 | - performance 26 | - kv 27 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /molecule/default/redis-test.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 15 | 16 | // Test adding a value to redis. 17 | if ($redis->set($key, $value)) { 18 | $result = $redis->get($key); 19 | 20 | // If we get the expected result, it was a success. 21 | if ($result == $value) { 22 | $success = TRUE; 23 | print "Redis connection successful.\r\n"; 24 | exit(0); 25 | } 26 | } 27 | } 28 | 29 | if (!$success) { 30 | print "Redis not working properly.\r\n"; 31 | exit(1); 32 | } 33 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | php_enable_webserver: false 8 | php_enablerepo: "epel,remi,remi-php82" 9 | 10 | pre_tasks: 11 | - name: Update apt cache. 12 | apt: update_cache=yes cache_valid_time=600 13 | when: ansible_facts.os_family == 'Debian' 14 | 15 | roles: 16 | - role: geerlingguy.repo-epel 17 | when: ansible_facts.os_family == 'RedHat' 18 | - role: geerlingguy.repo-remi 19 | when: ansible_facts.os_family == 'RedHat' 20 | - role: geerlingguy.redis 21 | - role: geerlingguy.php 22 | - role: geerlingguy.php-redis 23 | 24 | post_tasks: 25 | - name: Run test script to confirm Redis is reachable via PHP. 26 | script: redis-test.php 27 | args: 28 | executable: php 29 | changed_when: false 30 | -------------------------------------------------------------------------------- /tasks/install-from-source.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Clone the PhpRedis repo. 3 | git: 4 | repo: "{{ php_redis_source_repo }}" 5 | dest: "{{ php_redis_source_clone_dir }}" 6 | version: "{{ php_redis_source_version }}" 7 | accept_hostkey: true 8 | depth: 1 9 | 10 | - name: Run phpize. 11 | command: > 12 | phpize 13 | chdir={{ php_redis_source_clone_dir }} 14 | creates={{ php_extension_conf_paths[0] }}/redis.ini 15 | 16 | - name: Run configure script. 17 | command: > 18 | {{ php_redis_source_configure_command }} 19 | chdir={{ php_redis_source_clone_dir }} 20 | creates={{ php_extension_conf_paths[0] }}/redis.ini 21 | 22 | - name: Make and install PHP. 23 | command: > 24 | {{ item }} 25 | chdir={{ php_redis_source_clone_dir }} 26 | creates={{ php_extension_conf_paths[0] }}/redis.ini 27 | with_items: 28 | - make 29 | - make install 30 | 31 | - name: Ensure the Redis extension is present in PHP's configuration. 32 | copy: 33 | src: redis.ini 34 | dest: "{{ php_extension_conf_paths[0] }}/redis.ini" 35 | mode: 0644 36 | notify: restart webserver 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Include variables and define needed variables. 3 | - name: Include OS-specific variables. 4 | include_vars: "{{ ansible_facts.os_family }}.yml" 5 | 6 | - name: Define php_redis_package. 7 | set_fact: 8 | php_redis_package: "{{ __php_redis_package }}" 9 | when: php_redis_package is not defined 10 | 11 | # Install PhpRedis from the system package manager. 12 | - name: Install PhpRedis extension (RedHat). 13 | yum: 14 | name: "{{ php_redis_package }}" 15 | state: present 16 | enablerepo: "{{ php_enablerepo | default(omit, true) }}" 17 | notify: 18 | - restart webserver 19 | - restart php-fpm 20 | when: 21 | - not php_redis_install_from_source 22 | - ansible_facts.os_family == 'RedHat' 23 | 24 | - name: Install PhpRedis extension (Debian). 25 | apt: "name={{ php_redis_package }} state=present" 26 | notify: 27 | - restart webserver 28 | - restart php-fpm 29 | when: 30 | - not php_redis_install_from_source 31 | - ansible_facts.os_family == 'Debian' 32 | 33 | # Install PhpRedis from source. 34 | - include_tasks: install-from-source.yml 35 | when: php_redis_install_from_source 36 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.php-redis' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.php-redis' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.13' # Can't go to 3.14+ until Ansible 13.x 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "30 1 * * 4" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.php-redis' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v4 23 | with: 24 | path: 'geerlingguy.php-redis' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.13' # Can't go to 3.14+ until Ansible 13.x 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | distro: 44 | - rockylinux9 45 | - ubuntu2204 46 | 47 | steps: 48 | - name: Check out the codebase. 49 | uses: actions/checkout@v4 50 | with: 51 | path: 'geerlingguy.php-redis' 52 | 53 | - name: Set up Python 3. 54 | uses: actions/setup-python@v5 55 | with: 56 | python-version: '3.13' # Can't go to 3.14+ until Ansible 13.x 57 | 58 | - name: Install test dependencies. 59 | run: pip3 install ansible molecule molecule-plugins[docker] docker 60 | 61 | - name: Run Molecule tests. 62 | run: molecule test 63 | env: 64 | PY_COLORS: '1' 65 | ANSIBLE_FORCE_COLOR: '1' 66 | MOLECULE_DISTRO: ${{ matrix.distro }} 67 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Close inactive issues 3 | 'on': 4 | schedule: 5 | - cron: "55 3 * * 6" # semi-random time 6 | 7 | jobs: 8 | close-issues: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - uses: actions/stale@v8 15 | with: 16 | days-before-stale: 120 17 | days-before-close: 60 18 | exempt-issue-labels: bug,pinned,security,planned 19 | exempt-pr-labels: bug,pinned,security,planned 20 | stale-issue-label: "stale" 21 | stale-pr-label: "stale" 22 | stale-issue-message: | 23 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 24 | 25 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 26 | close-issue-message: | 27 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 28 | stale-pr-message: | 29 | This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 30 | 31 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 32 | close-pr-message: | 33 | This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 34 | repo-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: PhpRedis 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-php-redis/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-php-redis/actions/workflows/ci.yml) 4 | 5 | Installs PhpRedis support on Linux. 6 | 7 | ## Requirements 8 | 9 | This role doesn't *explicitly* require Redis to be installed, but if you don't have the daemon running somewhere (either on the same server, or somewhere else), this role won't be all that helpful. Check out `geerlingguy.redis` for a simple role to install and configure Redis (either on the same server, or separate servers). 10 | 11 | On newer RHEL systems, you should also install EPEL (I use the `geerlingguy.repo-epel` role to install this). 12 | 13 | ## Role Variables 14 | 15 | Available variables are listed below, along with default values (see `defaults/main.yml`): 16 | 17 | php_enablerepo: epel 18 | 19 | (RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install the latest version of PHP from Remi's repository. 20 | 21 | php_redis_package: php-redis 22 | 23 | (Default for Debian/Ubuntu shown). If installing from apt or yum, which package to install which provides the PhpRedis extension. 24 | 25 | ### Install from source 26 | 27 | If you want to install PhpRedis directly from source (if you're on an OS that doesn't have it available as a package, or if you want a newer version than is available through your package manager), you can use the variables below to configure the source installation: 28 | 29 | php_redis_install_from_source: false 30 | 31 | Whether to install PhpRedis from source. If you'd like to install a specific version of PhpRedis not available via the system package manager, you can compile the extension from source. 32 | 33 | php_redis_source_repo: https://github.com/phpredis/phpredis.git 34 | 35 | The git repository for the PhpRedis extension. 36 | 37 | php_redis_source_version: develop 38 | 39 | The branch, tag, or commit hash to use when cloning the source repository. Can be a branch (e.g. `develop` or `php7`), a tag (e.g. `2.2.7`), or a commit hash (e.g. `5241a5c`). 40 | 41 | php_redis_source_clone_dir: ~/phpredis 42 | 43 | The location where the PhpRedis source code will be cloned locally. 44 | 45 | php_redis_source_configure_command: "./configure" 46 | 47 | The command to configure a PhpRedis source install. You can modify this command if you want to do something like add `--enable-redis-igbinary`. 48 | 49 | ## Dependencies 50 | 51 | - geerlingguy.php 52 | 53 | ## Example Playbook 54 | 55 | - hosts: webservers 56 | roles: 57 | - { role: geerlingguy.repo-epel } 58 | - { role: geerlingguy.php-redis } 59 | 60 | ## License 61 | 62 | MIT / BSD 63 | 64 | ## Author Information 65 | 66 | This role was created in 2015 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 67 | --------------------------------------------------------------------------------