Puppet forge has modules for installing and maintaining Apache and MySQL.
Here's how you can use them to set up a LAMP stack.
Install Apache and MySQL Modules:
sudo puppet module install puppetlabs-apache
Notice: Preparing to install into /etc/puppetlabs/puppet/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-apache (v1.0.1)
├── puppetlabs-concat (v1.0.0) [/etc/puppet/modules]
└── puppetlabs-stdlib (v3.2.0) [/etc/puppet/modules]
sudo puppet module install puppetlabs-mysql
Now the apache and mysql modules are available for use!
Edit the Main Manifest:
-
Now edit the main manifest so it uses the new modules to install LAMP stack.
-
On the Puppet master, edit the main manifest:
sudo vi /etc/puppet/manifests/site.pp
Assuming the file is empty, add the following node blocks :
node default { }
node 'lamp-1' {
}
class { 'apache': # use the "apache" module
default_vhost => false, # don't use the default vhost
default_mods => false, # don't load default mods
mpm_module => 'prefork', # use the "prefork" mpm_module
}
include apache::mod::php # include mod php
apache::vhost { 'example.com': # create a vhost called "example.com"
port => '80', # use port 80
docroot => '/var/www/html', # set the docroot to the /var/www/html
}
-
The apache module can be passed parameters that override the default behavior of the module. We are passing in some basic settings that disable the default virtual host that the module creates, and make sure we create a virtual host that can use PHP.
-
Using the MySQL module is similar to using the Apache module. We will keep it simple since we are not actually using the database at this point. Add the following lines within the node block:
class { 'mysql::server':
root_password => 'password',
}
file { 'info.php': # file resource name
path => '/var/www/html/info.php', # destination path
ensure => file,
require => Class['apache'], # require apache class be used
source => 'puppet:///modules/apache/info.php', # specify location of file to be copied
}
-
Here in the file resource declaration we are specifying the source parameter instead of the content parameter. Source tells puppet to copy a file over, instead of simply specifying the file's contents. The specified source, puppet:///modules/apache/info.php gets interpreted by Puppet into /etc/puppet/modules/apache/files/info.php, so we must create the source file in order for this resource declaration to work properly.
-
Save and exit site.pp.
-
Create the info.php file with the following command:
sudo sh -c 'echo "<?php phpinfo(); ?>" > /etc/puppet/modules/apache/files/info.php'
-
The next time your lamp-1 Puppet agent node pulls its configuration from the master, it will evaluate the main manifest and apply the module that specifies a LAMP stack setup. If you want to try it out immediately, run the following command on the lamp-1 agent node:
sudo puppet agent --test
http://lamp_1_public_IP/info.php
You should be able to see the information page for your PHP installation.