422 Role vbotka.freebsd.apache PHP¶
Use case¶
Use the role vbotka.freebsd.apache to configure PHP in Apache HTTP Server. Use iocage property
host_hostname to create a jail.
Tree¶
shell> tree .
.
├── ansible.cfg
├── hosts
├── host_vars
│ ├── iocage_04
│ │ └── ansible-client-apache.yml
│ └── www-4
│ └── apache.yml
├── iocage.ini
└── pb-apache.yml
Synopsis¶
The playbook vbotka.freebsd.pb_iocage_ansible_clients.yml creates and starts one jail.
The playbook
pb-apache.ymlconfigures PHP in the Apache HTTP Server in the jail.
Requirements¶
Template
ansible_client_apachecreated in 209 Create iocage pkglist file
Notes¶
iocagepropertyhost_hostnameprovides “The hostname of the jail.”. Please note thatiocageoption--nameprovides “NAME instead of a UUID for the new jail”.In case of DHCP,
host_hostnameresolves, however--namedoes not.
ansible.cfg¶
[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false
[connection]
pipelining = true
Inventory iocage.ini¶
iocage_04 ansible_host=10.1.0.29
[iocage]
iocage_04
[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
host_vars¶
host_vars/iocage_04/ansible-client-apache.yml¶
properties:
notes: "vmm={{ inventory_hostname }}"
bpf: 1
dhcp: 1
vnet: 1
clones_host_hostname:
www-4:
template: ansible_client_apache
host_vars/www-4/apache.yml¶
apache_install: false
apache_confd: false
apache_servername: www-4
apache_serveradmin: admin@www-4
apache_httpd_conf_modules:
- {module: php_module, mod: libphp.so}
apache_directory_blocks:
- Directory: /usr/local/www/apache24/data/
Includefile: usr-local-www-apache-data.conf
Conf:
- "DirectoryIndex index.php index.html index.htm"
- "AddType application/x-httpd-php .php"
- "AddType application/x-httpd-php-source .phps"
- "Options Indexes FollowSymLinks"
- "AllowOverride All"
- "Require all granted"
Create and start jails¶
(env) > ansible-playbook vbotka.freebsd.pb_iocage_ansible_clients.yml \
-i iocage.ini \
-t clone_host_hostname -e clone_host_hostname=true
PLAY [Create and start jails. Optionally stop and destroy jails.] **************
TASK [Create clones host_hostname] *********************************************
changed: [iocage_04] => (item=www-4 ansible_client_apache)
TASK [Start clones host_hostname] **********************************************
changed: [iocage_04]
PLAY RECAP *********************************************************************
iocage_04 : ok=2 changed=2 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0
Inventory hosts¶
hosts¶
www-4
[www]
www-4
[www:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
Playbook pb-apache.yml¶
- name: Create Apache HTTP Server.
hosts: www
gather_facts: true
roles:
- vbotka.freebsd.apache
Playbook output - Create server¶
(env) > ansible-playbook pb-apache.yml -i hosts
PLAY [Create Apache HTTP Server.] **********************************************
TASK [Gathering Facts] *********************************************************
ok: [www-4]
TASK [Vars: Include OS vars.] **************************************************
included: vbotka.freebsd.lib for www-4
TASK [vbotka.freebsd.lib : Al_include_os_vars_path: Vars from /scratch/collections/ansible_collections/vbotka/freebsd/roles/apache/vars/defaults] ***
ok: [www-4]
TASK [vbotka.freebsd.apache : Httpd-conf: Configure parameters in /usr/local/etc/apache24/httpd.conf] ***
changed: [www-4] => (item={'regexp': 'ServerName', 'line': 'www-4'})
changed: [www-4] => (item={'regexp': 'ServerAdmin', 'line': 'admin@www-4'})
changed: [www-4] => (item={'regexp': 'ServerTokens', 'line': 'Prod'})
TASK [vbotka.freebsd.apache : Httpd-dirs: Configure directories in /usr/local/etc/apache24/Includes/] ***
changed: [www-4] => (item=/usr/local/www/apache24/data/)
TASK [vbotka.freebsd.apache : Httpd-modules: Load modules in /usr/local/etc/apache24/httpd.conf] ***
changed: [www-4] => (item={'module': 'php_module', 'mod': 'libphp.so'})
TASK [vbotka.freebsd.apache : Rc-conf: Enable and Start Apache] ****************
changed: [www-4]
RUNNING HANDLER [vbotka.freebsd.apache : Enable and start apache] **************
changed: [www-4]
RUNNING HANDLER [vbotka.freebsd.apache : Restart apache] ***********************
changed: [www-4]
RUNNING HANDLER [vbotka.freebsd.apache : Reload apache] ************************
ok: [www-4]
PLAY RECAP *********************************************************************
www-4 : ok=10 changed=6 unreachable=0 failed=0 skipped=33 rescued=0 ignored=0
Create info.php¶
(env) > ssh admin@www-4 cat /usr/local/www/apache24/data/info.php
<?php
phpinfo();
?>
Results¶
Test the configuration
(env) > ssh admin@www-4 sudo service apache24 configtest Performing sanity check on apache24 configuration: Syntax OK
In a browser, open the page
http://www-4/info.php. The content should be