Mediawiki, WordPress and PHP Performance Improvements on Lee.org

I run several Mediawiki wikis and WordPress blogs on my Dreamhost shared hosting. I continue to work on improving performance on my wikis.

Here are some performance hints for the Mediawiki LocalSettings.php file I am running right now:

## Compress output if the browser supports it
# I commented this out in favor of wgUseGzip below. I -think- it offers better
# performance. LCS 5-6-08
# if( !ini_get( ‘zlib.output_compression’ ) ) @ob_start( ‘ob_gzhandler’ );

# Enable the basic file cache for static pages for non-logged-in visitors
$wgUseFileCache = true;
$wgFileCacheDirectory = “/home/.author/leedh/lee.org/[my temp folder]”;
$wgShowIPinHeader = false;

# I set wgUseGzip to be true and commented out the bit about ob_gzhandler
# above. I -think- this makes for better performance. LCS 5-6-08
$wgUseGzip = true;

$wgEnableSidebarCache = true;

#default is 1, changing to a higher number will be a little bit
# nicer to the database
$wgHitcounterUpdateFreq = 10;

$wgUseETag = true;

I also run my own PHP executable on Dreamhost and PHP_Fast_CGI. I didn’t take the time to install my own PHP. This is a bit of a hack but it works fine. I control the php.ini file… read below. The part I like the most is that I don’t have to manually upgrade PHP every so-often. Dreamhost will do it automagically. Here is an excurpt from the .htaccess file of the root of my website that tells all the PHP programs on my site to use my PHP and PHP_Fast_CGI.

# This is to run my own PHP and PHP_Fast_CGI. Since this is in the root
# of my web site, the whole website will run this way.
# note that I modified php5-wrapper.fcgi to run my own copy of PHP
AddHandler fastcgi-script fcg fcgi fpl
AddHandler php5-fastcgi .php
Action php5-fastcgi /php5-wrapper.fcgi

The contents of the php5-wrapper.fcgi file in the root of my account is:

#!/bin/sh

# Run PHP with 2 persistant processes
export PHP_FCGI_CHILDREN=2

# Run PHP
#exec /usr/local/dh/cgi-system/php5.cgi

# Run my own PHP with increased limits
exec /home/.author/leedh/lee.org/cgi-bin/php.cgi

The php.cgi file in the cgi-bin directory is the PHP executable fetched from where it normally lives on the Dreamhost server at /dh/cgi-system/php5.cgi. Once a month I run this script to make sure I have the latest PHP. This script also fetches the php.ini and modifies it so I can upload files using PHP up to 100 MB instead of the 7 MB limit.

#!/bin/sh

# This script copies over the latest php5 to my folder so I can run PHP locally.
# running locally lets me use my own php.ini (in the same directory as php.cgi)
# So then I can set the max post size and max filesize to larger than 7 megabyte
s!!
# Hurray!

CGIFILE=”$HOME/lee.org/cgi-bin/php.cgi”
INIFILE=”$HOME/lee.org/cgi-bin/php.ini”
rsync -a /dh/cgi-system/php5.cgi “$CGIFILE”
# REMOVE THE FOLLOWING LINE TO CREATE THE UPDATE-ONLY SCRIPT:
cp /etc/php5/cgi/php.ini “$INIFILE”

perl -p -i -e ‘
s/.*post_max_size.*/post_max_size = 100M/;
s/.*upload_max_filesize.*/upload_max_filesize = 100M/;
‘ “$INIFILE”

Enjoy.

Leave a Comment

Do not write "http://" or "https://" in your comment, it will be blocked. It may take a few days for me to manually approve your first comment.