Wednesday, 7 December 2011

Setting up wordpress mu under apache

This morning I was still trying to get my wordpress multisite setup in my local dev environment on apache. The first problem I had was that I am using two variations of each domain - domain.con for nginx and domain.can for acessing the same site through apache. Because wordpress gets the domain name from the db (and wp_config) and checks it against the request, this meant I needed to have a separate db for .can and .con and also make some modifications to wp_config.

Otherwise if the db was for .con domains and I requested domain.can, wordpress would redirect me to .con. After getting this setup, I tried logging into the wp-admin area via the .con (nginx served) domain, but just got a couple of error messages about missing indexes in arrays etc. from some plugins. Doing some debugging I eventually tracked the problem down to wp_redirect. The function sends a redirect header, but this header wasn't being received according to the Web Developer toolbar in Firefox.

I scratched my head for a while, then tried turning off WP_DEBUG in wp_config. (I needed it switched on yesterday as otherwise wordpress just displayed a blank page instead of giving an error message about the mysql extension being missing). With WP_DEBUG set to false, the admin area now loaded successfully. Of course, now I thought about it, it was obvious why the header wasn't working - PHP had already sent output in the form of the error messages to do with the badly written plugins, and so couldn't send any headers.

It's a shame that PHP didn't also give the standard error message of 'Headers already sent' as that would have made debugging the issue much easier and quicker. Maybe that error message needs a stricter error reporting setting than wordpress uses with WP_DEBUG switched on.

The next job was to figure out why w3totalcache was correctly serving images from a static subdomain for the .con nginx site but not the .can apache site. I found the problem was that it loads the configuration settings from a file (rather than, or maybe as well as the database). After some debugging, I found the configuration file is stored as '/wp-content/w3-total-cache-config-domain.con.php' (I spent quite a while looking in the plugin directory as I thought it would save its files in there). So I just copied that file, renamed it to '/wp-content/w3-total-cache-config-domain.can.php and replaced the references in it to domain.con with domain.can.

No comments: