Skip to content

Commit 5c2dd91

Browse files
authored
Add example of how to configure php for el9 based systems (#811)
* Add example of how to configure php for el9 based systems Drop centos stream 8, ubuntu 18.04 and Debian 10 Signed-off-by: Mike van Goor <mvangoor@schubergphilis.com> * php on el9 requires different inspec tests and fix opensuse Signed-off-by: Mike van Goor <mvangoor@schubergphilis.com> --------- Signed-off-by: Mike van Goor <mvangoor@schubergphilis.com>
1 parent e05c008 commit 5c2dd91

File tree

12 files changed

+121
-73
lines changed

12 files changed

+121
-73
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,33 @@ jobs:
2626
- almalinux-8
2727
- almalinux-9
2828
- amazonlinux-2023
29-
- centos-stream-8
3029
- centos-stream-9
31-
- debian-10
3230
- debian-11
3331
- debian-12
3432
- fedora-latest
3533
- opensuse-leap-15
34+
- oraclelinux-8
35+
- oraclelinux-9
3636
- rockylinux-8
3737
- rockylinux-9
38-
- ubuntu-1804
3938
- ubuntu-2004
4039
- ubuntu-2204
4140
suite:
4241
- basic-site
4342
- default
4443
- mod-auth-cas
45-
- mod-php
44+
- php
4645
- module-template
4746
- mod-wsgi
4847
- ports
4948
- ssl
5049
- install-override
5150
exclude:
51+
# TODO: disabled due to https://github.com/chef/chef/pull/13691
5252
- os: amazonlinux-2023
5353
suite: mod-wsgi
54-
# TODO: disabled due to https://github.com/chef/chef/pull/13691
5554
- os: opensuse-leap-15
5655
suite: mod-wsgi
57-
# mod_php is considered old. PHP-FPM is the new hotness.
58-
- os: amazonlinux-2023
59-
suite: mod-php
60-
- os: almalinux-9
61-
suite: mod-php
62-
- os: centos-stream-9
63-
suite: mod-php
64-
- os: fedora-latest
65-
suite: mod-php
66-
- os: rockylinux-9
67-
suite: mod-php
6856
steps:
6957
- name: Check out code
7058
uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This file is used to list changes made in each version of the apache2 cookbook.
44

55
## Unreleased
66

7+
- Add example of how to configure php fpm pool config for rhel9 and derivatives
8+
79
## 9.3.3 - *2024-07-15*
810

911
Standardise files with files in sous-chefs/repo-management

documentation/resource_apache2_mod.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ This will use a template resource to write the module's configuration file in th
88

99
## Properties
1010

11-
| Name | Type | Default | Description |
12-
| ------------ | ------ | --------------------------- | ---------------------------------------------------------------------- |
13-
| `template` | String | | Name of the template |
14-
| `root_group` | String | `node['root_group']` | Set to override the platforms default root group for the template file |
15-
| `template_cookbook` | String | `apache2` | Cookbook containing the template file
11+
| Name | Type | Default | Description |
12+
| ------------------- | ------ | --------------------------- | ---------------------------------------------------------------------- |
13+
| `template` | String | | Name of the template |
14+
| `root_group` | String | `node['root_group']` | Set to override the platforms default root group for the template file |
15+
| `template_cookbook` | String | `apache2` | Cookbook containing the template file |
1616

1717
## Examples
1818

kitchen.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ platforms:
1616
- name: almalinux-8
1717
- name: almalinux-9
1818
- name: amazonlinux-2023
19-
- name: centos-stream-8
2019
- name: centos-stream-9
21-
- name: debian-10
2220
- name: debian-11
2321
- name: debian-12
22+
- name: fedora-latest
2423
- name: opensuse-leap-15
24+
- name: oraclelinux-8
25+
- name: oraclelinux-9
2526
- name: rockylinux-8
2627
- name: rockylinux-9
27-
- name: ubuntu-18.04
2828
- name: ubuntu-20.04
2929
- name: ubuntu-22.04
30+
- name: ubuntu-24.04
3031

3132
suites:
3233
- name: default
@@ -47,16 +48,9 @@ suites:
4748
- name: module_template
4849
run_list:
4950
- recipe[test::module_template]
50-
- name: mod_php
51+
- name: php
5152
run_list:
5253
- recipe[test::php]
53-
excludes:
54-
- almalinux-9
55-
- amazonlinux-2023
56-
- centos-stream-9
57-
- fedora-latest
58-
- oraclelinux-9
59-
- rockylinux-9
6054
- name: mod_wsgi
6155
run_list:
6256
- recipe[test::wsgi]

spec/resources/mod_php_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
it do
3434
is_expected.to enable_apache2_module('php').with(
35-
identifier: 'php7_module',
36-
mod_name: 'libphp7.4.so'
35+
identifier: 'php_module',
36+
mod_name: 'libphp8.1.so'
3737
)
3838
end
3939
end

test/cookbooks/test/metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
depends 'apache2'
1010
depends 'apt'
1111
# depends 'yum-ius'
12+
depends 'php'

test/cookbooks/test/recipes/php.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@
33
notifies :restart, 'apache2_service[default]'
44
end
55

6-
apache2_mod_php '' do
7-
notifies :reload, 'apache2_service[default]'
6+
if apache_mod_php_supported?
7+
apache2_mod_php '' do
8+
notifies :reload, 'apache2_service[default]'
9+
end
10+
else
11+
apache2_module 'proxy' do
12+
notifies :reload, 'apache2_service[default]'
13+
end
14+
apache2_module 'proxy_fcgi' do
15+
notifies :reload, 'apache2_service[default]'
16+
end
17+
apache2_mod_proxy 'proxy' do
18+
notifies :reload, 'apache2_service[default]'
19+
end
20+
php_fpm_pool 'nagios' do
21+
user default_apache_user
22+
group default_apache_group
23+
listen_user default_apache_user
24+
listen_group default_apache_group
25+
notifies :install, 'apache2_install[default]'
26+
end
27+
apache2_conf 'custom_php_pool' do
28+
template_cookbook 'test'
29+
options(
30+
apache_php_handler: "proxy:unix:#{php_fpm_socket}|fcgi://localhost"
31+
)
32+
notifies :reload, 'apache2_service[default]'
33+
end
834
end
935

1036
file "#{default_docroot_dir}/info.php" do
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
2+
SetHandler "<%= @apache_php_handler %>"
3+
</FilesMatch>

test/integration/mod_auth_cas/controls/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
httpd_command =
66
case os.family
7-
when 'fedora', 'amazon'
7+
when 'fedora', 'amazon', 'suse'
88
'httpd -M'
99
when 'redhat'
1010
os.release.to_i >= 9 ? 'httpd -M' : 'apachectl -M'

test/integration/mod_php/controls/default.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
include_controls 'apache2-default' do
2+
skip_control 'welcome-page'
3+
end
4+
5+
httpd_command =
6+
case os.family
7+
when 'fedora', 'amazon', 'suse'
8+
'httpd -M'
9+
when 'redhat'
10+
os.release.to_i >= 9 ? 'httpd -M' : 'apachectl -M'
11+
else
12+
'apachectl -M'
13+
end
14+
15+
control 'PHP module enabled & running' do
16+
impact 1
17+
desc 'php module should be enabled with config'
18+
19+
if (os['family'] == 'redhat' && os['release'].to_i >= 9) || os['family'] == 'fedora'
20+
describe command httpd_command do
21+
its('stdout') { should match(/proxy_fcgi/) }
22+
end
23+
else
24+
describe command httpd_command do
25+
its('stdout') { should match(/php/) }
26+
end
27+
end
28+
29+
case os['family']
30+
when 'debian', 'suse'
31+
describe file('/etc/apache2/mods-available/php.conf') do
32+
it { should exist }
33+
its('content') { should match %r{SetHandler application/x-httpd-php} }
34+
end
35+
when 'freebsd'
36+
describe file('/usr/local/etc/apache24/mods-available/php.conf') do
37+
it { should exist }
38+
its('content') { should match %r{SetHandler application/x-httpd-php} }
39+
end
40+
when 'redhat', 'fedora'
41+
if os['release'].to_i >= 9
42+
describe service('php-fpm') do
43+
it { should be_installed }
44+
it { should be_enabled }
45+
it { should be_running }
46+
end
47+
48+
describe file('/etc/httpd/conf-available/custom_php_pool.conf') do
49+
it { should exist }
50+
its('content') { should match %r{proxy:unix:/var/run/php.*-fpm.sock|fcgi://localhost} }
51+
end
52+
else
53+
describe file('/etc/httpd/mods-available/php.conf') do
54+
it { should exist }
55+
its('content') { should match %r{SetHandler application/x-httpd-php} }
56+
end
57+
end
58+
else
59+
describe file('/etc/httpd/mods-available/php.conf') do
60+
it { should exist }
61+
its('content') { should match %r{SetHandler application/x-httpd-php} }
62+
end
63+
end
64+
65+
describe http('localhost/info.php') do
66+
its('status') { should eq 200 }
67+
its('body') { should match /PHP Version/ }
68+
end
69+
end

test/integration/mod_php/inspec.yml renamed to test/integration/php/inspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: apache2-mod-php
2+
name: apache2-php
33
title: Integration tests for apache2 cookbook
44
summary: This InSpec profile contains integration tests for apache2 cookbook
55
supports:

0 commit comments

Comments
 (0)