Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Creating Development Environments with Vagrant Second Edition

You're reading from   Creating Development Environments with Vagrant Second Edition Leverage the power of Vagrant to create and manage virtual development environments with Puppet, Chef, and VirtualBox

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784397029
Length 156 pages
Edition 2nd Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
MICHAEL KEITH PEACOCK MICHAEL KEITH PEACOCK
Author Profile Icon MICHAEL KEITH PEACOCK
MICHAEL KEITH PEACOCK
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Creating Development Environments with Vagrant Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Vagrant FREE CHAPTER 2. Managing Vagrant Boxes and Projects 3. Provisioning with Puppet 4. Using Ansible 5. Using Chef 6. Provisioning Vagrant Machines with Puppet, Ansible, and Chef 7. Working with Multiple Machines 8. Creating Your Own Box 9. HashiCorp Atlas A Sample LEMP Stack Index

Default manifest


Finally, we need to pull these modules together, and install them when our machine is provisioned. To do this, we simply add the following modules to our vagrant.pp manifest file in the provision/manifests folder.

Installing Nginx and PHP

We need to include our nginx class and optionally provide a filename for the configuration file; if we don't provide one, the default will be used:

class {
    'nginx':
        file => 'default'
}

Similarly for PHP, we need to include the class and in this case, pass an nginx parameter to ensure that it installs PHP5-FPM too:

class {
    'php':
        nginx => true
}

Hostname configuration

We should tell our Vagrant virtual machine what its hostname is by adding a host resource to our manifest:

host { 'lemp-stack.local':
    ip => '127.0.0.1',
    host_aliases => 'localhost',
}

E-mail sending services

Because some of our projects might involve sending e-mails, we should install e-mail sending services on our virtual machine. As these are simply two packages, it makes more sense to include them in our Vagrant manifest, as opposed to their own modules:

package { "postfix":
    ensure => present
}

package { "mailutils":
    ensure => present
}

MySQL configuration

Because the MySQL module is very flexible and manages all aspects of MySQL, there is quite a bit for us to configure. We need to perform the following steps:

  1. Create a database.

  2. Create a user.

  3. Give the user permission to use the database (grants).

  4. Configure the MySQL root password.

  5. Install the MySQL client.

  6. Install the MySQL client bindings for PHP.

The MySQL server class has a range of parameters that can be passed to configure it, including databases, users, and grants. So, first, we need to define what the databases, users, and grants are that we want to be configured:

$databases = {
  'lemp' => {
    ensure  => 'present',
    charset => 'utf8'
  },
}

$users = {
  'lemp@localhost' => {
    ensure                   => 'present',
    max_connections_per_hour => '0',
    max_queries_per_hour     => '0',
    max_updates_per_hour     => '0',
    max_user_connections     => '0',
    password_hash            => 'MySQL-Password-Hash',
  },
}

Note

The password_hash parameter here is for a hash generated by MySQL. You can generate a password hash by connecting to an existing MySQL instance and running a query such as SELECT PASSWORD('password').

The grant maps our user and database and specifies what permissions the user can perform on that database when connecting from a particular host (in this case, localhost—so from the virtual machine itself):

$grants = {
  'lemp@localhost/lemp.*' => {
    ensure     => 'present',
    options    => ['GRANT'],
    privileges => ['ALL'],
    table      => 'lemp.*',
    user       => 'lemp@localhost',
  },
}

We then pass these values to the MySQL server class. We also provide a root password for MySQL (unlike earlier, this is provided in plain text), and we can override the options from the MySQL configuration file. This is unlike our own Nginx module that provides a full file—in this instance, the MySQL module provides a template configuration file and the changes are replaced in that template to create a configuration file:

class { '::mysql::server':
  root_password    => 'lemp-root-password',
  override_options => { 'mysqld' => { 'max_connections' => '1024' } },
  databases => $databases,
  users => $users,
  grants => $grants,
  restart => true
}

As we will have a web server running on this machine, which needs to connect to this database server, we also need the client library and the client bindings for PHP, so that we can include them too:

include '::mysql::client'

class { '::mysql::bindings':
  php_enable => true
}
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images