Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cookbooks/apache2/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
:max_clients => 150,
:max_requests_per_child => 0,
}
default[:apache2][:mpm_config][:event] = {
:start_servers => 2,
:max_clients => 150,
:min_spare_threads => 25,
:max_spare_threads => 75,
:thread_limit => 64,
:thread_per_child => 25,
:max_resquests_per_child => 0
}

default[:apache2][:tuning] = {
:server_signature => 'Off',
Expand All @@ -41,4 +50,4 @@
:enabled => true,
}

default[:apache2][:modules] = ["dir", "mime", "authz_host", "alias"]
default[:apache2][:modules] = ["dir", "mime", "authz_host", "alias"]
2 changes: 1 addition & 1 deletion cookbooks/apache2/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
%x{apachectl configtest 2>&1 > /dev/null}
$?.exitstatus != 0
end
end
end
23 changes: 12 additions & 11 deletions cookbooks/apache2/templates/default/apache2.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ListenBacklog <%= @tuning[:listen_backlog] %>
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
<IfModule mpm_prefork_module.c>
StartServers <%= @mpm[:prefork][:start] %>
MinSpareServers <%= @mpm[:prefork][:min_spare] %>
MaxSpareServers <%= @mpm[:prefork][:max_spare] %>
Expand All @@ -125,7 +125,7 @@ ListenBacklog <%= @tuning[:listen_backlog] %>
# and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
<IfModule mpm_worker_module.c>
StartServers <%= @mpm[:worker][:start_servers] %>
MinSpareThreads <%= @mpm[:worker][:min_spare_threads] %>
MaxSpareThreads <%= @mpm[:worker][:max_spare_threads] %>
Expand All @@ -142,14 +142,15 @@ ListenBacklog <%= @tuning[:listen_backlog] %>
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestsPerChild 0
<IfModule mpm_event_module.c>
StartServers <%= @mpm[:event][:start_servers] %>
ServerLimit <%= @mpm[:event][:server_limit] %>
MaxClients <%= @mpm[:event][:max_clients] %>
MinSpareThreads <%= @mpm[:event][:min_spare_threads] %>
MaxSpareThreads <%= @mpm[:event][:max_spare_threads] %>
ThreadLimit <%= @mpm[:event][:thread_limit] %>
ThreadsPerChild <%= @mpm[:event][:thread_per_child] %>
MaxRequestsPerChild <%= @mpm[:event][:max_resquests_per_child] %>
</IfModule>

# These need to be set in /etc/apache2/envvars
Expand Down Expand Up @@ -249,4 +250,4 @@ LogFormat "%{User-agent}i" agent
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/
Include sites-enabled/
24 changes: 23 additions & 1 deletion cookbooks/apache2/templates/default/default_vhost.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,27 @@
</Directory>

<% end %>
<% if node.apache2.mpm == 'event' %>
<IfModule mod_fastcgi.c>
# all .php files will be pushed to a php5-fcgi handler
AddHandler php5-fcgi .php
#action module will let us run a cgi script based on handler php5-fcgi
Action php5-fcgi /php5.external
# and we add an Alias to the fcgi location
Alias /php5.external /php5.external
# now we catch this cgi script which in fact does not exists on filesystem
# we catch it on the url (Location)
<Location /php5.external>
# here we prevent direct access to this Location url,
# env=REDIRECT_STATUS will let us use this fcgi-bin url
# only after an internal redirect (by Action upper)
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</Location>
FastCgiExternalServer /php5.external -host 127.0.0.1:9000 -appConnTimeout 30 -idle-timeout 60
#FastCgiExternalServer /php5.external -socket /var/run/fpm.socket -appConnTimeout 30 -idle-timeout 60
</IfModule>
<% end %>

</VirtualHost>
</VirtualHost>
48 changes: 37 additions & 11 deletions cookbooks/php5/recipes/apache2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,44 @@

include_recipe "php5"

package "libapache2-mod-php5" do
notifies :reload, "service[apache2]"
end

apache2_enable_module "php5"

template "/etc/php5/apache2/php.ini" do
mode '0644'
cookbook "php5"
source "php5.ini.erb"
variables node.php5.php_ini
notifies :reload, "service[apache2]"
if node.apache2.mpm == "event"
# Ensure it's uninstalled. In case of switch from prefork, it's cleaner
package "libapache2-mod-php5" do
action :remove
end
package "libapache2-mod-fastcgi" do
action :install
notifies :restart, "service[apache2]"
# At install, ensure it's enabled and started
notifies :enable, "service[php5-fpm]"
notifies :start, "service[php5-fpm]"
end
apache2_enable_module "fastcgi"
apache2_enable_module "actions"
service "php5-fpm" do
action :start
end
else
package "libapache2-mod-fastcgi" do
action :remove
end
package "libapache2-mod-php5" do
action :install
notifies :restart, "service[apache2]"
notifies :disable, "service[php5-fpm]"
end
apache2_enable_module "php5"
template "/etc/php5/apache2/php.ini" do
mode '0644'
cookbook "php5"
source "php5.ini.erb"
variables node.php5.php_ini
notifies :reload, "service[apache2]"
end
service "php5-fpm" do
action :stop
end
end

apache2_enable_module "setenvif"
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/php5/recipes/apc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
owner "www-data"
mode '0755'
source "apc_clear_cache.php.erb"
end
end