
上QQ阅读APP看书,第一时间看更新
Running the role
Now that the role for the final element of our LAMP stack is complete, we can add it to our playbook. It should now look like the following:
---
- hosts: boxes
gather_facts: true
become: yes
become_method: sudo
vars_files:
- group_vars/common.yml
roles:
- roles/common
- roles/apache
- roles/mariadb
- roles/php
Run it by using the following command:
$ ansible-playbook -i production site.yml
This will deploy PHP on our Vagrant box; this output picks up as the PHP role is called:
TASK [roles/php : install the php packages] ********************************************************
changed: [box] => (item=[u'php72u', u'php72u-bcmath', u'php72u-cli', u'php72u-common', u'php72u-dba', u'php72u-fpm', u'php72u-fpm-httpd', u'php72u-gd', u'php72u-intl', u'php72u-json', u'php72u-mbstring', u'php72u-mysqlnd', u'php72u-odbc', u'php72u-pdo', u'php72u-process', u'php72u-snmp', u'php72u-soap', u'php72u-xml', u'php72u-xmlrpc'])
TASK [roles/php : copy the test PHP page to the document root] *************************************
changed: [box]
TASK [roles/php : create the document root for adminer] ********************************************
changed: [box]
TASK [roles/php : download adminer] ****************************************************************
changed: [box]
TASK [roles/php : copy the vhost.conf to /etc/httpd/conf.d/] ***************************************
changed: [box]
RUNNING HANDLER [roles/common : restart ntp] *******************************************************
changed: [box]
RUNNING HANDLER [roles/apache : restart httpd] *****************************************************
changed: [box]
RUNNING HANDLER [roles/php : restart php-fpm] ******************************************************
changed: [box]
PLAY RECAP *****************************************************************************************
box : ok=34 changed=32 unreachable=0 failed=0
Once installed, you should be able to access the following URLs:
- http://192.168.50.4.nip.io/info.php
- http://192.168.50.4.nip.io/adminer/
When you go to the first link, you should see something like the following page:

At the second link, once logged in using the username root and password Pa55W0rd123, you should be able to see the employees database:

With Adminer, we have a PHP script accessing our MariaDB database; the pages are being served by Apache from our Linux Vagrant box.