Building a LAMP system using Puppet

I have always been interested in sysadmin, however the thing that annoyed me was trying to remember the config file contents. Back in the day when I used to work for Boss Pacific Information Systems, I would find the idea of setting up servers very interesting. In the mean time, the tedious task of remembering which config file to change and what to change was a bit daunting.

Recently, I have been introduced to Puppet script which has been used in my work environment has proven its importance.

“Puppet manages your servers: you describe machine configurations in an easy-to-read declarative language, and Puppet will bring your systems into the desired state and keep them there.”

This tutorial will show you how to create a simple puppet script to build a LAMP system which is the base for any web system. The components required for a web system such as apache, mysql etc are all available as modules from Puppet Forge

First things first, install puppet using yum

yum install puppet-server puppet

By default puppet is installed in /etc/puppet path.

Now onto installing web server components, you have to be in /etc/puppet/modules path and run the following commands.

puppet module install puppetlabs/apache
puppet module install puppetlabs/mysql
puppet module install rabinshr/rabinshr_phpmyadmin_1_0

The above commands will install puppet modules for apache and mysql. To learn more about installing modules, visit the documentation here.

We now have the modules ready, its now time to create a manifest file that will use these modules and create a web server. My manifest file has the following code:

node puppet{
    $db_password = 'db_password_here'
    include apache
    include apache::mod::php
    class{'mysql::server':
        config_hash => {'root_password' => $db_password}
    }
    class{'mysql::php':}

    class { 'phpmyadmin':
        db_user     => '',
        db_password => '',
        blowfish    => 'abcedf1234true',
     }
}

To create a new database you can add the following code to your manifest:

mysql::db{'db_name_here':
	user => 'root',
	password => 'db_password_here'
}

To run this manifest, simply execute the following command.

puppet apply path_to_your_manifest_file

Leave a Reply

Your email address will not be published. Required fields are marked *