diff --git a/Vagrantfile b/Vagrantfile index 5eca053..7b0c5d1 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -70,11 +70,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # vm config config.vm.hostname = 'zf2tutorial.zf2.dev' - config.vm.box = 'opscode-ubuntu-12.04' - config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box' + #config.vm.box = 'opscode-ubuntu-12.04' + #config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box' - #config.vm.box = 'opscode-ubuntu-14.04' - #config.vm.box_url = 'http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box' + config.vm.box = 'opscode-ubuntu-14.04' + config.vm.box_url = 'http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box' config.vm.network :private_network, :ip => '33.33.33.77' diff --git a/attributes/php.rb b/attributes/php.rb index cf7be45..af7bf75 100644 --- a/attributes/php.rb +++ b/attributes/php.rb @@ -17,7 +17,13 @@ # limitations under the License. # -default['php']['set_version'] = '5.4' +default['php']['set_version'] = 'latest' + +# only if PHP 5.4 >= +force_default['php']['ext_conf_dir'] = '/etc/php5/mods-available' +default['php']['php5enmod'] = '/usr/sbin/php5enmod' + +# default php packages default['php']['packages'] = %w( curl libxml2-utils php-pear php-apc diff --git a/recipes/database.rb b/recipes/database.rb index 7bcb750..3dd8385 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -17,13 +17,17 @@ # limitations under the License. # +# need for secure_password +::Chef::Node.send(:include, Opscode::OpenSSL::Password) + + begin data_bag('databases').each do |database| - databasedata = data_bag_item('databases', database)[node.chef_environment] - - Chef::Log.debug(databasedata.inspect) - Chef::Log.debug("Cookbook #{cookbook_name} in the recipe: #{recipe_name}.") + database_bagitem = data_bag_item('databases', database) + databasedata = database_bagitem[node.chef_environment] + Chef::Log.info("Cookbook #{cookbook_name} in the recipe: #{recipe_name}.") + Chef::Log.info(databasedata.to_hash) begin database_connection = { @@ -52,6 +56,13 @@ action :drop end + # set the secure_passwords + if databasedata['password'].nil? + database_bagitem[node.chef_environment]['password'] = secure_password + database_bagitem.save unless Chef::Config[:solo] + databasedata['password'] = database_bagitem[node.chef_environment]['password'] + end + mysql_database_user databasedata['username'] do connection database_connection host '%' diff --git a/recipes/mailcatcher.rb b/recipes/mailcatcher.rb index 3615480..acb5a8f 100644 --- a/recipes/mailcatcher.rb +++ b/recipes/mailcatcher.rb @@ -20,44 +20,45 @@ # Never enable on production unless node.chef_environment == 'production' - # This is a dependency of MailCatcher - case node['platform_family'] - when 'debian' - package 'sqlite' - package 'libsqlite3-dev' - when 'rhel', 'fedora', 'suse' - package 'libsqlite3-dev' - else - # type code here - Chef::Log.warn('Unsupported platform_family: '+ node['platform_family']) - end - - # Install MailCatcher - gem_package 'mailcatcher' - - #bash 'install_mailcatcher' do - # #not_if 'which mailcatcher' - # code 'gem install mailcatcher --no-ri --no-rdoc' - #end - - # Generate the startmailcatchcommand - startmailcatchcommand = sprintf('mailcatcher --http-ip %s --http-port %s --smtp-ip %s --smtp-port %s', node['mailcatcher']['http-ip'], node['mailcatcher']['http-port'], node['mailcatcher']['smtp-ip'], node['mailcatcher']['smtp-port']) - - Chef::Log.info("start mailcatch command = #{startmailcatchcommand}") - - # Start MailCatcher - bash 'mailcatcher' do - not_if 'ps ax | grep -E "mailcatche[r]"' - code startmailcatchcommand - end - - # Publish PHP configuration - template File.join(node['php']['ext_conf_dir'], 'mailcatcher.ini') do - source 'mailcatcher.ini.erb' - owner 'root' - group 'root' - mode '0644' - action :create - end + # This is a dependency of MailCatcher + case node['platform_family'] + when 'debian' + package 'sqlite' + package 'libsqlite3-dev' + when 'rhel', 'fedora', 'suse' + package 'libsqlite3-dev' + else + # type code here + Chef::Log.warn('Unsupported platform_family: '+ node['platform_family']) + end + + # Install MailCatcher + gem_package 'mailcatcher' + + # Generate the startmailcatchcommand + startmailcatchcommand = sprintf('mailcatcher --http-ip %s --http-port %s --smtp-ip %s --smtp-port %s', node['mailcatcher']['http-ip'], node['mailcatcher']['http-port'], node['mailcatcher']['smtp-ip'], node['mailcatcher']['smtp-port']) + + Chef::Log.info("start mailcatch command = #{startmailcatchcommand}") + + # Start MailCatcher + bash 'mailcatcher' do + not_if 'ps ax | grep -E "mailcatche[r]"' + code startmailcatchcommand + end + + # Publish PHP configuration + template File.join(node['php']['ext_conf_dir'], 'mailcatcher.ini') do + source 'mailcatcher.ini.erb' + owner 'root' + group 'root' + mode '0644' + action :create + end + + + bash 'php5enmod_mailcatcher' do + code 'php5enmod mailcatcher' + only_if { ::File.exists?(node['php']['php5enmod']) } + end end diff --git a/templates/default/web_app.conf.erb b/templates/default/web_app.conf.erb index 024fd56..9260a9d 100644 --- a/templates/default/web_app.conf.erb +++ b/templates/default/web_app.conf.erb @@ -3,9 +3,8 @@ > ServerName <%= @params[:server_name] %> <% unless @params[:server_aliases].empty? -%> - ServerAlias <% @params[:server_aliases].each do |a| %><%= a %> <% end %> + ServerAlias <%= @params[:server_aliases].join " " %> <% end -%> - RewriteEngine On SetEnv APP_ENV "<%= node.chef_environment %>" @@ -13,8 +12,12 @@ > Options <%= [@params[:directory_options] || "FollowSymLinks" ].flatten.join " " %> AllowOverride <%= [@params[:allow_override] || "None" ].flatten.join " " %> + <% if node['apache']['version'] == '2.4' -%> + Require all granted + <% else -%> Order allow,deny Allow from all + <% end -%> @@ -25,31 +28,40 @@ SetHandler server-status + <% if node['apache']['version'] == '2.4' -%> + Require local + <% else -%> Order Deny,Allow Deny from all Allow from 127.0.0.1 + <% end -%> + RewriteEngine On + <%- if node['apache']['version'] == '2.4' -%> + LogLevel info rewrite:trace1 + <%- else -%> LogLevel info + RewriteLog <%= node['apache']['log_dir'] %>/<%= @application_name %>-rewrite.log + RewriteLogLevel 0 + <%- end -%> + ErrorLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-error.log CustomLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-access.log combined -<% if @params[:directory_index] -%> - DirectoryIndex <%= [@params[:directory_index]].flatten.join " " %> -<% end -%> - RewriteEngine On - RewriteLog <%= node['apache']['log_dir'] %>/<%= @application_name %>-rewrite.log - RewriteLogLevel 0 -<% if @params[:canonical_host] -%> + <% if @params[:directory_index] -%> + DirectoryIndex <%= [@params[:directory_index]].flatten.join " " %> + <% end -%> + <% if @params[:canonical_host] -%> # Canonical host, <%= @params[:server_name] %> RewriteCond %{HTTP_HOST} !^<%= @params[:server_name] %> [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*)$ http://<%= @params[:server_name] %>/$1 [L,R=301] -<% end -%> + <% end -%> RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html - RewriteRule ^.*$ /system/maintenance.html [L] + RewriteRule ^.*$ /system/maintenance.html [L,R=503]