Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin-harangus committed Oct 15, 2012
0 parents commit c546e55
Show file tree
Hide file tree
Showing 24 changed files with 800 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[submodule "chef/cookbooks/apache2"]
path = chef/cookbooks/apache2
url = https://github.com/opscode-cookbooks/apache2.git
[submodule "chef/cookbooks/mysql"]
path = chef/cookbooks/mysql
url = https://github.com/opscode-cookbooks/mysql.git
[submodule "chef/cookbooks/php"]
path = chef/cookbooks/php
url = https://github.com/opscode-cookbooks/php.git
[submodule "chef/cookbooks/apt"]
path = chef/cookbooks/apt
url = https://github.com/opscode-cookbooks/apt.git
[submodule "chef/cookbooks/git"]
path = chef/cookbooks/git
url = https://github.com/opscode-cookbooks/git.git
[submodule "chef/cookbooks/imagemagick"]
path = chef/cookbooks/imagemagick
url = https://github.com/opscode-cookbooks/imagemagick.git
[submodule "chef/cookbooks/openssl"]
path = chef/cookbooks/openssl
url = https://github.com/opscode-cookbooks/openssl.git
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Documentation
=============

This repository contains a general vagrant configuration for developing web applications using PHP and Zend Framework.

The package installs the following:
- ubuntu
- apache2
- php 5.3 with xdebug
- mysql
- apt
- imagemagick
- git
- phpmyadmin
- webgrind

Configuration
=============

Before going ahead and installing all packages there are a few configuration items that you should be aware of.

First of all you should edit the Vagrantfile to set up any virtual hosts you need.
By default this file defines 2 virtual hosts:

```
sites:[
{
name: "zf2app",
docroot: "/vagrant/www/",
server_name: "www.zf2app.dev",
server_aliases: ["www.zf2app.dev"],
},{
name: "debug.zf2app",
docroot: "/var/www/webgrind/",
server_name: "debug.zf2app.dev",
server_aliases: ["debug.zf2app.dev"],
}
],
```

The first one is your main application and it is pointing to the `www/` folder within your project.
The second one is used for debugging your code with XDEBUG.

Make sure you add these domain names to your hosts file using the following line:

```
127.0.0.1 www.zf2app.dev debug.zf2app.dev
```

You can create any number of virtual hosts by editing this Vagrantfile.

Apart from this you can also change the root mysql password, the loaded apache2 modules and any other setting from the used cookbooks.

Installation
============

In order to use this package you need to install [Vagrant](http://vagrantup.com/)and have a basic knowledge on how to use it.

Usage:

```
$ git clone https://github.com/ZendExperts/vagrant-base-lamp.git project
$ cd project
$ git submodule init
$ git submodule update
$ vagrant up
```

After the last command completes you should be able to access your application using the virtual hosts you defined(see configuration above) using port 8080: `http://www.zf2app.dev:8080/` and `http://debug.zf2app.dev:8080/`.

Credits
=======

The cookbooks have been taken from [Opscode Public Cookbooks](https://github.com/opscode-cookbooks/) and some code was used from [Yann Mainier](https://github.com/ymainier)'s vagrant-lamp repository to help with the debugging.
A few files were changed to better fit the development environment and a cookbook was added to put everything together.

Please use it any way you want and add any changes that can make this vagrant configuration perfect from developing custom PHP/Zend applications.
52 changes: 52 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "lucid64"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"

config.vm.define :project do |project_config|
project_config.vm.forward_port 80, 8080
# config.vm.boot_mode = :gui
# config.vm.share_folder "v-data", "/vagrant_data", "../data"


project_config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["chef/cookbooks/", "chef/site-cookbooks/"]

chef.run_list = ["recipe[site]"]
chef.json = {
sites:[
{
name: "zf2app",
docroot: "/vagrant/www/",
server_name: "www.zf2app.dev",
server_aliases: ["www.zf2app.dev"],
},{
name: "debug.zf2app",
docroot: "/var/www/webgrind/",
server_name: "debug.zf2app.dev",
server_aliases: ["debug.zf2app.dev"],
}
],
apache:{
default_site_enabled: false,
default_modules:[
"status","alias","auth_basic","authn_file","authz_default","authz_groupfile","authz_host","authz_user","autoindex","dir", "env", "mime", "negotiation", "setenvif",
"rewrite", "php5", "headers", "include"]
},
mysql:{
server_root_password: 'root'
}
}
end
end
end
65 changes: 65 additions & 0 deletions chef/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Rakefile for Chef Server Repository
#
# Author:: Adam Jacob (<[email protected]>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'rubygems'
require 'chef'
require 'json'

# Load constants from rake config file.
require File.join(File.dirname(__FILE__), 'config', 'rake')

# Detect the version control system and assign to $vcs. Used by the update
# task in chef_repo.rake (below). The install task calls update, so this
# is run whenever the repo is installed.
#
# Comment out these lines to skip the update.

if File.directory?(File.join(TOPDIR, ".svn"))
$vcs = :svn
elsif File.directory?(File.join(TOPDIR, ".git"))
$vcs = :git
end

# Load common, useful tasks from Chef.
# rake -T to see the tasks this loads.

load 'chef/tasks/chef_repo.rake'

desc "Bundle a single cookbook for distribution"
task :bundle_cookbook => [ :metadata ]
task :bundle_cookbook, :cookbook do |t, args|
tarball_name = "#{args.cookbook}.tar.gz"
temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
temp_cookbook_dir = File.join(temp_dir, args.cookbook)
tarball_dir = File.join(TOPDIR, "pkgs")
FileUtils.mkdir_p(tarball_dir)
FileUtils.mkdir(temp_dir)
FileUtils.mkdir(temp_cookbook_dir)

child_folders = [ "cookbooks/#{args.cookbook}", "site-cookbooks/#{args.cookbook}" ]
child_folders.each do |folder|
file_path = File.join(TOPDIR, folder, ".")
FileUtils.cp_r(file_path, temp_cookbook_dir) if File.directory?(file_path)
end

system("tar", "-C", temp_dir, "-cvzf", File.join(tarball_dir, tarball_name), "./#{args.cookbook}")

FileUtils.rm_rf temp_dir
end
38 changes: 38 additions & 0 deletions chef/config/rake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Configure the Rakefile's tasks.

###
# Company and SSL Details
# Used with the ssl_cert task.
###

# The company name - used for SSL certificates, and in srvious other places
COMPANY_NAME = "Example Com"

# The Country Name to use for SSL Certificates
SSL_COUNTRY_NAME = "US"

# The State Name to use for SSL Certificates
SSL_STATE_NAME = "Several"

# The Locality Name for SSL - typically, the city
SSL_LOCALITY_NAME = "Locality"

# What department?
SSL_ORGANIZATIONAL_UNIT_NAME = "Operations"

# The SSL contact email address
SSL_EMAIL_ADDRESS = "[email protected]"

# License for new Cookbooks
# Can be :apachev2 or :none
NEW_COOKBOOK_LICENSE = :apachev2

###
# Useful Extras (which you probably don't need to change)
###

# The top of the repository checkout
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))

# Where to store certificates generated with ssl_cert
CADIR = File.expand_path(File.join(TOPDIR, "certificates"))
54 changes: 54 additions & 0 deletions chef/cookbooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
This directory contains the cookbooks used to configure systems in your infrastructure with Chef.

Knife needs to be configured to know where the cookbooks are located with the `cookbook_path` setting. If this is not set, then several cookbook operations will fail to work properly.

cookbook_path ["./cookbooks"]

This setting tells knife to look for the cookbooks directory in the present working directory. This means the knife cookbook subcommands need to be run in the `chef-repo` directory itself. To make sure that the cookbooks can be found elsewhere inside the repository, use an absolute path. This is a Ruby file, so something like the following can be used:

current_dir = File.dirname(__FILE__)
cookbook_path ["#{current_dir}/../cookbooks"]

Which will set `current_dir` to the location of the knife.rb file itself (e.g. `~/chef-repo/.chef/knife.rb`).

Configure knife to use your preferred copyright holder, email contact and license. Add the following lines to `.chef/knife.rb`.

cookbook_copyright "Example, Com."
cookbook_email "[email protected]"
cookbook_license "apachev2"

Supported values for `cookbook_license` are "apachev2", "mit","gplv2","gplv3", or "none". These settings are used to prefill comments in the default recipe, and the corresponding values in the metadata.rb. You are free to change the the comments in those files.

Create new cookbooks in this directory with Knife.

knife cookbook create COOKBOOK

This will create all the cookbook directory components. You don't need to use them all, and can delete the ones you don't need. It also creates a README file, metadata.rb and default recipe.

You can also download cookbooks directly from the Opscode Cookbook Site. There are two subcommands to help with this depending on what your preference is.

The first and recommended method is to use a vendor branch if you're using Git. This is automatically handled with Knife.

knife cookbook site install COOKBOOK

This will:

* Download the cookbook tarball from cookbooks.opscode.com.
* Ensure its on the git master branch.
* Checks for an existing vendor branch, and creates if it doesn't.
* Checks out the vendor branch (chef-vendor-COOKBOOK).
* Removes the existing (old) version.
* Untars the cookbook tarball it downloaded in the first step.
* Adds the cookbook files to the git index and commits.
* Creates a tag for the version downloaded.
* Checks out the master branch again.
* Merges the cookbook into master.
* Repeats the above for all the cookbooks dependencies, downloading them from the community site

The last step will ensure that any local changes or modifications you have made to the cookbook are preserved, so you can keep your changes through upstream updates.

If you're not using Git, use the site download subcommand to download the tarball.

knife cookbook site download COOKBOOK

This creates the COOKBOOK.tar.gz from in the current directory (e.g., `~/chef-repo`). We recommend following a workflow similar to the above for your version control tool.
1 change: 1 addition & 0 deletions chef/cookbooks/apache2
Submodule apache2 added at 0de251
1 change: 1 addition & 0 deletions chef/cookbooks/apt
Submodule apt added at d9011d
1 change: 1 addition & 0 deletions chef/cookbooks/git
Submodule git added at 3adfd6
1 change: 1 addition & 0 deletions chef/cookbooks/imagemagick
Submodule imagemagick added at 0e0023
1 change: 1 addition & 0 deletions chef/cookbooks/mysql
Submodule mysql added at 4fa2e1
1 change: 1 addition & 0 deletions chef/cookbooks/openssl
Submodule openssl added at ec3952
1 change: 1 addition & 0 deletions chef/cookbooks/php
Submodule php added at 4e76d0
57 changes: 57 additions & 0 deletions chef/site-cookbooks/apache2/templates/default/default-site.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<VirtualHost *:80>
ServerAdmin <%= node['apache']['contact'] %>

DocumentRoot /vagrant/www/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /vagrant/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog <%= node['apache']['log_dir'] %>/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog <%= node['apache']['log_dir'] %>/access.log combined
ServerSignature On

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

<% if %w{ rhel fedora }.include?(node['platform_family']) -%>
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>
<% end -%>
</VirtualHost>
Loading

0 comments on commit c546e55

Please sign in to comment.