<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
    >

<channel>
	<title>Chris Gilligan » new media &#187; Web Server Performance Tuning</title>
	<atom:link href="http://chrisgilligan.com/consulting/web-server-performance-tuning/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisgilligan.com</link>
	<description>portfolio of web work</description>
	<lastBuildDate>Mon, 13 May 2013 23:44:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Varnish VCL and Config for WordPress with W3 Total Cache</title>
		<link>http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/</link>
		<comments>http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/#comments</comments>
		<pubDate>Wed, 15 Aug 2012 00:23:11 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Content Management Systems]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[apc cache]]></category>
		<category><![CDATA[apc fcgid]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[varnish cache]]></category>
		<category><![CDATA[w3 total cache]]></category>
		<category><![CDATA[w3tc]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=867</guid>
		<description><![CDATA[<p>I have been working on a Varnish front-end for Apache, to be used with WordPress sites. I described the architecture in Load Balancing Virtualmin WordPress Hosting Server with Varnish on AWS. I now have a configuration that seems to work for all WordPress features, including logged-out commenting. This configuration also works well with W3 Total [...]</p><p>The post <a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/">Varnish VCL and Config for WordPress with W3 Total Cache</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/08/wordnish.png" width="240" />
		</p><p>I have been working on a Varnish front-end for Apache, to be used with WordPress sites. I described the architecture in <a title="Load Balancing Virtualmin WordPress Hosting Server with Varnish on AWS" href="http://chrisgilligan.com/consulting/load-balancing-virtualmin-wordpress-hosting-server-varnish-aws/">Load Balancing Virtualmin WordPress Hosting Server with Varnish on AWS</a>. I now have a configuration that seems to work for all WordPress features, including logged-out commenting. This configuration also works well with W3 Total Cache.</p>
<p>This configuration is for Varnish on a separate server, but should also work on a single server with appropriate changes to the port and backend IP settings.</p>
<h3>Varnish Config (/etc/sysconfig/varnish)</h3>
<p></p><pre class="crayon-plain-tag"># Configuration file for varnish
#
# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this
# shell script fragment.
#
#
# Maximum number of open files (for ulimit -n)
NFILES=131072
#
# Locked shared memory (for ulimit -l)
# Default log size is 82MB + header
MEMLOCK=82000
#
# Maximum size of corefile (for ulimit -c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT="unlimited"
#
# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE
RELOAD_VCL=1
#
## Advanced configuration
#
# # Main configuration file.
VARNISH_VCL_CONF=/etc/varnish/wordpress-varnish3.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80
#
# # Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
#
# # Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location if using file cache
#VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
#
# # Cache size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=3G
#
# # Backend storage specification
# malloc runs from RAM, file from file
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
#VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options,
# # be sure you update this section, too.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
-u varnish -g varnish \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
#</pre><p></p>
<h3>Varnish VCL (/etc/varnish/wordpress-varnish3.vcl)</h3>
<p></p><pre class="crayon-plain-tag">backend origin {
.host = "10.11.12.13";
.port = "80";
.connect_timeout = 60s;
.first_byte_timeout = 60s;
.between_bytes_timeout = 60s;
}
#
sub vcl_recv {
# only using one backend
set req.backend = origin;
#
# set standard proxied ip header for getting original remote address
set req.http.X-Forwarded-For = client.ip;
#
# logged in users must always pass
if( req.url ~ "^/wp-(login|admin)" || req.http.Cookie ~ "wordpress_logged_in_" ){
return (pass);
}
# accept purges from w3tc and varnish http purge
if (req.request == "PURGE") {
return (lookup);
}
#
# don't cache search results
if( req.url ~ "\?s=" ){
return (pass);
}
#
# always pass through posted requests and those with basic auth
if ( req.request == "POST" || req.http.Authorization ) {
return (pass);
}
#
# else ok to fetch a cached page
unset req.http.Cookie;
return (lookup);
}
#
# accept purges from w3tc and varnish http purge
sub vcl_hit {
if (req.request == "PURGE") { purge; }
return (deliver);
}
#
# accept purges from w3tc and varnish http purge
sub vcl_miss {
if (req.request == "PURGE") { purge; }
return (fetch);
}
#
sub vcl_fetch {
#
# remove some headers we never want to see
unset beresp.http.Server;
unset beresp.http.X-Powered-By;
#
# only allow cookies to be set if we're in admin area - i.e. commenters stay logged out
if( beresp.http.Set-Cookie &amp;&amp; req.url !~ "^/wp-(login|admin)" ){
unset beresp.http.Set-Cookie;
}
#
# don't cache response to posted requests or those with basic auth
if ( req.request == "POST" || req.http.Authorization ) {
return (hit_for_pass);
}
#
# only cache status ok
if ( beresp.status != 200 ) {
return (hit_for_pass);
}
#
# don't cache search results
if( req.url ~ "\?s=" ){
return (hit_for_pass);
}
#
# else ok to cache the response
set beresp.ttl = 24h;
return (deliver);
}
#
sub vcl_deliver {
# add debugging headers, so we can see what's cached
if (obj.hits &gt; 0) {
set resp.http.X-Cache = "HIT";
}
else {
set resp.http.X-Cache = "MISS";
}
# remove some headers added by varnish
unset resp.http.Via;
unset resp.http.X-Varnish;
}
#
sub vcl_hash {
hash_data( req.url );
# altering hash so subdomains are ignored.
# don't do this if you actually run different sites on different subdomains
if ( req.http.host ) {
hash_data( regsub( req.http.host, "^([^\.]+\.)+([a-z]+)$", "\1\2" ) );
} else {
hash_data( server.ip );
}
# ensure separate cache for mobile clients (WPTouch workaround)
if( req.http.User-Agent ~ "(iPod|iPhone|incognito|webmate|dream|CUPCAKE|WebOS|blackberry9\d\d\d)" ){
hash_data("touch");
}
return (hash);
}</pre><p></p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="w3 total cache varnish">w3 total cache varnish</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish wordpress vcl">varnish wordpress vcl</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish wordpress">varnish wordpress</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish backend subdomain">varnish backend subdomain</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="wordpress varnish vcl">wordpress varnish vcl</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish video cache server configuration">varnish video cache server configuration</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish 3 0 wordpress vcl">varnish 3 0 wordpress vcl</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="w3tc varnish">w3tc varnish</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="varnish wordpress multisite">varnish wordpress multisite</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/" title="w3 total cache varnish cache">w3 total cache varnish cache</a></li></ul><p>The post <a href="http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/">Varnish VCL and Config for WordPress with W3 Total Cache</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/consulting/varnish-vcl-and-config-for-wordpress-with-w3-total-cache/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/08/wordnish.png" type="image/png" medium="image" width="217" height="300">
                <media:description type="plain"><![CDATA[wordnish]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/08/wordnish.png" />
				            </media:content>
            	</item>
		<item>
		<title>Punk Rock Music Community</title>
		<link>http://chrisgilligan.com/portfolio/punk-rock-music-community/</link>
		<comments>http://chrisgilligan.com/portfolio/punk-rock-music-community/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 14:20:41 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Publishing]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=771</guid>
		<description><![CDATA[<p>Punktastic.com is a community powered site that covers punk music in Britain, but is poised to go worldwide. They cover punk and hardcore shows and festivals, and provide album reviews, video interviews and more. With a growing audience and user base, Punktastic needed a more reliable and robust web server, so they made the move [...]</p><p>The post <a href="http://chrisgilligan.com/portfolio/punk-rock-music-community/">Punk Rock Music Community</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/04/Screen-Shot-2012-04-10-at-10.03.58-AM.png" width="240" />
		</p><p><strong><a title="Punktastic.com" href="http://punktastic.com/">Punktastic.com</a> is a community powered site that covers punk music in Britain, but is poised to go worldwide.</strong> They cover punk and hardcore shows and festivals, and provide album reviews, video interviews and more.</p>
<p>With a growing audience and user base, Punktastic needed a more reliable and robust web server, so they made the move to a dedicated CentOS 5 series web server with 3GB RAM. While this is a relatively low-end box, it has plenty of horsepower for a single WordPress site and phpBB3 forum.</p>
<div id="attachment_772" class="wp-caption aligncenter" style="width: 257px"><a href="http://punktastic.com/"><img class="size-medium wp-image-772" title="Punktastic.com" src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/04/Screen-Shot-2012-04-10-at-10.03.58-AM-247x300.png" alt="" width="247" height="300" /></a><p class="wp-caption-text">Punktastic.com web site</p></div>
<h3>For this GIG, I soloed on&#8230;</h3>
<ul>
<li>transferring the site from a WAMP development server to the live LAMP server</li>
<li>configuring an active firewall to block the baddies</li>
<li>installing monitoring and administration tools</li>
<li>tuning Apache and MySQL for high traffic</li>
<li>integrating APC PHP Cache to speed up web pages and provide better concurrency</li>
</ul>
<p><strong>Loud Fast Rules.</strong></p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/portfolio/punk-rock-music-community/" title="resume template forum power by expressionengine">resume template forum power by expressionengine</a></li></ul><p>The post <a href="http://chrisgilligan.com/portfolio/punk-rock-music-community/">Punk Rock Music Community</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/portfolio/punk-rock-music-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/04/Screen-Shot-2012-04-10-at-10.03.58-AM-247x300.png" type="image/png" medium="image" width="247" height="300">
                <media:description type="plain"><![CDATA[Punktastic.com]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/04/Screen-Shot-2012-04-10-at-10.03.58-AM-247x300.png" />
				            </media:content>
            	</item>
		<item>
		<title>WordPress with W3 Total Cache on Nginx with APC (Virtualmin)</title>
		<link>http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/</link>
		<comments>http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 15:25:34 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[virtualmin]]></category>
		<category><![CDATA[w3 total cache]]></category>
		<category><![CDATA[w3tc]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=672</guid>
		<description><![CDATA[<p>Virtualmin now includes support for Nginx web server. I deploy many WordPress sites with W3 Total Cache and APC Alternative PHP Cache, so I was very interested to see how Nginx performance compares to Apache for WordPress, and whether APC and W3TC would play nice with Nginx. I prefer to install WordPress in public_html/wordpress for [...]</p><p>The post <a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/">WordPress with W3 Total Cache on Nginx with APC (Virtualmin)</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc.png" width="240" />
		</p><p><strong><a href="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc.png"><img class="alignright size-medium wp-image-673" title="virtualmin-nginx-wordpress-permalinks-apc" alt="" src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc-300x187.png" width="300" height="187" /></a>Virtualmin now includes <a title="Virtualmin Nginx" href="http://www.virtualmin.com/documentation/web/nginx">support for Nginx web server</a>.</strong> I deploy many WordPress sites with W3 Total Cache and APC Alternative PHP Cache, so I was very interested to see how Nginx performance compares to Apache for WordPress, and whether APC and W3TC would play nice with Nginx.</p>
<p>I prefer to install WordPress in public_html/wordpress for ease of development, compatibility with other scripts, etc. Accordingly, the suggested configuration is for WordPress installed in a subfolder. This info also assumes you have successfully installed APC Cache on your server, and set up a <em>clean</em> install of Virtualmin with Nginx as the Alternative Web Server. Switching from Apache to Nginx later is difficult, as is transferring apache virtual server backups. Best to start fresh and build from scratch.</p>
<h3>Testing the Virtualmin Nginx Modules</h3>
<p>Virtualmin does not support Nginx and Apache together, and there is no easy migration from Apache to Nginx, so it is suggested to begin with a fresh install of Virtualmin with no existing accounts.</p>
<p>If you would like to experiment with Nginx, and you already have a Virtualmin Pro license, you are permitted to set up Virtualmin on a second server for testing and migration. I run the extra Virtualmin Pro system on a VPS that I use for backups, slave DNS, and testing.</p>
<p>The Nginx modules are <a title="Virtualmin Nginx on GPL?" href="http://www.virtualmin.com/node/20602">also available for the free Virtualmin GPL version</a>. To install the modules, go to Virtualmin Package Updates (wbm-virtualmin-nginx and wbm-virtualmin-nginx-ssl).</p>
<h3>WordPress Plugins for this Setup</h3>
<ul>
<li><a title="Wordpress opcode cache, page cache, caching, database cache, browser cache" href="http://wordpress.org/extend/plugins/w3-total-cache/">W3 Total Cache</a> &#8212; adds opcode cache, minification, browser cache and page cache capabilities to WordPress&#8230; and it works with Nginx. Works best with Alternative PHP Cache to provide opcode and database cache. Setting APC for all caches works easiest with Nginx&#8230; setting to file caching introduces URL rewrite errors&#8230; See <a title="W3 Total Cache Settings" href="#w3tc-settings">W3TC Settings</a> information below for instructions on how to implement File caching.</li>
<li><a title="Wordpress Nginx Plugin" href="http://wordpress.org/extend/plugins/nginx-compatibility/">nginx Compatibility</a> &#8212; makes WordPress more compatible with Nginx, allows use of permalinks without /index.php/</li>
</ul>
<h3>Configuring Nginx for WordPress pretty URL Permalinks</h3>
<p>The nginx Compatibility plugin has support for pretty URLs, but you must configure Nginx to use them. You should add or edit the following URL path locations to nginx.conf for your virtual domain&#8230; either by direct edit, or via URL Path Locations in Virtualmin &gt; Services &gt; Configure Nginx Website (<em><a title="Virtualmin Nginx WordPress URL Path Locations" href="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc.png">see attached image&#8230;</a></em>). This config is for WP installed in /public_html/wordpress, so you will need to omit or change /wordpress if WP is installed in a different directory.</p><pre class="crayon-plain-tag">location ^~ /files/ {
rewrite /files/(.+) /wordpress/wp-includes/ms-files.php?file=$1 last;
}
location @wordpress {
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_NAME /index.php;
}
location ~ \.php$ {
try_files $uri @wordpress;
fastcgi_index index.php;
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ^~ /blogs.dir/ {
internal;
root /home/username/public_html/wordpress/wp-content;
}</pre><p></p>
<h3>Adding APC Support for a Virtual Domain</h3>
<p>Because Virtualmin&#8217;s implementation of Nginx uses php-fastcgi, each virtual domain will load its own php.ini file, so you can add the APC directives to that file (/home/domainname/etc/php5/php.ini)</p>
<p>Add the following to php.ini (adjust to your requirements)</p><pre class="crayon-plain-tag">[APC]
extension = apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 12M
apc.optimization = 0
apc.num_files_hint = 256
apc.user_entries_hint = 1024
apc.ttl = 0
apc.user_ttl = 0
apc.gc_ttl = 600
apc.cache_by_default = 0
apc.filters = "-/home/username/public_html/scripts-not-to-cache/.*,-/home/username/public_html/apc/.*"
apc.slam_defense = 0
apc.use_request_time = 1
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.file_update_protection = 2
apc.enable_cli = 0
apc.max_file_size = 2M
apc.stat = 1
apc.write_lock = 1
apc.report_autofilter = 0
apc.include_once_override = 0
apc.rfc1867 = 0
apc.rfc1867_prefix = "upload_"
apc.rfc1867_name = "APC_UPLOAD_PROGRESS"
apc.rfc1867_freq = 0
apc.localcache = 1
apc.localcache.size = 256
apc.coredump_unmap = 0
apc.stat_ctime = 0</pre><p></p>
<h3>Reloading PHP-fastcgi processes after changes to php.ini</h3>
<p>You will need to reload the php-fastcgi processes if you change php.ini. Luckily, Virtualmin creates service scripts for each virtual domain, which you can use to reload PHP.</p>
<p>The service scripts are located in /etc/rc.d/init.d.<br />
<code>php-fcgi-domain1-com<br />
php-fcgi-domain2-com</code><br />
Script allows stop, start, restart<br />
e.g.<br />
<code>service php-fcgi-domain2-com restart</code></p>
<p><em><strong>The service may also be restarted via Webmin &gt; Services &gt; Bootup and Shutdown</strong></em></p>
<h3>Memory Considerations</h3>
<p>PHP FCGId will launch the number of sub-processes you specify in Virtualmin &gt; Server Configuration &gt; Website Options, so beware of the memory overhead if you specify a large number, because each will consume the amount of memory specified in  apc.shm_size. You may need to experiment with this value, depending on your server&#8217;s memory and potential traffic.</p>
<p>Virtualmin explains: &#8220;When PHP scripts for this domain as run via FCGId, the number of PHP processes set in this field will be kept running at all times to serve requests. You can increase this from the default of 4 to improve PHP script latency, or decrease it to reduce memory use. Setting it to None will cause PHP processes to be launched only as needed on demand, and to be cleaned up after some period of inactivity.&#8221;</p>
<p>Nginx support on Virtualmin is working well, and it is reported that the lead developer, Jamie Cameron, is working on a php-fpm implementation, which should increase performance and lessen memory requirements. Let&#8217;s hope this rumor is true!</p>
<h3><a title="W3 Total Cache Settings" name="w3tc-settings"></a>W3 Total Cache Settings</h3>
<p>Provided you use the nginx.conf settings described above, using APC cache for all W3TC categories of cache/minify/etc. will work with no additional changes to the conf file. However, if you wish to choose Disk cache for page and/or minify cache, URL rewriting will not work properly on Virtualmin. You must include the location {&#8230;} directives in the nginx.conf created in your public_html root by W3TC, and add them after the location {&#8230;} directives described above.</p>
<p>You can do this either by copying the directives and pasting into /etc/nginx/nginx.conf, or (better) by using an include statement:</p><pre class="crayon-plain-tag">[...]
location ^~ /blogs.dir/ {
internal;
root /home/username/public_html/wordpress/wp-content;
}
include /home/username/public_html/nginx.conf;
[...]</pre><p><em><strong>However, remember you will need to restart NginX web server after making changes to the W3TC configuration, because these will over-write the local nginx.conf file.</strong></em></p>
<h3>Conclusion</h3>
<p>Sorry, no benchmarks. See my <a title="Wordpress on Nginx with APC cache (Virtualmin)" href="http://nginx.chrisgilligan.com/" target="_blank">example/test site here</a>.</p>
<p>Nginx support on Virtualmin is working well, though I don&#8217;t see much improvement over Apache in terms of initial index page load, or time to first byte on the WordPress test site I created.  Cached and subsequent pages load very quickly, so it looks like there is an overall improvement. All WordPress functions seem to work well: comments, image uploads, etc. are no problem. I am interested to see if there is improvement with other scripts, especially phpbb3.</p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="virtualmin wordpress install script">virtualmin wordpress install script</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="install memcached from virtualmin">install memcached from virtualmin</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="w3 total cache nginx">w3 total cache nginx</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="virtualmin mySQL cache">virtualmin mySQL cache</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="index of metart">index of metart</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="met art models index">met art models index</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="it appears page cache url rewriting is not working">it appears page cache url rewriting is not working</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="virtualmin nginx">virtualmin nginx</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="it appears minify url rewriting is not working if using apache verify that the server configuration allows htaccess or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx)">it appears minify url rewriting is not working if using apache verify that the server configuration allows htaccess or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx)</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/" title="virtualmin nginx wordpress">virtualmin nginx wordpress</a></li></ul><p>The post <a href="http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/">WordPress with W3 Total Cache on Nginx with APC (Virtualmin)</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/wordpress/wordpress-with-w3-total-cache-on-nginx-with-apc-virtualmin/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc-300x187.png" type="image/png" medium="image" width="300" height="187">
                <media:description type="plain"><![CDATA[virtualmin-nginx-wordpress-permalinks-apc]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2012/03/virtualmin-nginx-wordpress-permalinks-apc-300x187.png" />
				            </media:content>
            	</item>
		<item>
		<title>Apache and MySql Performance Tuning for High Traffic WordPress Website on Cpanel</title>
		<link>http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/</link>
		<comments>http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 14:27:52 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache web server]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[blacklisting]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[denial of service]]></category>
		<category><![CDATA[denial of service attacks]]></category>
		<category><![CDATA[inspection firewall]]></category>
		<category><![CDATA[internet climate]]></category>
		<category><![CDATA[load balancing]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[page impressions]]></category>
		<category><![CDATA[performance testing]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Search Engine Optimization]]></category>
		<category><![CDATA[security probes]]></category>
		<category><![CDATA[soccer news]]></category>
		<category><![CDATA[Syndication]]></category>
		<category><![CDATA[traffic load]]></category>
		<category><![CDATA[traffic security]]></category>
		<category><![CDATA[traffic surges]]></category>
		<category><![CDATA[web hosting servers]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=523</guid>
		<description><![CDATA[<p>SoccerNews.com is a high traffic WordPress site with over 600,000 unique visitors and over 2,000,000 page impressions per month. It is a content republisher and aggregator, presenting custom XML feeds for (what else?) soccer news from all over the world. The site has a very active user base, providing content in the forms of editorials and [...]</p><p>The post <a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/">Apache and MySql Performance Tuning for High Traffic WordPress Website on Cpanel</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/Screen-Shot-2011-08-26-at-9.01.12-AM.png" width="240" />
		</p><p><strong><a title="Soccer News" href="http://soccernews.com/">SoccerNews.com</a> is a high traffic WordPress site with over 600,000 unique visitors and over 2,000,000 page impressions per month.</strong> It is a content republisher and aggregator, presenting custom XML feeds for (what else?) soccer news from all over the world. The site has a very active user base, providing content in the forms of editorials and comments on news items. Advertising and sponsored referrals provide the revenue stream.</p>
<div id="attachment_524" class="wp-caption aligncenter" style="width: 269px"><a href="http://soccernews.com/"><img class="size-medium wp-image-524 " title="SoccerNews.com website" src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/Screen-Shot-2011-08-26-at-9.01.12-AM-259x300.png" alt="SoccerNews.com website" width="259" height="300" /></a><p class="wp-caption-text">SoccerNews.com website</p></div>
<p><strong>I was contacted by the publisher</strong> after responding to a plea for assistance in a WordPress.org support forum. Though the site was running on a dedicated server with 8GB RAM, it was crashing frequently under load. The developer tried implementing APC Alternative PHP Cache and W3 Total Cache, but these measures turned out to be incompatible with some of the custom PHP code and the software architecture of the Cpanel server. Haphazardly implementing randomly suggested &#8220;solutions&#8221; had actually made the problems worse, resulting in an &#8220;own goal&#8221; that brought down the server.</p>
<p><strong>I did an assessment of the software, hardware and traffic load</strong> and found that there were many improvements to be made. Among the changes:</p>
<ul>
<li><strong>Implemented a <a href="http://configserver.com/cp/csf.html">Stateful Packet Inspection firewall and Login Failure Daemon</a></strong>to block malicious IP addresses, malware servers, bad bots, content scrapers, etc. Many of the problems leading to site crashes were due to constant bad bot traffic, security probes and Denial of Service attacks. Connection Tracking in the firewall now limits the amount of resources a single legitimate IP address can monopolize, in addition to blacklisting attackers.
<ul>
<li>This is the first step to proper web server performance in today&#8217;s Internet climate. Popular sites that do not have a solid security and load balancing strategy are subject to crippling traffic from the Internet&#8217;s millions of malicious and compromised servers and personal computers.</li>
</ul>
</li>
<li><strong><a title="Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment" href="http://chrisgilligan.com/wordpress/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Reconfigured Apache web server, PHP and MySQL</a></strong> to better utilize the server&#8217;s horsepower. Cpanel&#8217;s efault Apache and MySQL configurations were limiting the number of concurrent user sessions the server could handle. Changed PHP to run as FastCGI (fcgid) and recompiled Apache to better handle the needs of a high traffic WordPress site. Configured a large MySQL table and query cache based on performance and load testing.</li>
<li><strong>Configured Amazon CloudFront Content Distribution Network</strong>, page cache, browser cache, and object cache with the WordPress plugin, <a title="W3 Edge -- W3 Total Cache" href="http://www.w3-edge.com/wordpress-plugins/w3-total-cache/">W3 Total Cache</a>. Due to the sheer number of ad scripts being served per page, there were inevitable JavaScript and PHP conflicts, but W3TC is very flexible and was able to handle the task.</li>
<li><strong>Suggested a scheduled, offsite backup strategy</strong> that would utilize existing resources, and eliminate the need for a 3rd-party backup solution that was causing more load issues and costing $45.00 per month.</li>
</ul>
<div><strong>Now the site is stable and fast</strong>, and is ready for very high traffic. With World Cup Brazil coming up in 2014, the site will definitely see a huge amount of users. Future plans include changing the architecture of the server to simplify the background processes and implement APC Alternative PHP Cache, or a caching web server front end.</div>
<h3>Results? I&#8217;ll let the publisher speak to that!</h3>
<blockquote><p><strong>The site has been as good as &#8220;flawless&#8221; since, with no downtime, and we couldn&#8217;t be happier. Everything is running smoothly and it&#8217;s a great relief knowing that we made the site faster, safer and more reliable. The site feels a lot more stable and faster. So you&#8217;ve done a great job. </strong></p>
<p>&#8211; Kim Vincenzius, <a title="StarScape, LLC" href="http://www.starscape.com/">StarScape LLC</a></p></blockquote>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="fcgidmaxrequestsperprocess">fcgidmaxrequestsperprocess</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="timthumb alternative">timthumb alternative</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="Tuning Apache for High Traffic">Tuning Apache for High Traffic</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="optimizing mysql for high traffic">optimizing mysql for high traffic</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="tune mysql for high traffic site">tune mysql for high traffic site</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="apache config for high traffic">apache config for high traffic</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="mysql settings for large wordpress website">mysql settings for large wordpress website</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="mysql huge traffic to apache">mysql huge traffic to apache</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="optimization high traffic php">optimization high traffic php</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/" title="optimize apache for high traffic">optimize apache for high traffic</a></li></ul><p>The post <a href="http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/">Apache and MySql Performance Tuning for High Traffic WordPress Website on Cpanel</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/consulting/web-server-performance-tuning/apache-and-mysql-performance-tuning-for-high-traffic-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/Screen-Shot-2011-08-26-at-9.01.12-AM-259x300.png" type="image/png" medium="image" width="259" height="300">
                <media:description type="plain"><![CDATA[SoccerNews.com website]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/Screen-Shot-2011-08-26-at-9.01.12-AM-259x300.png" />
				            </media:content>
            	</item>
		<item>
		<title>Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</title>
		<link>http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/</link>
		<comments>http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 15:13:20 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[buffer length]]></category>
		<category><![CDATA[buffer pool]]></category>
		<category><![CDATA[buffer size]]></category>
		<category><![CDATA[cache size]]></category>
		<category><![CDATA[configured server]]></category>
		<category><![CDATA[email servers]]></category>
		<category><![CDATA[force probes]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[lfd]]></category>
		<category><![CDATA[max connections]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[php scripts]]></category>
		<category><![CDATA[pool size]]></category>
		<category><![CDATA[software accounts]]></category>
		<category><![CDATA[stateful packet inspection]]></category>
		<category><![CDATA[static html files]]></category>
		<category><![CDATA[virtual hosts]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=508</guid>
		<description><![CDATA[<p>Web hosting has changed dramatically in the last few years. The majority of accounts are now running PHP scripts and MySQL, whereas in the past most accounts were only serving static HTML files. This presents challenges in security as well as performance tuning. It is impossible to predict whether a certain configuration will work properly [...]</p><p>The post <a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php.jpg" width="240" />
		</p><p><strong><img class="alignright size-thumbnail wp-image-515" title="LAMP-linux-apache-mysql-php" src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php-e1314060599892-150x81.jpg" alt="" width="150" height="81" />Web hosting has changed dramatically in the last few years.</strong> The majority of accounts are now running PHP scripts and MySQL, whereas in the past most accounts were only serving static HTML files. This presents challenges in security as well as performance tuning.</p>
<p>It is impossible to predict whether a certain configuration will work properly for a given server, unless the hardware, software, accounts, network and traffic are identical to a previously configured server… therefore it is impossible to give a configuration which will cover all applications.</p>
<h3>Firewall Unnecessary Traffic from Affecting the Server</h3>
<p>Before you begin performance tuning, please consider using a stateful packet inspection (SPI) firewall &amp; login failure daemon (LFD) for your server: <a title="ConfigServer free firewall for web servers" href="http://configserver.com/cp/csf.html">ConfigServer Firewall is an excellent free firewall</a> &amp; lfd. This will help prevent brute force probes, port flooding, DDOS, etc. If you have 600 virtual hosts running on a server, it is very likely that the server is experiencing constant malicious exploits, especially if you are also running email servers on the same IP addresses.</p>
<h3>Tune Apache the Sane Way (Requires Basic Math Skills)</h3>
<p>If you wish to tune your Apache MPM settings, you should consider following this method:<br />
<a href="https://telvps.com/clients/knowledgebase/25/HOW-TO-Optimize-Apache-for-Low-Memory-Usage.html">https://telvps.com/clients/knowledgebase/25/HOW-TO-Optimize-Apache-for-Low-Memory-Usage.html</a><br />
(the formula works well for any level of traffic and memory).</p>
<h3>MySQL Tuning Is More Difficult: Trial and Error</h3>
<p>To test your MySQL server performance, you may try:</p>
<ul>
<li><strong>mysqltuner:</strong> <a title="MySQL performance tuning script" href="https://github.com/rackerhacker/MySQLTuner-perl">https://github.com/rackerhacker/MySQLTuner-perl</a> (or http://mysqltuner.pl for the script only)</li>
<li><strong>MySQL Tuning Primer:</strong> <a title="MySQL Tuning Primer script" href="https://launchpad.net/mysql-tuning-primer">https://launchpad.net/mysql-tuning-primer</a></li>
<li><strong><a title="Secure phpMyAdmin with SSL on CentOS, Amazon Linux, RedHat" href="http://chrisgilligan.com/consulting/amazon-web-services/secure-phpmyadmin-with-ssl-on-centos-amazon-linux-redhat/">phpMyAdmin 3.5</a>+:</strong> Status Monitor and Advisor are excellent tools, but require <a title="Secure phpMyAdmin with SSL on CentOS, Amazon Linux, RedHat" href="http://chrisgilligan.com/consulting/amazon-web-services/secure-phpmyadmin-with-ssl-on-centos-amazon-linux-redhat/">proper phpMyAdmin setup</a></li>
</ul>
<p>These scripts will analyze MySQL performance and make suggestions regarding your my.cnf configuration. mysqltuner is now deprecated, but it still widely used and is very simple. Tuning Primer is the most up-to-date, and provides more complete recommendations.</p>
<p><strong>If you are running MySQL 5 or later, the configuration statements can be in the following form (example from one of my servers):</strong></p>
<p><code>[mysqld]<br />
datadir=/var/lib/mysql<br />
socket=/var/lib/mysql/mysql.sock<br />
user=mysql</code></p>
<p><code>symbolic-links=0<br />
innodb_file_per_table = 1<br />
thread_concurrency = 8<br />
query_cache_size = 64M<br />
query_cache_limit = 4M<br />
thread_cache_size = 8<br />
myisam_sort_buffer_size = 64M<br />
read_rnd_buffer_size = 8M<br />
read_buffer_size = 2M<br />
sort_buffer_size = 2M<br />
table_cache = 1600<br />
table_definition_cache = 1600<br />
max_allowed_packet = 4M<br />
key_buffer = 1G<br />
interactive_timeout = 2<br />
wait_timeout = 5<br />
long_query_time = 1<br />
log_slow_queries = ON<br />
open_files_limit = 3200<br />
innodb_buffer_pool_size = 26M<br />
join_buffer_size = 4M<br />
tmp_table_size = 72M<br />
max_heap_table_size = 72M<br />
max_connections = 80</code></p>
<p><code>[mysqld_safe]<br />
log-error=/var/log/mysqld.log<br />
pid-file=/var/run/mysqld/mysqld.pid</code></p>
<p>This is for example only! table_cache should be set a little higher than the total number of tables (sum of MYISAM,INNODB,MEMORY etc.), as reported by mysqltuner. If you anticipate adding more virtual hosts, or clients adding more databases or tables, you will need to raise table_cache value.</p>
<p>Follow the recommendations from the Apache tuning, and then follow the recommendations of the tuning scripts. The apache tuning will give you the number of maxclients, and from this you will know the appropriate beginning value for [mysqld] max_connections. Begin with max_connections set slightly higher than Apache&#8217;s maxclients. If you are running database caching via APC, you may lower max_connections, because APC will serve the busiest queries directly from cache.</p>
<h3>Take Time to Get a Realistic Assessment of MySQL Performance</h3>
<p>If you have a PHP opcode and database caching strategy (such as APC) implemented on your web server and for your PHP script packages, you will be able to lower maxconnections, based on the information you receive from mysqltuner after 24-48 hours of steady traffic. For example, I have a server with Apache set to 256 maxclients, but the MySQL maxconnections set to 200, because many web requests do not require direct interaction with the MySQL server.</p>
<p>Take a look at &#8220;Highest usage of available connections&#8221;, and lower maxconnections accordingly. It is safe to lower maxconnections to a number slightly above the reported highest usage. Doing so will allow you to set higher values for the individual cache settings which affect the thread cache size, because the total thread buffer memory size is multiplied by maxconnections. Feedback is available in the reports for &#8220;Total buffers&#8221; and &#8220;Highest usage of available connections&#8221;.</p>
<p>After you have the proper settings for maxclients and maxconnections, restart httpd and mysqld. Wait 1 hour, and run mysqltuner to see if there are any recommended changes. Mysqltuner will show you the maximum memory which will be used by mysql. You should adjust config variables to take up no more than 60% of total RAM. Wait 24-48 hours and run mysqltuner again.</p>
<h4>Example mysqltuner results:</h4>
<p><code>------- Performance Metrics -------------------------------------------------<br />
[--] Up for: 13d 2h 34m 16s (1M q [1.561 qps], 67K conn, TX: 81B, RX: 449M)<br />
[--] Reads / Writes: 91% / 9%<br />
[--] Total buffers: 298.0M global + 6.4M per thread (151 max threads)<br />
[OK] Maximum possible memory usage: 1.2G (61% of installed RAM)<br />
[OK] Slow queries: 0% (0/1M)<br />
[OK] Highest usage of available connections: 6% (10/151)<br />
[OK] Key buffer size / total MyISAM indexes: 256.0M/9.7M<br />
[OK] Key buffer hit rate: 99.6% (3M cached / 13K reads)<br />
[OK] Query cache efficiency: 75.2% (1M cached / 1M selects)<br />
[!!] Query cache prunes per day: 1360<br />
[OK] Sorts requiring temporary tables: 0% (4 temp sorts / 13K sorts)<br />
[!!] Temporary tables created on disk: 38% (6K on disk / 16K total)<br />
[OK] Thread cache hit rate: 99% (13 created / 67K connections)<br />
[OK] Table cache hit rate: 51% (115 open / 223 opened)<br />
[OK] Open file limit used: 20% (212/1K)<br />
[OK] Table locks acquired immediately: 99% (408K immediate / 409K locks)</code><br />
<code>-------- Recommendations -----------------------------------------------------<br />
General recommendations:<br />
Add skip-innodb to MySQL configuration to disable InnoDB<br />
Run OPTIMIZE TABLE to defragment tables for better performance<br />
Enable the slow query log to troubleshoot bad queries<br />
When making adjustments, make tmp_table_size/max_heap_table_size equal<br />
Reduce your SELECT DISTINCT queries without LIMIT clauses<br />
Variables to adjust:<br />
query_cache_size (&gt; 16M)<br />
tmp_table_size (&gt; 16M)<br />
max_heap_table_size (&gt; 16M)</code></p>
<p>I suggest you NOT enable the slow query log unless the Slow Queries result is very high. Slow Queries result % will be somewhat high if MySQL has run for less than 24 hours.</p>
<h4>Example MySQL Tuning Primer results:</h4>
<p><code>SLOW QUERIES<br />
The slow query log is NOT enabled.<br />
Current long_query_time = 10.000000 sec.<br />
You have 0 out of 1768137 that take longer than 10.000000 sec. to complete<br />
Your long_query_time seems to be fine<br />
</code></p>
<p><code>BINARY UPDATE LOG<br />
The binary update log is NOT enabled.<br />
You will not be able to do point in time recovery<br />
See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html<br />
</code></p>
<p><code>WORKER THREADS<br />
Current thread_cache_size = 8<br />
Current threads_cached = 7<br />
Current threads_per_sec = 0<br />
Historic threads_per_sec = 0<br />
Your thread_cache_size is fine<br />
</code></p>
<p><code>MAX CONNECTIONS<br />
Current max_connections = 151<br />
Current threads_connected = 1<br />
Historic max_used_connections = 10<br />
The number of used connections is 6% of the configured maximum.<br />
You are using less than 10% of your configured max_connections.<br />
Lowering max_connections could help to avoid an over-allocation of memory<br />
See "MEMORY USAGE" section to make sure you are not over-allocating<br />
</code></p>
<p><code>INNODB STATUS<br />
Current InnoDB index space = 0 bytes<br />
Current InnoDB data space = 0 bytes<br />
Current InnoDB buffer pool free = 96 %<br />
Current innodb_buffer_pool_size = 8 M<br />
Depending on how much space your innodb indexes take up it may be safe<br />
to increase this value to up to 2 / 3 of total system memory<br />
</code></p>
<p><code>MEMORY USAGE<br />
Max Memory Ever Allocated : 345 M<br />
Configured Max Per-thread Buffers : 962 M<br />
Configured Max Global Buffers : 282 M<br />
Configured Max Memory Limit : 1.21 G<br />
Physical Memory : 2.00 G<br />
Max memory limit seem to be within acceptable norms<br />
</code></p>
<p><code>KEY BUFFER<br />
Current MyISAM index space = 9 M<br />
Current key_buffer_size = 256 M<br />
Key cache miss rate is 1 : 247<br />
Key buffer free ratio = 80 %<br />
Your key_buffer_size seems to be fine<br />
</code></p>
<p><code>QUERY CACHE<br />
Query cache is enabled<br />
Current query_cache_size = 16 M<br />
Current query_cache_used = 12 M<br />
Current query_cache_limit = 1 M<br />
Current Query cache Memory fill ratio = 77.74 %<br />
Current query_cache_min_res_unit = 4 K<br />
MySQL won't cache query results that are larger than query_cache_limit in size<br />
</code></p>
<p><code>SORT OPERATIONS<br />
Current sort_buffer_size = 1 M<br />
Current read_rnd_buffer_size = 4 M<br />
Sort buffer seems to be fine<br />
</code></p>
<p><code>JOINS<br />
Current join_buffer_size = 132.00 K<br />
You have had 0 queries where a join could not use an index properly<br />
Your joins seem to be using indexes properly<br />
</code></p>
<p><code>OPEN FILES LIMIT<br />
Current open_files_limit = 1024 files<br />
The open_files_limit should typically be set to at least 2x-3x<br />
that of table_cache if you have heavy MyISAM usage.<br />
Your open_files_limit value seems to be fine<br />
</code></p>
<p><code>TABLE CACHE<br />
Current table_open_cache = 256 tables<br />
Current table_definition_cache = 256 tables<br />
You have a total of 97 tables<br />
You have 115 open tables.<br />
The table_cache value seems to be fine<br />
</code></p>
<p><code>TEMP TABLES<br />
Current max_heap_table_size = 16 M<br />
Current tmp_table_size = 16 M<br />
Of 10325 temp tables, 37% were created on disk<br />
Perhaps you should increase your tmp_table_size and/or max_heap_table_size<br />
to reduce the number of disk-based temporary tables<br />
Note! BLOB and TEXT columns are not allow in memory tables.<br />
If you are using these columns raising these values might not impact your<br />
ratio of on disk temp tables.<br />
</code></p>
<p><code>TABLE SCANS<br />
Current read_buffer_size = 1 M<br />
Current table scan ratio = 199 : 1<br />
read_buffer_size seems to be fine<br />
</code></p>
<p><code>TABLE LOCKING<br />
Current Lock Wait ratio = 1 : 2405<br />
You may benefit from selective use of InnoDB.<br />
If you have long running SELECT's against MyISAM tables and perform<br />
frequent updates consider setting 'low_priority_updates=1'<br />
If you have a high concurrency of inserts on Dynamic row-length tables<br />
consider setting 'concurrent_insert=2'.</code></p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="apache tuning script">apache tuning script</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="join_buffer_size">join_buffer_size</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="mysql join_buffer_size">mysql join_buffer_size</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="apache performance tuning scripts">apache performance tuning scripts</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="opencart slow loading">opencart slow loading</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="opencart slow">opencart slow</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="mysql max connections calculator">mysql max connections calculator</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="tune apache to block more hits from same ip">tune apache to block more hits from same ip</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="opencart very slow">opencart very slow</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/" title="join_buffer_size mysql">join_buffer_size mysql</a></li></ul><p>The post <a href="http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php-300x162.jpg" type="image/jpeg" medium="image" width="300" height="162">
                <media:description type="plain"><![CDATA[LAMP-linux-apache-mysql-php]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php-300x162.jpg" />
				            </media:content>
            	</item>
		<item>
		<title>APC Cache Considerations for Virtual Hosting Environments</title>
		<link>http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/</link>
		<comments>http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 14:58:21 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Virtualmin]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[commodity]]></category>
		<category><![CDATA[configured]]></category>
		<category><![CDATA[conflicts]]></category>
		<category><![CDATA[cpu requirements]]></category>
		<category><![CDATA[environments]]></category>
		<category><![CDATA[hosting server]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[neighborhood]]></category>
		<category><![CDATA[personal clients]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[script packages]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[virtual host]]></category>
		<category><![CDATA[virtual hosts]]></category>
		<category><![CDATA[virtual server]]></category>
		<category><![CDATA[virtualmin]]></category>
		<category><![CDATA[web hosting servers]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=505</guid>
		<description><![CDATA[<p>APC cache does not work well in a virtual hosting environment unless PHP is running as FCGID, and every individual virtual host has a unique PHP.ini and a unique fcgiwrapper. This is not the case with many virtual hosting environments because the memory and CPU requirements are too great. I suggest using Virtualmin for a [...]</p><p>The post <a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/">APC Cache Considerations for Virtual Hosting Environments</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM.png" width="240" />
		</p><p>APC cache does not work well in a virtual hosting environment unless PHP is running as FCGID, and every individual virtual host has a unique PHP.ini and a unique fcgiwrapper. This is not the case with many virtual hosting environments because the memory and CPU requirements are too great.</p>
<p><a title="How to Configure APC Cache on Virtual Servers with PHP running under FCGId" href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/">I suggest using Virtualmin for a shared hosting environment with APC cache</a>, because it does allow to set php.ini and fcgiwrapper for every individual virtual host, and so to set an individual configuration for APC per virtual server. However with 200+ virtual hosts all running PHP script packages, as is the case with a commodity shared hosting server, this will use a lot of memory, and you will need somewhere in the neighborhood of 10-30GB apc.shm_size if you attempt to configure a single APC cache for the entire server.</p>
<p>My web hosting server is for a small number of personal clients, so I adjust the APC settings for each individual account, depending on the number and type of PHP script packages running on the account. These accounts are all administered by myself, not by the clients.</p>
<p>I do not think APC is the correct cache for most shared web hosting servers, given the number of virtual hosts. You will probably have better results if you remove APC and concentrate on <a title="Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment" href="http://chrisgilligan.com/portfolio/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Apache performance tuning and MySQL cache</a>.</p>
<p>If your clients are adamant in their requests to use APC cache, you may wish to move them to a different server which can properly handle their needs. Virtualmin is a very good choice for this, as it allows individual accounts to be configured with individual php.ini and fcgiwrapper, or even different versions of PHP. Of course, because this will require greater management, it should be charged as a premium service.</p>
<p>If you wish to enable APC on a commodity web hosting server, you may try the following method to selectively enable APC per directory:<br />
<a href="http://www.php.net/manual/en/ini.php">http://www.php.net/manual/en/ini.php</a></p>
<p><em>Also see other recommendations in following comments&#8230; </em></p>
<p>&nbsp;</p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="php apc per virtual host">php apc per virtual host</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="apc by virtual host">apc by virtual host</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="php APC shared hosting">php APC shared hosting</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="apc shared hosting">apc shared hosting</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="php-apc per virtualhost">php-apc per virtualhost</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="server cache apc conflict">server cache apc conflict</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="virtual host apc">virtual host apc</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="virtual hosts apache apc">virtual hosts apache apc</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="vps apc joomla unable to allocate memory for pool in">vps apc joomla unable to allocate memory for pool in</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/" title="apache2 apc virtual host">apache2 apc virtual host</a></li></ul><p>The post <a href="http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/">APC Cache Considerations for Virtual Hosting Environments</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/consulting/apc-cache-considerations-for-virtual-hosting-environments/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache config for Worker MPM vs Prefork MPM</title>
		<link>http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/</link>
		<comments>http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 14:42:39 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apache config]]></category>
		<category><![CDATA[apache group]]></category>
		<category><![CDATA[group permissions]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[performance testing]]></category>
		<category><![CDATA[php scripts]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[prefork mpm]]></category>
		<category><![CDATA[server apache]]></category>
		<category><![CDATA[worker mpm]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=421</guid>
		<description><![CDATA[<p>Some installations of Apache will have been compiled to work with either Prefork or Worker MPM, but most by default are compiled only to work with Prefork. Changing to Worker MPM may allow your server to handle much higher traffic, more user sessions, with less RAM use. Your site or server will not scale well [...]</p><p>The post <a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/">Apache config for Worker MPM vs Prefork MPM</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/07/apache_web-hosting.png" width="240" />
		</p><p>Some installations of Apache will have been compiled to work with either Prefork or Worker MPM, but most by default are compiled only to work with Prefork. Changing to Worker MPM may allow your server to handle much higher traffic, more user sessions, with less RAM use. Your site or server will not scale well if it is running Prefork MPM. Worker is a bit more difficult to set up properly, and has some restrictions regarding functionality of PHP scripts.</p>
<ul>
<li>To determine which MPM is running:<br />
<pre class="crayon-plain-tag">/usr/sbin/apachectl -l</pre>
</li>
<ul>
<li>If you see worker.c in the list of loaded modules, your Apache is running Worker MPM. If prefork.c, it is running prefork.</li>
</ul>
</ul>
<ul>
<li>To determine if apache has Worker MPM compiled in:<br />
<pre class="crayon-plain-tag">/usr/sbin/httpd.worker -l</pre></p>
<ul>
<li>If you see worker.c in the list of compiled-in modules, Apache can run Worker MPM.</li>
</ul>
</li>
</ul>
<p>Here is some useful info to help if your installation of Apache will work with Worker MPM:</p>
<ul>
<li><a href="http://www.virtualmin.com/node/15046">http://www.virtualmin.com/node/15046</a></li>
<li><a href="http://articles.slicehost.com/2010/5/19/configuring-the-apache-mpm-on-centos">http://articles.slicehost.com/2010/5/19/configuring-the-apache-mpm-on-centos</a></li>
</ul>
<ul>
<li>Un-Comment HTTPD=/usr/sbin/httpd.worker in<code> /etc/sysconfig/httpd</code></li>
<li>restart apache</li>
<li>do some performance testing and raise your worker server and thread limits to sane levels in httpd.conf</li>
</ul>
<p>If you need to recompile Apache and PHP, then you should do more research. Recompiling is not a trivial process.</p>
<p>I found that my server had much better memory usage under Worker MPM, however:</p>
<div>
<ul>
<li>some scripts (squirrelmail, phpmyadmin) do not work on a per-domain basis and must be run direct to the actual server process with symlinked directories. This is much more efficient but less convenient for virtual domain owners</li>
<li>some /dev processes took on strange group permissions, getting the gid of the first user in the apache group.</li>
<li>browser caching was not well supported&#8230; the dreaded &#8220;blank screen between page loads&#8221; occurred more frequently under Worker MPM than Prefork MPM&#8230; also login/logout was sketchy on some sites&#8230; not sure why but my guess is that sessions may not be quite persistent using Worker vs Prefork due to cookie confusion&#8230; possible that multi-threading does not track cookies well.</li>
</ul>
<div>More testing will be necessary to determine whether Worker MPM is a benefit on my server.</div>
</div>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="apache prefork vs worker">apache prefork vs worker</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="prefork mpm vs worker mpm">prefork mpm vs worker mpm</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="apache worker vs prefork">apache worker vs prefork</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="apache mpm worker vs prefork">apache mpm worker vs prefork</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="prefork vs worker">prefork vs worker</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="prefork vs worker mpm">prefork vs worker mpm</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="worker mpm">worker mpm</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="worker vs prefork">worker vs prefork</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="apache mpm prefork vs worker">apache mpm prefork vs worker</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/" title="mpm prefork vs worker">mpm prefork vs worker</a></li></ul><p>The post <a href="http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/">Apache config for Worker MPM vs Prefork MPM</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/consulting/apache-config-for-worker-mpm-vs-prefork-mpm/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/07/apache_web-hosting.png" type="image/png" medium="image" width="261" height="285">
                <media:description type="plain"><![CDATA[apache_web-hosting]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2011/07/apache_web-hosting.png" />
				            </media:content>
            	</item>
		<item>
		<title>How to Configure APC Cache on Virtual Servers with PHP running under FCGId</title>
		<link>http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/</link>
		<comments>http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 01:33:31 +0000</pubDate>
		<dc:creator>Chris Gilligan</dc:creator>
				<category><![CDATA[Virtualmin]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[apc cache]]></category>
		<category><![CDATA[apc fcgid]]></category>
		<category><![CDATA[commodity web]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[hosts section]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[installation suggestions]]></category>
		<category><![CDATA[memory limit]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[page cache]]></category>
		<category><![CDATA[performance testing]]></category>
		<category><![CDATA[php module]]></category>
		<category><![CDATA[php.ini apc settings]]></category>
		<category><![CDATA[server performance]]></category>
		<category><![CDATA[system resources]]></category>
		<category><![CDATA[traffic surges]]></category>
		<category><![CDATA[virtual domains]]></category>
		<category><![CDATA[virtual hosts]]></category>
		<category><![CDATA[virtual private server]]></category>
		<category><![CDATA[virtual servers]]></category>
		<category><![CDATA[virtualmin]]></category>
		<category><![CDATA[web hosting servers]]></category>

		<guid isPermaLink="false">http://chrisgilligan.com/?p=274</guid>
		<description><![CDATA[<p>My Virtualmin CentOS 5.6 Virtual Private Server runs several virtual domains with PHP under FCGId using APC for opcode caching: Joomla, PHPbb, WordPress, etc . APC is somewhat challenging to configure properly with fcgid-enabled virtual domains, but it is quite helpful to optimize system resources and prevent traffic surges on one site from affecting overall [...]</p><p>The post <a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/">How to Configure APC Cache on Virtual Servers with PHP running under FCGId</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="float:right; margin:0 0 10px 15px; width:240px;">
		<img src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM.png" width="240" />
		</p><div id="attachment_306" class="wp-caption alignright" style="width: 301px"><a href="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM.png"><img class="size-medium wp-image-306" title="APC INFO" src="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM-291x300.png" alt="APC INFO Monitor" width="291" height="300" /></a><p class="wp-caption-text">APC INFO Monitor</p></div>
<p><strong>My Virtualmin CentOS 5.6</strong> Virtual Private Server runs several virtual domains with <strong>PHP under FCGId</strong> using <strong>APC for opcode caching</strong>: Joomla, PHPbb, WordPress, etc . APC is somewhat challenging to configure properly with fcgid-enabled virtual domains, but it is quite helpful to optimize system resources and prevent traffic surges on one site from affecting overall server performance. Joomla and PHPbb have code that is pre-optimized with hooks for APC, but WordPress requires a plugin called <strong>W3 Total Cache</strong>.</p>
<h3>First Things First</h3>
<p>Please read my posts about <a title="APC Cache Considerations for Virtual Hosting Environments" href="http://chrisgilligan.com/wordpress/apc-cache-considerations-for-virtual-hosting-environments/">APC on commodity virtual hosting servers</a> and <a title="Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment" href="http://chrisgilligan.com/portfolio/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Apache and MySQL performance tuning</a> before you begin.</p>
<p>If you are running your virtual servers under FCGId, then you should do so for all virtual servers on your machine. Why? Because then you do not need apache&#8217;s mod_php (php module). Less modules loaded, less wasted memory.</p>
<ul>
<li>Comment out:<code><br />
LoadModule php5_module modules/libphp5.so</code><br />
in /etc/httpd/conf.d/php.conf</li>
<li>Remove any php_memory_limit lines in httpd.conf&#8217;s virtual hosts section.<code></code></li>
<li>restart apache<br />
<code></code></li>
<li>do some performance testing and raise your server and thread limits to sane levels in httpd.conf</li>
</ul>
<p>If possible, you may wish to run Apache with Worker MPM instead of Prefork MPM.</p>
<ul>
<li>More information about <a title="Apache config for Worker MPM vs Prefork MPM" href="http://chrisgilligan.com/wordpress/apache-config-for-worker-mpm-vs-prefork-mpm/">Apache Worker MPM vs. Prefork MPM »</a></li>
</ul>
<p>Installation Suggestions and Modification of Defaults</p>
<p>Be sure to install the newest version of APC, 3.1.9 as of the last revision of this post (I assume you know how to install and configure all the packages mentioned in this post):</p>
<p><code>pecl install apc</code></p>
<p>Choose &#8220;no&#8221; for internal debugging,  but choose &#8220;yes&#8221; for the other installation options, including the Experimental options.</p>
<p><strong>For W3 Total Cache (WordPress plugin):</strong><br />
Page Cache: do not choose APC for the W3TC&#8217;s Page Cache, choose Enhanced Disk.<br />
Minify: do not choose APC for Minify, use Disk.<br />
Opcode Cache: choose APC for Opcode Cache<br />
Database Cache: choose APC for Opcode Cache<em><br />
</em></p>
<p><strong>For APC running on virtual servers for opcode caching:</strong><br />
<em> Remove</em> apc.ini from /etc/php.d. Do not add the APC configuration into /etc/php.ini (main php.ini which is probably a template used for creation of new virtual servers).</p>
<p>Instead, enable APC on a per-domain basis by modifying the respective /home/domainname.com/etc/php5/php.ini &#8212; your httpd.conf or virtual.conf should look something like this for each virtual domain.</p><pre class="crayon-plain-tag">&lt;VirtualHost 99.88.177.288:80&gt;
ServerName chrisgilligan.com
ServerAlias www.chrisgilligan.com
DocumentRoot /home/chris/public_html
ErrorLog /var/log/serversoftware/chrisgilligan.com_error_log
CustomLog /var/log/serversoftware/chrisgilligan.com_access_log combined
ScriptAlias /cgi-bin/ /home/chris/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
&lt;Directory /home/chris/public_html&gt;
Options Indexes IncludesNOEXEC FollowSymLinks ExecCGI
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/chris/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/chris/fcgi-bin/php5.fcgi .php5
&lt;/Directory&gt;
&lt;Directory /home/chris/cgi-bin&gt;
allow from all
&lt;/Directory&gt;
SuexecUserGroup "#987" "#756"
Options ExecCGI FollowSymLinks Includes IncludesNOEXEC -Indexes MultiViews SymLinksIfOwnerMatch
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 12
&lt;/VirtualHost&gt;</pre><p>You must &#8220;babysit&#8221; the configuration: use the APC monitor (apc.php) to see how many files are being cached, and how much memory (apc.shm_size) is needed to avoid fragmentation, which will cause the 500 errors. If fragmentation rises quickly to 100%, memory usage is full, and cache full count rises above 0, you will almost surely see &#8220;500&#8243; errors.</p>
<p>If WordPress is the only PHP script software package on the domain, the following configuration will likely work for you; if you have more PHP software packages, you will need to raise apc.shm_size and raise the apc.user_entries_hint and apc.user_entries_hint settings, and possibly lower TTL values to allow cached files to expire and be replaced.</p>
<p>In general, you must <em>double</em> apc.shm_size in relation to APC&#8217;s highest reported Memory Usage to avoid fragmentation completely.</p>
<h3>Configuration Suggestion for php.ini</h3>
<p>in the virtual server&#8217;s /home/domainname.com/etc/php5/php.ini, add the following configuration:<br />
(you may also install memcached, and should install fileinfo for full use of W3 Total Cache)</p><pre class="crayon-plain-tag">[memcached]
;memcached for distributed servers - e.g. mysql server on separate host
;extension=memcache.so

[fileinfo]
;fileinfo is included in PHP 5.3=&gt;... uncomment the following line if using &lt;=5.2
;extension=fileinfo.so

[APC]
extension = apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 12M
apc.optimization = 0
apc.num_files_hint = 512
apc.user_entries_hint = 1024
apc.ttl = 0
apc.user_ttl = 0
apc.gc_ttl = 600
apc.cache_by_default = 0
apc.filters = "-/home/username/public_html/apc/apc\.php$"
apc.slam_defense = 0
apc.use_request_time = 1
apc.mmap_file_mask = /tmp/apc-accountname.XXXXXX
;OR apc.mmap_file_mask = /dev/zero
apc.file_update_protection = 2
apc.enable_cli = 0
apc.max_file_size = 2M
apc.stat = 1
apc.write_lock = 1
apc.report_autofilter = 0
apc.include_once_override = 0
apc.rfc1867 = 0
apc.rfc1867_prefix = "upload_"
apc.rfc1867_name = "APC_UPLOAD_PROGRESS"
apc.rfc1867_freq = 0
apc.localcache = 1
apc.localcache.size = 512
apc.coredump_unmap = 0
apc.stat_ctime = 0</pre><p>Save php.ini, restart apache and then watch the APC Monitor to ensure fragmentation stays below 50% (it should remain less than 10% most of the time&#8230; if fragmentation rises quickly, you should add a few more MB&#8217;s of memory to apc.shm_size and restart apache).</p>
<h3>Monitoring APC Performance and Detecting Errors</h3>
<p>You should run apc.php in a password-protected directory in the domain&#8217;s public_html. Edit the apc.php code to allow passwordless access.<br />
<code>defaults('USE_AUTHENTICATION',0);</code></p>
<p>You can monitor errors with these commands:<br />
<code>tail -f -n 50 /var/log/httpd/error_log<br />
tail -f -n 50 /home/domainname.com/logs/error_log</code></p>
<p>In the logs, you should see messages like the following:<br />
<code>mod_fcgid: process /home/username/public_html/scriptname.php(21272) exit(lifetime expired), terminated by calling exit(), return code: 0</code><br />
<code>... exit(server exited) ...</code><br />
<code>... exit(idle timeout) ...</code><br />
if the cache is working well. If you see <code>exit(communication error)</code> then you have issues, probably cache full and fragmented.</p>
<h3>Fragmentation Explained</h3>
<p>Fragmentation is a measure of the non-available portion of apc.shm_size due to lack of contiguous memory large enough to accept new cache items. 100% fragmentation means the available memory is broken into hundreds of small pieces that are too small to accept new cache items. This occurs when cached items expire and new cached items fill their vacated memory slots; usually the new item is slightly smaller than the old item, and the leftover space may be too small for a new cache item.</p>
<p>Fragmentation can cause even a large amount of free memory to be unavailable for new cache items. That is why I say above you can avoid fragmentation by doubling the apc.shm_size in relation to the largest total memory usage you see. So you may want to start with 100MB, let the site run for a few hours during high traffic conditions, and then reduce shm_size to roughly double the highest amount of cache memory usage during that time.</p>
<h3>Further Information and Suggestions</h3>
<p>APC can have a very significant effect on minimizing overall server load and overall memory usage. It takes time to configure, and must be re-configured whenever PHP script software is added to a virtual server. The more plugins/mods/components you add to a PHP software package, the more scripts, database queries and objects will be cached.</p>
<p>If you have PHP scripts or plugins that do not need to be cached (low traffic pages such as contact forms, PHP scripts that do not have APC hooks and have their own caching schemes, dynamic image resizers, etc.), you can filter them out with simple RegEx:<br />
<code>apc.filters = "-/home/username/public_html/apc\.php$,-/home/username/public_html/wordpress/wp-content/themes/themename/thumb\.php$,-/usr/share/psa-horde/.*,+/home/username/public_html/phpmyadmin/.*"</code></p>
<p>TimThumb is a good example of a common WordPress theme plugin that may not need to be cached.</p>
<p>Because the apc.filters RegExp only works with filenames, it is not possible to filter out an entire PHP script package, component or plugin based on the directory where it resides. So if you do not wish to use APC cache on a particular script package, you should run it in a separate website. Some PHP script packages such as Gallery2 have an incredibly large number of .php, .inc and .class files which will be cached, so it is difficult to find them all and filter them all using apc.filters.</p>
<p>If you can&#8217;t raise apc.shm_size due to lack of available memory, try lowering the TTL&#8217;s (values in seconds, 0 is no limit, 600=10minutes, etc.). This will still have a good effect on high-traffic sites with many concurrent end users; caching is not at all necessary for low-traffic sites. However, be aware that lower TTL&#8217;s can cause more fragmentation.</p>
<h3>During Testing or Debugging with CMS caching plugins or modules</h3>
<p>While you are tweaking your opcode settings, and especially if you are using APC with a CMS like WordPress (w3 total cache) or phpbb or joomla, and you are experimenting with settings, or updating plugins or core, you should set apc.stat=1 (on). Restart the web server to load the new settings.</p>
<p>APC.Stat is the file change polling, which checks for file change every time a cached script or object is called. So, with polling turned off, your settings/configuration files will remain cached, and this will cause you a lot of frustration. W3 Total Cache in particular is difficult to get configured properly with apc.stat=0 because the config settings and files are dependent upon database and php, which will be cached as files or opcode.</p>
<p>After you have sorted out your opcode settings, you may switch apc.stat=0 and restart the web server to turn off polling for better performance.</p>
<p>If you cannot get APC to configured correctly for your WordPress sites, I suggest WP Super Cache and WP Minify&#8230; that combination will probably have a better effect, as it will serve pages very quickly and accellerate user experience for a small number of users. Joomla 1.5 and phpBB3 are much easier to work with, as their caching systems are built to use APC and other opcode caches. Apparently, Gallery3 now also supports opcode caching.</p>
<p><strong>More advice: </strong></p>
<ul>
<li>turn <strong><em>on</em></strong> apc.stat (documentation says, &#8220;not for production servers&#8221;, but W3TC requires stat polling to monitor file status, post revisions, plugin upgrades, etc.)</li>
<li>turn <strong><em>off</em></strong> apc.optimization (experimental and unstable, may cache user session info, fubaring items which should not be cached, such as admin pages and logged-in site pages)</li>
<li>turn <strong><em>off</em></strong> apc.include_once_override (use carefully; only useful with PHP scripts that do not have cache hooks, such as Joomla 1.0, phpBB2, etc.)</li>
<li>turn <em><strong>off</strong></em> apc.slam_defense (may cause objects to be replaced with PHP warnings which are displayed to the user, especially on Joomla 1.5)</li>
<li>set apc.user_ttl = 0 (allows your php scripts to set appropriate timeouts for queries and objects)</li>
<li>set apc.mmap_file_mask = /tmp/apc-yourusernamehere.XXXXXX for file-backed mmap; make file mask unique by adding your unique string; XXXXXX (exactly 6 X&#8217;s) must remain to allow APC to add random string<br />
OR set to /dev/zero for anonymous mmap if you can spare the memory</li>
</ul>
<p><small>APC Manual: <a href="http://www.php.net/manual/en/book.apc.php">http://www.php.net/manual/en/book.apc.php</a><br />
APC Runtime Configuration <a href="http://www.php.net/manual/en/apc.configuration.php">http://www.php.net/manual/en/apc.configuration.php</a></small></p>
<strong class="seo-searchterms">Incoming search terms for the article:</strong><ul class="seo-searchterms"><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="apache is running a threaded mpm but your php module is not compiled to be threadsafe">apache is running a threaded mpm but your php module is not compiled to be threadsafe</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="For optimal performance we recommend adding the Alternative PHP Cache (APC) extension">For optimal performance we recommend adding the Alternative PHP Cache (APC) extension</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="configure APC">configure APC</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="apc config">apc config</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="Apache is running a threaded MPM but your PHP Module is not compiled to be threadsafe You need to recompile PHP">Apache is running a threaded MPM but your PHP Module is not compiled to be threadsafe You need to recompile PHP</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="php apc config">php apc config</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="[apc-warning] unable to allocate memory for pool">[apc-warning] unable to allocate memory for pool</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="apache is running a threaded mpm">apache is running a threaded mpm</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="how to configure apc">how to configure apc</a></li><li class="seo-searchterms"><a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/" title="apc fragmentation">apc fragmentation</a></li></ul><p>The post <a href="http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/">How to Configure APC Cache on Virtual Servers with PHP running under FCGId</a> appeared first on <a href="http://chrisgilligan.com">Chris Gilligan » new media</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://chrisgilligan.com/wordpress/how-to-configure-apc-cache-on-virtual-servers-with-php-running-under-fcgid/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
	            <media:content url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM-291x300.png" type="image/png" medium="image" width="291" height="300">
                <media:description type="plain"><![CDATA[APC INFO]]></media:description>
                <media:copyright>Chris Gilligan</media:copyright>
                					<media:thumbnail url="http://d318px5m0jadsp.cloudfront.net/wp-content/uploads/2010/10/Screen-shot-2010-10-13-at-6.20.12-PM-291x300.png" />
				            </media:content>
            	</item>
	</channel>
</rss>

<!-- Served from: chrisgilligan.com @ 2013-05-20 23:19:28 by W3 Total Cache -->