Skip to content

Commit

Permalink
Added apache-fpm recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jujugrrr committed Nov 14, 2014
1 parent cf16e5e commit 640e67a
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 145 deletions.
16 changes: 16 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@

# Toggle newrelic application monitoring
default[stackname]['newrelic']['application_monitoring']['php']['enabled'] = 'false'

# apache-fpm
default['magentostack']['web']['domain'] = 'mymagento.com'
default['magentostack']['web']['http_port'] = '80'
default['magentostack']['web']['https_port'] = '443'
default['magentostack']['web']['server_aliases'] = node.fqdn
default['magentostack']['web']['ssl_autosigned'] = true
default['magentostack']['web']['cookbook'] = 'magentostack'
default['magentostack']['web']['template'] = 'apache2/magento_vhost.erb'
default['magentostack']['web']['fastcgi_cookbook'] = 'magentostack'
default['magentostack']['web']['fastcgi_template'] = 'apache2/fastcgi.conf'
default['magentostack']['web']['dir'] = "#{node['apache']['docroot_dir']}/magento"

site_name = node['magentostack']['web']['domain']
default['magentostack']['web']['ssl_key'] = "#{node['apache']['dir']}/ssl/#{site_name}.key"
default['magentostack']['web']['ssl_cert'] = "#{node['apache']['dir']}/ssl/#{site_name}.pem"
5 changes: 1 addition & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
version '0.0.1'

depends 'apache2'
depends 'application'
depends 'application_php'
depends 'apt'
depends 'build-essential'
depends 'chef-sugar'
depends 'git'
depends 'memcached'
depends 'php'
depends 'openssl'
depends 'php-fpm'
depends 'platformstack'
depends 'stack_commons'
Expand Down
104 changes: 104 additions & 0 deletions recipes/apache-fpm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Encoding: utf-8
#
# Cookbook Name:: phpstack
# Recipe:: apache
#
# Copyright 2014, Rackspace Hosting
#
# 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.
#

# repo dependencies for php-fpm
if platform_family?('rhel')
include_recipe 'yum'
include_recipe 'yum-epel'
include_recipe 'yum-ius'
elsif platform_family?('debian')
include_recipe 'apt'
end

# Modules depedencies (Magento/Php-fpm)
node.default['apache']['default_modules'] = %w(
status actions alias auth_basic
authn_file authz_default
authz_groupfile authz_host
authz_user autoindex dir env mime
negotiation setenvif ssl headers
expires log_config logio
)

%w(
apache2
apache2::mod_fastcgi
php-fpm
).each do |recipe|
include_recipe recipe
end


# create self signed certificate (enable by default)
if node['magentostack']['web']['ssl_autosigned']
openssl_x509 node['magentostack']['web']['ssl_cert'] do
common_name node.name
org 'Magento'
org_unit 'Magento'
country 'US'
key_file node['magentostack']['web']['ssl_key']
end
end

# Fast-cgi configuration
apache_conf "fastcgi" do
enable true
end

# Create documentroot
directory node['magentostack']['web']['dir'] do
action :create
not_if File.exists?(node['magentostack']['web']['dir'])
end

# Create vhost
%w(default ssl).each do |site|
web_app "#{site}" do
template node['magentostack']['web']['template']
cookbook node['magentostack']['web']['cookbook']
http_port node['magentostack']['web']['http_port']
docroot node['magentostack']['web']['dir']
server_name node['magentostack']['web']['domain']
server_aliases node['magentostack']['web']['server_aliases']
ssl true if site == 'ssl'
https_port node['magentostack']['web']['https_port']
ssl_cert node['magentostack']['web']['ssl_cert']
ssl_key node['magentostack']['web']['ssl_key']
end
end



# to add to include_recipe platformstack::monitors
#template "http-monitor-#{site_opts['server_name']}-#{port}" do
# cookbook stackname
# source 'monitoring-remote-http.yaml.erb'
# path "/etc/rackspace-monitoring-agent.conf.d/#{site_opts['server_name']}-#{port}-http-monitor.yaml"
# owner 'root'
# group 'root'
# mode '0644'
# variables(
# http_port: port,
# server_name: site_opts['server_name']
# )
# notifies 'restart', 'service[rackspace-monitoring-agent]', 'delayed'
# action 'create'
# only_if { node.deep_fetch('platformstack', 'cloud_monitoring', 'enabled') }
#end
81 changes: 0 additions & 81 deletions recipes/apache.rb

This file was deleted.

6 changes: 6 additions & 0 deletions templates/default/apache2/fastcgi.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/bin/php-cgi
FastCgiExternalServer /usr/bin/php-cgi -socket /var/run/php-fpm-www.sock -flush -idle-timeout 1800
</IfModule>
52 changes: 52 additions & 0 deletions templates/default/apache2/magento_vhost.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<%- if @params[:ssl] %>
<VirtualHost *:<%= @params[:https_port] %>>

SSLEngine on
SSLCertificateFile <%= @params[:ssl_cert] %>
SSLCertificateKeyFile <%= @params[:ssl_key] %>
<%- else %>
<VirtualHost *:<%= @params[:http_port] %>>
<%- end %>

ServerName <%= @params[:server_name] %>
<% if @params[:server_aliases] %>ServerAlias <%= @params[:server_aliases] %><% end %>
DocumentRoot <%= @params[:docroot] %>
DirectoryIndex index.php

# Enable this line if you are terminating your SSL on a load-balancer.
# SetEnvIf X-Forwarded-Proto https HTTPS=on

<Directory <%= @params[:docroot] %>/>
Options +FollowSymLinks
AllowOverride All
<%- if @params[:ssl] %>SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128<%- end %>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</IfModule>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</IfModule>
</Directory>

#Log settings
CustomLog <%= node['apache']['log_dir'] %>/<%= @params[:server_name] %>-<% if @params[:ssl] %>ssl_<% end %>access_log combined
ErrorLog <%= node['apache']['log_dir'] %>/<%= @params[:server_name] %>-<% if @params[:ssl] %>ssl_<% end %>error_log

<Location /server-status>
SetHandler server-status

<% if node['apache']['version'] == '2.2' -%>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
<% elsif node['apache']['version'] == '2.4' -%>
Require host 127.0.0.1
<% end -%>
</Location>
</VirtualHost>
60 changes: 0 additions & 60 deletions templates/default/apache2/sites/magento_vhost.erb

This file was deleted.

6 changes: 6 additions & 0 deletions templates/default/fastcgi.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/bin/php-cgi
FastCgiExternalServer /usr/bin/php-cgi -socket /var/run/php-fpm-www.sock -flush -idle-timeout 1800
</IfModule>

1 comment on commit 640e67a

@niven01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recipes/apache-fpm.rb

Cookbook name correction needed:
Cookbook Name:: phpstack should be Cookbook Name:: magentostack

Please sign in to comment.