A Non-Traditional Wordpress Tuning Guide - Part II

July 19, 2008 by Shop Network 

Before getting to deep into Wordpress itself, it is important to tune the underlying structures that power Wordpress. In a typical situation, Wordpress runs off of LAMP — Linux, Apache, mySQL, and PHP. There are several blog posts have been written about tuning Wordpress for optimal performance. Some of the references below address the LAMP structure as a whole, while others address a particular aspect of the LAMP structure.

  1. Tuning Wordpress for Speed
  2. 4+1 Ways To Speed Up WordPress With Caching
  3. Optimizing performance for WordPress
  4. Guide To Optimizing WordPress Servers
  5. Wordpress Performance: Why My Site Is So Much Faster Than Yours
  6. Optimizing WordPress for High Volume Traffic
  7. Diggproof & Speed up Your Wordpress Blog
  8. 5 Ways To Increase The Loading Speed Of A WordPress Blog

Tweaking PHPTweaking PHP is done through the use of a PHP Accelerator and through customizing the PHP.INI file. Now, there are several PHP Accelerators available — but which one offers the faster performance and the most stability? I’ll leave that for you to decide. There are several topics regarding benchmarking of the various accelerators.

  1. Benchmarking PHP accelerators
  2. PHP Accelerators
  3. PHP Accelerators : APC vs Zend vs XCache with Zend Framework
  4. Install eAccelerator to Optimize PHP performance
  5. Adventures with WP-Cache2 & APC

What I use on my dedicated server is APC PHP Accelerator. In order to install APC, please read a post on vBulletin that details how to install APC. Inside PHP.INI, I have set the variables to the following:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

extension = apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 256
apc.ttl = 7200
apc.user_ttl = 7200
apc.gc_ttl = 7200
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.enable_cli = 1
apc.num_files_hint = 2500
apc.stat = 1
apc.filters = wp-cache-config

Tuning mySQL Regarding tuning and optimizing mySQL, there have also been several blog posts made. Of course, some blogs have covered tuning PHP along with tuning mySQL. Basically, the file that contains all the tweakable variables is my.cnf. Both tuning-primer and mysqlsla can offer insight into slow mySQL queries. Read their documentation, download them, and install them.

  1. Tuning / Optimizing my.cnf file for MySQL
  2. Example my.cnf files
  3. Tweaking MySQL Server
  4. mySQL Performance Forums

Please keep in mind, that the my.cnf is always a work in progress.


[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-locking
skip-innodb
back_log = 50
query_cache_limit = 3M
query_cache_size = 64M
query_cache_type = 1
interactive_timeout = 100
wait_timeout = 15
connect_timeout = 10000
interactive_timeout = 25
thread_cache_size = 1024
join_buffer = 3M
read_rnd_buffer_size = 3096K
max_connect_errors = 10
thread_concurrency = 4
server-id = 1
key_buffer = 192M
max_allowed_packet = 32M
thread_stack = 128K
thread_cache = 3096
read_buffer_size = 3096K
sort_buffer_size = 3096K
myisam_sort_buffer_size = 48M
key_buffer_size = 192M
net_buffer_length = 16k
max_tmp_tables = 512
table_cache = 1536
max_connections = 150
log_slow_queries = /var/log/mysqld.slow.log
long_query_time = 1
tmp_table_size = 64M
max_heap_table_size = 64M
query_cache_min_res_unit = 1
low_priority_updates = 1
concurrent_insert = 2
record_buffer = 3M
[safe_mysqld]
open_files_limit=7092
[mysqldump]
quick
max_allowed_packet=64M
max_allowed_packet=64M
[mysql]
no-auto-rehash
[isamchk]
key_buffer=48M
sort_buffer=48M
read_buffer=24
write_buffer=24M
[myisamchk]
key_buffer=48M
sort_buffer=48M
read_buffer=24M
write_buffer=24M
[mysqlhotcopy]
interactive-timeout

Tune ApacheTuning Apache is done primarily through the httpd.conf file. I have included an example copy of my tweaked and tuned httpd.conf file — a SMALL beginning section of it. I wouldn’t recommend copying and pasting it; however, after inspecting it, if you find something useful — then feel free to use sections of it.


<Directory “/”>
Options All
AllowOverride All
Options -Indexes
Options +FollowSymLinks

</Directory>

<Directory “/usr/local/apache/htdocs”>
Options Includes Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

</Directory>

# Prevent .htaccess and .htpasswd files from being viewed by web clients

<Files ~ “^error_log$”>
Order allow,deny
Deny from all
Satisfy All
</Files>

<Files “^\.ht”>
Order allow,deny
Deny from all
</Files>

# Protect files
<Files ~ “^(.*)\.(inc|inc\.php|tpl|sql)$”>
Order deny,allow
Deny from all
</Files>

# Protect directories
<Files ~ “^(backup|aom|images|design|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$”>
Order deny,allow
Deny from all
</Files>

<IfModule log_config_module>
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common

CustomLog “logs/access_log” common

<IfModule logio_module>
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\” %I %O” combinedio

</IfModule>

</IfModule>

<IfModule alias_module>
ScriptAlias /cgi-bin/ “/usr/local/apache/cgi-bin/”

</IfModule>

<Directory “/usr/local/apache/cgi-bin”>
AllowOverride None
Options None
Order allow,deny
Allow from all

</Directory>

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

</IfModule>

#######################
# Optimizations #
#######################

HostnameLookups Off
ServerSignature Off
ServerTokens ProductOnly

Timeout 120
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2

<IfModule prefork.c>
StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 150
MaxClients 150
MaxRequestsPerChild 500
</IfModule>

Header unset Pragma
FileETag None
Header unset ETag

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year (forever?)
<FilesMatch “\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$”>
ExpiresDefault A29030400
Header append Cache-Control “public”
</FilesMatch>

# Set up caching on media files for 1 week
<FilesMatch “\.(gif|jpe?g|png|swf)$”>
ExpiresDefault A604800
Header append Cache-Control “public, must-revalidate”
</FilesMatch>

# Set up cache on media files for 3 days
<FilesMatch “\.(css|js|txt)$”>
ExpiresDefault “access plus 3 days”
Header append Cache-Control “public, must-revalidate”
</FilesMatch>

# Set up 2 Hour caching on commonly updated files
<FilesMatch “\.(xml|html|htm)$”>
ExpiresDefault A7200
Header append Cache-Control “public, must-revalidate”
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch “\.(php|cgi|pl)$”>
ExpiresActive Off
Header set Cache-Control “private, no-cache, no-store, proxy-revalidate, no-transform”
Header set Pragma “no-cache”
</FilesMatch>

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(?:exe|t?gz|zip|bz2|sit|rar)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

######################

Comments

One Response to “A Non-Traditional Wordpress Tuning Guide - Part II”

  1. Shop Network on July 19th, 2008 11:34 pm

    Be careful if you copy and paste this information because due to the formatting here, there will be line breaks where there should not be line breaks in an actual httpd.conf file.

    In particular, there is a distinct line break @ # Protect directories.

You are welcome to contribute comments, but they should be relevant to the post and the conversation that ensues. To keep comment exchanges focused and engaging, we reserve the right to delete off-topic remarks and self-promotional URLs - so please avoid these.
We recommend that comments be a minimum of 3 sentences long.